Replace character "\" with "\\"? - python-3.x

When I copy a path from Windows explorer, it will be in this "C:\Users" notation, while I actually want "C:\\Users". Is there some function that does this replacement for me?
I already figured out that the other way round can be solved using codecs.decode(file_path, "unicode_escape"), not sure about this direction though.

As stated by tobias_k in a comment, use a raw string:
In this case, use a raw string: r"<paste path here>". Otherwise, if you paste it into input or a UI textfield, Python will do the escaping for you.

Related

Removing all special characters from a string that cannot be used inside the command line (python)

I'm making a tk application in which I have to execute a command line application (MP4Box) from python, using subprocess.check_call().
The filename (used in the command) is retrieved from youtube and hence has all types of special characters. I want to remove all characters that can't be used as filenames in the Operating system also btw (i want the implementation would work across multiple platforms)
I tried the solution over here
. windows seems accept the filename but but it returns an error with subproces.check_call().
I tried manually removing the special char from filename and it works good after that. so it isnt a problem with the command.
EDIT:
For eg, i tested for this video. The solution in above link won't remove 'รค' and cause a problem in the command line.
I eventually found the correct answer. Ascii did the trick :)
''.join([t for t in <filenmae> if t.isalnum()]).encode('ascii', 'ignore'))

Printing literal ' in React Native text object

I want to print:
Hi, let's do this:
the issue is, it won't work with the "let's" due to the apostrophe. If I use quotes around this (""), it prints the quotes as well in the view, which I don't want.
How do I do this in React Native?
Try this
<Text>{"Let's"}</Text>
Try <Text>{"Hi, let's do this"}</Text>.
Any time you encounter any difficulty using a Text label, just remember that inside the brackets the rules of JavaScript apply, and so you can do anything in the same way that you would for a JS string.
A temporary work around is to use ' instead of '

String Manipulation in Bash when variable is a path

This may be an easy question for someone more experienced than me out there. Any help would be massively appreciated.
I'm trying to manipulate a text string using the below code:
CONTENTS=${RESPONSEFILE%</Header></StockResponse>}
Where RESPONSEFILE = /apps/live/awards/tmp/NexPhase4.tmp
Trouble is whenever I run the above code it takes the pathname of the file and tries to manipulate that instead of opening up the file and manipulating the text within the file.
that is exactly what bash string manipulation is supposed to do: http://tldp.org/LDP/abs/html/string-manipulation.html
what you want can be done using sed or other programs that allow to change files

Fortran 90 - I/O passing variable as filepath

This seems like it should be an easy fix, but after searching for hours I cannot find a solution.
I want to save a filepath as a character variable, then use the variable in a I/O statement. Below is my code for reading from the file defined by "filepath".
character:: filepath
filepath='c:\users\chris\...\data.txt'
open(unit=1,file=filepath,status='old',action='read',form='formatted',iostat=ierror)
if(ierror.NE.0)then
print*,'file cannot be opened or does not exist'
read*,
endif
......
The program compiles (gfortran compiler using NetBeans IDE), but when I run, I get the error printed to the screen.
Note 1: When I put the filepath directly into the open function as shown below, it seems to work fine
open(unit=1,file='c:\\Users\\Chris\\...\\data.txt',status='old',action='read',form='formatted',iostat=ierror)
Note 2: I have tried all variations of forward/backward, single/double slashes in the filepath variable, so I don't think that is the problem. When I print out "filepath" to the screen as a debugging mechanism (before the open function above), all is get back is "C". So for some reason, it seems I am losing the rest of the filepath. (I will leave my questions regarding what slash method is appropriate until I research it more)
I appreciate any suggestions.
Thanks,
Chris
You've declared filepath to be a character variable of length 1. Change the declaration to something like character(80):: filepath (use a length long enough to contain the entire path).

How to use variables with Recordset!

My problem is the following:
I need to assign a value to the recordset. The problem isthat I need to use a variable. So, instead of write this
MyRecordSet![field_name]
I need to write this
MyRecordSet![variable_name]
This all look simple even to me, until I find out that inside the brackets there are no quotation marks to separate strings of text from variable names. Therefore, I can't distinguish them.
Please, guys, help me! I've tried everything you can imagine.
Thanks in advance.
MyRecordSet.Fields(variablename)

Resources