473,320 Members | 1,848 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,320 software developers and data experts.

trouble using \ to escape %

I'm writing a python script that modifies the smb.conf file, and i need
to write the characters '%U' in the file. I tried making a string like
so:

str1 = "[%s%s]\n\tpath = /mnt/samba/%s%s/\%U" % (list[0], list[1],
list[0], list[1])

but i keep getting: "TypeError: not enough arguments for format
string". I've also tried making the string:

str1 = "[%s%s]\n\tpath = /mnt/samba/%s%s/\%" % (list[0], list[1],
list[0], list[1])

but i get: "ValueError: incomplete format". These errors lead me to
believe that for some reason it is not escaping the '%' character.
There has to be a way to write '%' to a file. Thanks in advance..

Cheers
-Lucas Machado

Jul 19 '05 #1
4 2912
Lucas Machado wrote in news:1113606334.524947.54630
@l41g2000cwc.googlegroups.com in comp.lang.python:
str1 = "[%s%s]\n\tpath = /mnt/samba/%s%s/\%U" % (list[0], list[1],
list[0], list[1])


In a format string use '%%' for a single % char':

str1 = "[%s%s]\n\tpath = /mnt/samba/%s%s/%%U" % (list[0], list[1],list[0],
list[1])
Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 19 '05 #2
In article <11*********************@l41g2000cwc.googlegroups. com>,
"Lucas Machado" <LM*******@gmail.com> wrote:
I'm writing a python script that modifies the smb.conf file, and i need
to write the characters '%U' in the file.


print "%s = %%U" % "a" yields a = %U for me.

Maarten
Jul 19 '05 #3
Lucas Machado wrote:
I'm writing a python script that modifies the smb.conf file, and i need to write the characters '%U' in the file. I tried making a string like so:

str1 = "[%s%s]\n\tpath = /mnt/samba/%s%s/\%U" % (list[0], list[1],
list[0], list[1])

but i keep getting: "TypeError: not enough arguments for format
string". I've also tried making the string:

str1 = "[%s%s]\n\tpath = /mnt/samba/%s%s/\%" % (list[0], list[1],
list[0], list[1])

but i get: "ValueError: incomplete format". These errors lead me to
believe that for some reason it is not escaping the '%' character.
There has to be a way to write '%' to a file. Thanks in advance..

percentage = 93
# The string % operator uses "%%" for the percent sign.
format_string = "%d%% of all statistics are made up on the spot."
print format_string % percentage 93% of all statistics are made up on the spot. # When the % operator is not used, "%" is just another character.
print format_string %d%% of all statistics are made up on the spot.


Jul 19 '05 #4
On 15 Apr 2005 16:05:34 -0700, "Lucas Machado" <LM*******@gmail.com>
wrote:
I'm writing a python script that modifies the smb.conf file, and i need
to write the characters '%U' in the file. I tried making a string like
so:

str1 = "[%s%s]\n\tpath = /mnt/samba/%s%s/\%U" % (list[0], list[1],
list[0], list[1])

but i keep getting: "TypeError: not enough arguments for format
string". I've also tried making the string:

str1 = "[%s%s]\n\tpath = /mnt/samba/%s%s/\%" % (list[0], list[1],
list[0], list[1])

but i get: "ValueError: incomplete format". These errors lead me to
believe that for some reason it is not escaping the '%' character.
There has to be a way to write '%' to a file. Thanks in advance..


Looks like you've already got your answer, but here's some META-help:
what to do when you have a problem and your internet connection is
broken:

1. GUESS. Extrapolation from examples like DLE DLE in networking, $$
in m4 and \\ in *almost* everything might suggest trying %%

2. READ THE DOCS. Don't know what platform you're running on, but one
of what a recent blogger called "hopeless Windows people" [like me]
would do is this:

Start->Programs->Python 2.4->Python manuals, click on the Index tab,
type %, hit Enter ... scrolling down leads to a table of conversion
types, the last of which is the somewhat tautological """% No argument
is converted, results in a "%" character in the result."""

HTH,
John
Jul 19 '05 #5

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

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
3
by: Thorsten Walenzyk | last post by:
Hi all, I'm pretty new to PHP. So far I know regular expression only from Perl I've written a perl script which I now want to port to PHP. It works in PErl, but gives my a headache in PHP. ...
14
by: Ian Rastall | last post by:
Sorry for the double question. I'm having a terrible time figuring out how to escape apostrophes in my mySQL database. Perhaps they have to be escaped in the PHP, using mysql_real_escape_string? ...
0
by: Fernando Rodriguez | last post by:
Hi, I have a filewhose contents looks like this: Compression=bzip/9 OutputBaseFilename=$<OutputFileName> OutputDir=$<OutputDir> LicenseFile=Z:\apps\easyjob\main\I18N\US\res\license.txt ...
1
by: google | last post by:
It would seem that when I assign an HTML entity to a form text input using "inline" javascript that it will display properly. But when trying to set it via a function call, the entity text shows...
6
by: OriginalBrownster | last post by:
Hi there... I'm still pretty new to turbogears. but i have gotten pretty familiar with it i'm just trying to clear something up, i'm having a difficult time using \ when declaring a string...
3
by: placid | last post by:
Hi All, I have these files; which are Merge Request (ClearCase) files that are created by a Perl CGI script (being re-written in Python, as the HTML/ JavaScript have been mixed with Perl,...
2
by: Rozzy | last post by:
Hi, I'm having trouble using the proper terminology, so bear with me, I am trying to submit text to a mysql database. I want to be able to allow formatting of this content (like breaking it up into...
4
Xx r3negade
by: Xx r3negade | last post by:
I'm using regular expressions to parse HTML hyperlinks and I've run into a problem. I'm trying to escape characters such as '.' and '?' for use in regular expressions, but it's not working #...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.