import sys showing paths with double backslash [duplicate] - python

This question already has answers here:
How to get rid of double backslash in python windows file path string? [duplicate]
(5 answers)
Why do backslashes appear twice?
(2 answers)
Closed 2 years ago.
I am using Spyder when I import the environmental variables using:
import sys
print(sys.path)
I get the following:
['C:\\Users\\james', 'C:\\Python\\Anaconda3\\python37.zip', 'C:\\Python\\Anaconda3\\DLLs', 'C:\\Python\\Anaconda3\\lib', 'C:\\Python\\Anaconda3', '', 'C:\\Python\\Anaconda3\\lib\\site-packages', 'C:\\Python\\Anaconda3\\lib\\site-packages\\win32', 'C:\\Python\\Anaconda3\\lib\\site-packages\\win32\\lib', 'C:\\Python\\Anaconda3\\lib\\site-packages\\Pythonwin', 'C:\\Python\\Anaconda3\\lib\\site-packages\\IPython\\extensions', 'C:\\Users\\james\\.ipython']
I am wondering why I get double backslashes, while the tutorial I am watching displays the paths with a single forward slash. eg
['C:/Users/james', ...

The difference is that your tutorial is on not-windows system, and directories are like this/is/path. On Windows, the directories are like this\is\path. But in Python and in most programming languages, \(backslash) is used for escapes, so to writethis\is\path you need to write 2 slashes.

Related

Python Import Syntax Rules [duplicate]

This question already has answers here:
Python module with a dash, or hyphen (-) in its name
(2 answers)
What is the naming convention in Python for variable and function?
(15 answers)
Closed 11 months ago.
I've been doing some searching but I couldn't find any consensus on the syntax allowed for imports.
I threw an syntax error for this import and was wondering if there was documentation on allowable syntax.
import some-module
# Do stuff.
You can't use hyphen('-') symbol in any names in Python as this is regarded as substraction operator. Use underscore ('_') instead.

What is the Python ` symbol [duplicate]

This question already has answers here:
What do backticks mean to the Python interpreter? Example: `num`
(3 answers)
Meaning of the backtick character in Python
(2 answers)
Closed 1 year ago.
Lots of old python code I look in has this ` symbol around a lot of stuff, what does it do? Now it is not considered valid syntax, obviously.
And I don't think it is just another string identifier, its sometimes wrapped around functions in the code I'm looking at.
Any help will be appreciated.

How to suppress * as a wildcard, instead interpret as character? [duplicate]

This question already has answers here:
Prevent expansion of wildcards in non-quoted python script argument when running in UNIX environment
(5 answers)
Closed 3 years ago.
I am working with files that have an asterisk in the filenames.
I have a list of certain ones I am interested in but whenever I loop through them, the "*" in the name is interpreted as a wildcard.
For example: filenames are A*01:02 and A*02.
I only want to extract A*02 but the "*" is interpreted as a wildcard and both A*01:02 and A*02 are used.
How can I suppress the wildcard "*" and interpret it as a character instead?
Quote "A*02" or use a backslash as in A\*02.

Opencv , imwrite, and unicode character problems. [duplicate]

This question already has answers here:
opencv imread() on Windows for non-ASCII file names
(4 answers)
How do I read an image from a path with Unicode characters?
(5 answers)
Closed 5 years ago.
It seems if my file path or file name has unicode characters, I can't use opencv's imwrite method (no explicit error comes, but folders are empty).
I'm using Windows 7 and Python 3.6.
If I use non-unicode specific characters, the imwrite method will work fine.
The unicode-characters in question are greek letters:
C:\Users\Moondra\Desktop\TEMP\LRF Spinning Ένα διασκεδαστικό ψάρεμαδιάφορα ψάρια \image_459.jpg
Is there some argument I can use to allow imwrite with unicode characters?
Thank you.

Python - Spaces in Filenames [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
How to escape os.system() calls in Python?
Is there a Python method of making filenames safe (ie. putting \ infront of spaces and escaping ( , ), symbols) programatically in Python?
Spaces are already "safe" for Python in open(). As for os.system() and similar functions, use subprocess instead.
>>> import pipes
>>> pipes.quote("\&*!")
"'\\&*!'"

Categories

Resources