473,395 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Regular Text

Hallo,
I am new to python.
I wrote a program to retrieve the filepath. eg. C:\Programs\Python\
and write it in a text file
It works fine until the path contains \t or \n. eg. C:\Programs\Python
\new\.
Because of the regular text format, I didn't get what I want in the
text file.

I tried to change the separator from \ to / but python only gives C:/
Programs/Python\new/.

How should I do to make sure that the program writes the correct path
in the text file?

Jun 11 '07 #1
3 1211
En Mon, 11 Jun 2007 05:53:55 -0300, <ja******@yahoo.co.ukescribió:
Hallo,
I am new to python.
I wrote a program to retrieve the filepath. eg. C:\Programs\Python\
and write it in a text file
It works fine until the path contains \t or \n. eg. C:\Programs\Python
\new\.
Because of the regular text format, I didn't get what I want in the
text file.

I tried to change the separator from \ to / but python only gives C:/
Programs/Python\new/.

How should I do to make sure that the program writes the correct path
in the text file?
In your code, you should use string literals like

my_path = r"C:\Programs\Python\new"
my_path = "C:\\Programs\\Python\\new"

But you said "a program to retrieve the filepath" - and I understand that
you dont have a string literal, and you compute it somehow. Escape
characters should not be a problem then. Have you verified the contents of
the text file? With notepad?

--
Gabriel Genellina

Jun 11 '07 #2
Wow, that is fast. Thanks.
In your code, you should use string literals like

my_path = r"C:\Programs\Python\new"
my_path = "C:\\Programs\\Python\\new"

But you said "a program to retrieve the filepath" - and I understand that
you dont have a string literal, and you compute it somehow. Escape
characters should not be a problem then. Have you verified the contents of
the text file? With notepad?
I meant, I used a GUI-Tkinter Script to retrieve the input(the
directory). my program is supposed to
1. get the directory from the GUI Script,
with my_path= FieldValue.insert(n, variable.get())
2. open a text file
3. and edit a filepath in the file,
4 then saving as another new file...

if that is the case, how should I do, in order to get the input in the
correct format??

Jun 11 '07 #3
ja******@yahoo.co.uk wrote:
Wow, that is fast. Thanks.
>In your code, you should use string literals like

my_path = r"C:\Programs\Python\new"
my_path = "C:\\Programs\\Python\\new"

But you said "a program to retrieve the filepath" - and I understand that
you dont have a string literal, and you compute it somehow. Escape
characters should not be a problem then. Have you verified the contents
of the text file? With notepad?

I meant, I used a GUI-Tkinter Script to retrieve the input(the
directory). my program is supposed to
1. get the directory from the GUI Script,
with my_path= FieldValue.insert(n, variable.get())
2. open a text file
3. and edit a filepath in the file,
4 then saving as another new file...

if that is the case, how should I do, in order to get the input in the
correct format??
The user can input literals like "...\t..." via the GUI, and Python will
interpret the sequence "\t" as a backslash followed by the letter t. If you
want to allow the user to use forward slashes, too, apply
os.path.normpath():

.... os.path.normpath(variable.get()) ...

Peter
Jun 11 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
4
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following...
4
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
9
by: netimen | last post by:
I have a text containing brackets (or what is the correct term for '>'?). I'd like to match text in the uppermost level of brackets. So, I have sth like: 'aaaa 123 < 1 aaa < t bbb < a <tt ff 2...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.