Can you encapsulate the contents of the file in a root element before
processing?
- Original Message -
From: rail shafigulin
To: tutor@python.org
Sent: Tuesday, August 30, 2011 10:27 AM
Subject: [Tutor] xml parsing without a root element
hello everyone.
i need to pa
I think Steven and Alan misunderstood the Rayon's question.
Rayon is using his telnet script to pass commands to a device ONE AT A TIME.
Then he breaks the connection and reconnects for the next command..
He is asking how to open a telnet connection, pass MULTIPLE commands, then
close the se
Or, open the file as a blob (one long string) and do a single 'replace'.
fin = open("dirtyfile.txt", 'r').read().replace('## ', '#')
open("dirtyfile.txt", 'w').write(fin)
or,
open("dirtyfile.txt", 'w').write(open("dirtyfile.txt",
'r').read().replace('## ', '#'))
- Original Message --
I think I understand.
One thing you can do is create a "myprogram.bat" file with an entry something
like:
python c:/myprogrampath/myprogram.py
Put the "myprogram.bat" file in the root directory or any directory in the
PATH. Then it will behave like an executable.
In Linux, it would be "m
I'm not contradicting anyone, just relating my experience.
I have a large suite of Python programs that run routinely on both Windows
and Linux systems. Some of the programs build large directory tree
structures. I cast all directory delimiters to the forward slash "/". No
problems.
-
Seven years ago, my story was similar. I started off with "The Python Quick
Book" (Manning) and "Python - Visual Quickstart Guide" (Peachpit Press).
Both are very easy to follow. I still pick up the "Quick" book once in a
while for reference.
This "Tutor" list helped a lot. I learned by tryi
It's difficult to see exactly what the data looks like as it is received. Where
are the line breaks? At the commas?
Is the "header" just the first line? Is "1Time" considered part of the header?
Is everything after "1Time" considered "data"?
I can see several simple alternatives to your method
FYI...
There is a non-Python commercial program called XMLSpy which displays a visual
tree rendition of an XML schema (.xsd) file. The schema file can be created or
manipulated with Python/ElementTree.
Maybe it can help you in your program development.
- Original Message -
Fro
"join" operates on lists. It "joins" the elements of the list using the
leading character or string as the delimiter. In this case it is NUL.
Try putting a character or string, like 'XX\n' in front of the ".join" in
both places. It should illustrate what's really happening.
"XX\n".jo
I suggest something like:
try:
os.makedirs(path)
except:
pass
open("%s/%s" % (path, filename), 'w').write(filedata)
- Original Message -
From: "Emile van Sebille"
To:
Sent: Monday, September 13, 2010 11:56 AM
Subject: Re: [Tutor] What's the best way to ask forgiveness here?
I have Python code that opens a telnet session with a network device and
performs a multitude of tasks. Now, I am trying to establish and maintain an
SSH connection as an alternative to telent. My research has found that the SSH
implementation some network device manufacturers use is not consis
- Original Message -
From: "nitin chandra"
To:
Sent: Sunday, August 08, 2010 7:29 AM
Subject: Re: [Tutor] Reading every 5th line
Thank you all.
@Dave - Thank you for the tip. No this is not a class exercise, that
is assured.
Will let know how much progress i made.
Truly, I am s
- Original Message -
From: "nitin chandra"
To:
Sent: Sunday, August 08, 2010 5:04 AM
Subject: [Tutor] Reading every 5th line
Hello Everyone,
I am to make a small programme for a friend of mine
where i am to start reading from 14th (string) from a file and then
read every 5th row.
You wouldn't gain much with a Pyton script. You can specify the extension
with "assoc".
Try "assoc .zip".
But if you want to try it anyway, look at the "popen2" module (depreciated)
or the "subprocess" module to extract the data and assign it to a variable
that you can parse any way you lik
I agree with Steven D'Aprano. Keep the code as simple as possible.
A simple text file with a variable/value pair on each line is very easy to
parse and store in a Dictionary object. You can use any convenient
delimiter; "=", ":", "$", ...
Nesting items under categories takes just a little mo
There are probably "return" characters at the end of each "line" from the
"grocery_list".
Try using the String method "line.strip()".
Or "grocery_list.read().splitlines()"
- Original Message -
From: "Eric Hamiter"
To:
Sent: Wednesday, July 14, 2010 8:46 AM
Subject: [Tutor] Sea
How about this?
List = [1, 2, 3, 3, 3, 4, 5, 5]
for Item in list(set(List)):
print Item, List.count(Item)
- Original Message -
From: Ken G.
To: Steven D'Aprano
Cc: tutor@python.org
Sent: Friday, June 11, 2010 9:09 AM
Subject: Re: [Tutor] Looking for duplicates within
17 matches
Mail list logo