Re: [Tutor] xml parsing without a root element

2011-08-30 Thread davidheiserca
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

[Tutor] STUPID telnet connection question

2011-06-11 Thread davidheiserca
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

Re: [Tutor] search-replace

2011-06-06 Thread davidheiserca
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 --

Re: [Tutor] Making a script part of the terminal

2011-05-20 Thread davidheiserca
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

Re: [Tutor] create an xls file using data from a txt file

2011-05-11 Thread davidheiserca
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. -

Re: [Tutor] print "Hello, World!"

2011-02-02 Thread davidheiserca
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

Re: [Tutor] Defining Exceptions

2011-02-02 Thread davidheiserca
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

Re: [Tutor] Interactive visualization in python

2010-11-07 Thread davidheiserca
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

Re: [Tutor] join question

2010-10-14 Thread davidheiserca
"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

Re: [Tutor] What's the best way to ask forgiveness here?

2010-09-13 Thread davidheiserca
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?

[Tutor] SSH session problems with network devices

2010-08-26 Thread davidheiserca
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

Re: [Tutor] Reading every 5th line

2010-08-08 Thread davidheiserca
- 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

Re: [Tutor] Reading every 5th line

2010-08-08 Thread davidheiserca
- 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.

Re: [Tutor] Seek suggestions for script for looking up extensions usingC:\>assoc

2010-08-06 Thread davidheiserca
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

Re: [Tutor] xml question

2010-07-26 Thread davidheiserca
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

Re: [Tutor] Searching a text file's contents and comparing them to alist

2010-07-14 Thread davidheiserca
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

Re: [Tutor] Looking for duplicates within a list [SOLVED]

2010-06-11 Thread davidheiserca
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