I have a path of the form
input_path=C:\Users\ngv\workspace\filename1.
I am using
dir,file = os.path.split(input_path).
This prints:
`dir= C:\Users
gv\workspace` by treating \n of \ngv as newline
and file = filename1.
How do I fix this? I cannot seem to find any way to escape \n.
I tried input_path=input_path.replace('\n','\\n') and input_path.replace('\\n','\\\n') with failed results.
Please note that I am using exec() in python. And it is during this exec() invoke that the file path name changes.
Related
I'm working to look through websites to find specific words. I use the re.compile with bs4 to search for the word. I am having issues if my word contains a backslash ('\'). I was hoping I could get some help on how to do this. My code is usually like this
results = self.soup.find_all(string=re.compile('.*{0}.*'.format(searched_word), re.IGNORECASE), recursive=True)
This code throws an error of re.error: bad escape \M at position 13 when I try to have searched_word = Software\Microsoft\Windows\CurrentVersion\Run
I read somewhere that in order to escape backslash, I should make it Software\\Microsoft\\Windows\\CurrentVersion\\Run which throws an error. Or Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Run which doesn't throw an error but does not return the text.
It seems you are not escaping the string for re.compile(). To do that, use re.escape() (doc):
results = self.soup.find_all(string=re.compile('.*{0}.*'.format(re.escape(searched_word)), re.IGNORECASE), recursive=True)
When trying to upload a csv file to BigQuery with the following params:
bq load --quote='"' --null_marker='\\N' --source_format=CSV sendpulse.user_orders gs://data-sendpulse/user_orders_3.csv
I get an error when trying to parse the following row:
"0","63800.00","1","0","Service \"Startup Pack\""
Obviously, Bigquery doesn't treat backslash as an escape character for inner quotes, but is there a way to specify backslash as an escape character?
Tried different options and always got errors.
Update:
Quote in a quoted csv value is escaped with another quote and there is no setting for an escape character.
I don't see a better workaround than replacing all \" with ' or "" in your files.
I would like to print a directory "w:\dir\xx.doc" as the output in my rmarkdown output pdf file.
I have tried to:
1) directly write in text:
here is the directory w:\dir\xx.doc
2) try to print it in inline R-code:
here is the directory r print("w:\dir\xx.doc")
Does anyone know how to print the directory?
My problem is not about how to treat a directory in R, but how to properly print out a directory in my pdf file as a string in a common fomat as a directory. So actually I do not want to functionally call the directory in R, but just to properly print it out. for instance I would like to have a sentence in my file: "here is the location where we store the file: w:\dir\xx.doc"
The backslashes are being interpreted as escape sequences.
The easiest solution is to use normalizePath() to convert the path to a more unix-like representation:
normalizePath(mydir, winslash = "/")
R on windows will interpret forward slashes correctly.
Alternatively you can try using a double-backslash (\) to escape your backslash, but there are usually several levels where this needs escaping.
In R, backslash must be escaped; so each time you want to write \ inside a string, you need to write \\.
mydir <- "w:\\dir\\xx.doc"
print(mydir)
# w:\\dir\\xx.doc
cat(mydir)
# w:\dir\xx.doc
I'm running into a problem when trying to upload certain files. If a file has a '#' in the name, I get errors when trying to then open the file. Is there a way to strip the '#' character from the filename before uploading it?
I've tried using Replace, but it throws an error when I use '#' in there:
<cfset myfile = #Replace('myfile', '#', '', 'all')#>
I could use createUUID, but there may be multiple file types, so I don't necessarily know what the file extension will be.
When you upload the file, use reReplace() to remove any non alpha numeric characters in the final name of the file. You might also consider replacing spaces with underscores and/or making the name all lowercase letters.
i'm trying to make vim check for the filename of the file it's about to open
if #%== .\+"notes.tex"
highlight done ctermbg=blue ctermfg=white guibg=#292960 guifg=#AAAAAA
match done /.\+itemize.\+/
endif
i'd like this script work on the file notes.tex regardless of the directory. the reason i pu .+ before notes is because i want to match all the preceeding characterrs in the filename
in other words i want if to match "notes.tex" and "../notes.tex"
I think you'd be better of using the expand("%") function to read the filename, and then using matchstr() to check it:
if matchstr(expand("%"),"notes\.tex$") != ""
highlight done ctermbg=blue ctermfg=white guibg=#292960 guifg=#AAAAAA
match done /.\+itemize.\+/
endif
Note the $ in the matchstr statement: so this only matches "notes.tex" if it is at the very end of the string.
The nice this about this approach is that it doesn't care about the slash direction (\ or /) and therefore should be platform independent.
Hope this helps.