[issue21253] unittest assertSequenceEqual can lead to Difflib.compare() crashing on mostly different sequences
Ernesto Eduardo Medina Núñez added the comment: While this gets fixed, can you provide a workaround? or recommend another library? -- nosy: +Ernesto Eduardo Medina Núñez ___ Python tracker <https://bugs.python.org/issue21253> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3548] subprocess.pipe function
Changes by Ernesto Menéndez pya...@gmail.com: -- nosy: +Netto ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue3548 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5315] signal handler never gets called
Changes by Ernesto Menéndez pya...@gmail.com: -- nosy: +Netto ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5315 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1856] shutdown (exit) can hang or segfault with daemon threads running
Changes by Ernesto Menéndez pya...@gmail.com: -- nosy: +Netto ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1856 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
On copying arrays
Is there a conceptual difference between best =test[:] and best = [x for x in test] ? test is a list of real numbers. Had to use the second form to avoid a nasty bug in a program I am writing. I have to add too that I was using psyco in Python 2.5.1. Regards, Ernie. -- http://mail.python.org/mailman/listinfo/python-list
Re: Cascading ifs
tbl = [(my_regex, doSomething), (my_regex2, doSomething2), (my_regex3, doSomething3)] for regex, fun in tbl: match = regexp.match(line) if match: fun(line) break Thank you for the idea. This is a bit more difficult when functions need to work with a common context, but in that case I could store the context in an object and use the object's methods. Thanks, Ernesto -- http://mail.python.org/mailman/listinfo/python-list
Cascading ifs
Hi experts, How would you do this without the more and more indenting cascade of ifs?: match = my_regex.search(line) if match: doSomething(line) else: match = my_regex2.search(line) if match: doSomething2(line) else: match = my_regex3.search(line) if match: doSomething3(line) etc. Thanks in advance and regards, Ernesto -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a commas-in-between idiom?
I've collected a bunch of list pydioms and other notes here: http://effbot.org/zone/python-list.htm Thank you for the suggestion. Ernesto -- http://mail.python.org/mailman/listinfo/python-list
Is there a commas-in-between idiom?
Hi experts, it's very common that I have a list and I want to print it with commas in between. How do I do this in an easy manner, whithout having the annoying comma in the end? code list = [1,2,3,4,5,6] # the easy way for element in list: print element, ',', print # this is what I really want. is there some way better? if (len(list) 0): print list[0], for element in list[1:]: print ',', element, /code Thx, Ernesto -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a commas-in-between idiom?
Ernesto García García wrote: Hi experts, it's very common that I have a list and I want to print it with commas in between. How do I do this in an easy manner, whithout having the annoying comma in the end? code list = [1,2,3,4,5,6] # the easy way for element in list: print element, ',', print # this is what I really want. is there some way better? if (len(list) 0): print list[0], for element in list[1:]: print ',', element, /code Thx, Ernesto mylist = [1,2,3,4,5,6] print ','.join(map(str, mylist)) Great solution! Thank all of you, Ernesto -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a commas-in-between idiom?
Tim Peters wrote: More idiomatic as if len(list) 0: and even more so as plain if list: print list[0], for element in list[1:]: print ',', element, Do you really want a space before and after each inter-element comma? No, but it was only an example. I usually go for string concatenation. An often-overlooked alternative to playing with ,.join() is: print str(list)[1:-1] That's funny! Not that I like it more that the join solution, but funny nevertheless. Thank you, Ernesto -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythondocs.info : collaborative Python documentation project
Somehow all of the above discussions did not mention having examples or demos built-in for the language itself: majorfunction.example() demo(package) or package.demo() search engine in local html documentation apropos() The statistical software R is bettter in this respect if you really wanted such kind of help. -Ernie Adorio -- http://mail.python.org/mailman/listinfo/python-list
[Newbie] List from a generator function
Hi all, I'm sure there is a better way to do this: [random.choice(possible_notes) for x in range(length)] Regards, Ernesto -- http://mail.python.org/mailman/listinfo/python-list
Re: [Newbie] List from a generator function
I'm sure there is a better way to do this: [random.choice(possible_notes) for x in range(length)] There is at least a better way to ask the question. The subject has nothing to do with the body of your post. Or am I missing something? Sorry, I should have explained better. I just want to build a fix length list made up of elements generated by a function, in this case random.choice(). I don't like my list comprehension, because I'm using that dumb variable x and the range() list. Ernesto -- http://mail.python.org/mailman/listinfo/python-list
Re: building lists of dictionaries
parinfo = [{'value':0., 'fixed':0, 'limited':[0,0], 'limits':[0.,0.]}]*6 With this, you are creating a list with 6 references to the same list. Note that the left operand of '*' is evaluated only once before multiplying it six times. Regards, Tito -- http://mail.python.org/mailman/listinfo/python-list
Re: [Newbie] List from a generator function
Thank you guys. So the answer is to keep with the original form, perhaps with xrange. Ernesto -- http://mail.python.org/mailman/listinfo/python-list
Re: building lists of dictionaries
parinfo = [{'value':0., 'fixed':0, 'limited':[0,0], 'limits':[0.,0.]}.copy() for i in xrange(0,6)] However, this will still reference internal lists that have been referenced multiple times, such that parinfo[5]['limited'] [0, 0] parinfo[4]['limited'][0] = 2 parinfo[5]['limited'] [2, 0] Interesting. Cut-and-paste to my python prompt and I get parinfo[5]['limited'] [0, 0] Tried both Python 2.4.1 and 2.5 beta, Linux, GCC 4.0.2 Of course. The expression within the list comprehension is evaluated for each iteration, so that the objects are recreated each time. The copy() for the dictionary is also not needed: parinfo = [{'value':0., 'fixed':0, 'limited':[0,0], 'limits':[0.,0.]} for i in xrange(0,6)] parinfo [{'limited': [0, 0], 'fixed': 0, 'limits': [0.0, 0.0], 'value': 0.0}, {'limited': [0, 0], 'fixed': 0, 'limits': [0.0, 0.0], 'value': 0.0}, {'limited': [0, 0], 'fixed': 0, 'limits': [0.0, 0.0], 'value': 0.0}, {'limited': [0, 0], 'fixed': 0, 'limits': [0.0, 0.0], 'value': 0.0}, {'limited': [0, 0], 'fixed': 0, 'limits': [0.0, 0.0], 'value': 0.0}, {'limited': [0, 0], 'fixed': 0, 'limits': [0.0, 0.0], 'value': 0.0}] parinfo[0]['limited'] [0, 0] parinfo[0]['limited'][0]=1 parinfo [{'limited': [1, 0], 'fixed': 0, 'limits': [0.0, 0.0], 'value': 0.0}, {'limited': [0, 0], 'fixed': 0, 'limits': [0.0, 0.0], 'value': 0.0}, {'limited': [0, 0], 'fixed': 0, 'limits': [0.0, 0.0], 'value': 0.0}, {'limited': [0, 0], 'fixed': 0, 'limits': [0.0, 0.0], 'value': 0.0}, {'limited': [0, 0], 'fixed': 0, 'limits': [0.0, 0.0], 'value': 0.0}, {'limited': [0, 0], 'fixed': 0, 'limits': [0.0, 0.0], 'value': 0.0}] Ernesto -- http://mail.python.org/mailman/listinfo/python-list
Global except condition
Within the scope of one Python file (say myFile.py), I'd like to print a message on ANY exception that occurs in THAT file, dependent on a condition. Here's the pseudocode: if anyExceptionOccurs(): if myCondition: print Here's my global exception message Is this functionality possible in python? If so, how? -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting floating point to string in non-scientific format
See also non-exponential floating point representation in http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/358361 by R. Hettinger. -- http://mail.python.org/mailman/listinfo/python-list
Advanced Treeview Filtering Help
Hi you all, I am developping a python application which connects to a database (postresql) and displays the query results on a treeview. In adittion to displaying the info i do need to implement filtering facility for all the columns of the treestore/liststore model in order to allow the user an easy search method to find the desired information. The treestore is created with information related to cars, the columns are: car_model car_year car_color car_type car_price chevrolet 1998 white sedan 5.000 US$ ford 1996blue sedan 3.000 US$ - - -- - - - -- - - - -- - I have been able to allow filtering to only one column, an extract of my code as follows: #treestore creation self.treestore = gtk.TreeStore(str, str, str, str, str) self.modelfilter = self.treestore.filter_new() self.treeview=gtk.TreeView() #append treestore columns self.treestore.append(None, [self.model, self.year, self.color, self.type, self.price] #set treestore model to allow filtering by car_model column self.modelfilter.set_visible_func(self.visible_cd, self.car_model) #the function to filter the treestore def visible_cb(self, treestore, iter, x) return treestore.get_value(iter, 0) in x #self.car_model is a list of items wich change according to user needs and can be controlled by a #secundary treeview or a button this function is not explained. The code mentioned above does work but i can only fllter by defining criterias in the first column. To allow filtering to all the columns i do need the following code to work: - treemodelfilter.set_modify_func(types, func, data=None) def func(model, iter, column, user_data) - where types should be: types = (str, str, str, str, str) the function to allow filtering: def visible_cb(self, treestore, column, iter, x) return treestore.get_value(iter, column) in x and the rest of the code never changes...however it is not woking. Any suggestion about the code mention?? am i making mistakes?? where?? do i have to pass the column number someway to the visible_cb function??? how?? can any of you suggest a code example to follow and find out how the treeview must be coded in order to allow multicolumn filtering??? thanks in advance for your support.. Juan -- http://mail.python.org/mailman/listinfo/python-list
fwd: Advanced Treeview Filtering Help
by the way, iam using pygtk to develop the GUI Regards.- -- http://mail.python.org/mailman/listinfo/python-list
Re: [pygtk] Advanced Treeview Filtering Trouble
Thanks a lot! it did work!! :) -- http://mail.python.org/mailman/listinfo/python-list
[Newbie] Referring to a global variable inside a function
Hi experts, I've built a class for parsing a user-defined list of files and matching lines with a user-defined list of regular expressions. It looks like this: code import re import glob class LineMatcher: Parses a list of text files, matching their lines with the given regular expressions and executing associated actions. def __init__(self): # List of file names to parse for matching. self.file_names = [] # Association of reg expressions to actions to execute when match. self.regexp_action = {} def go(self): for file_name in self.file_names: file = open(file_name) for line in file: for regexp, action in self.regexp_action.items(): match = regexp.match(line) if match: action(line, match.groupdict()) def add_files(self, file_pattern): self.file_names.extend(glob.glob(file_pattern)) def add_action(self, regexp_string, action): self.regexp_action[re.compile(regexp_string)] = action /code But then, when I try to use my class using actions with memory it will fail: code import LineMatcher global count count = 0 def line_action(line, match_dictionary): count = count + 1 line_matcher = LineMatcher.LineMatcher() line_matcher.add_files('*') line_matcher.add_action(r'(?Pline.*)', line_action) line_matcher.go() /code The error is: console Traceback (most recent call last): File Test.py, line 12, in ? line_matcher.go() File LineMatcher.py, line 21, in go action(line, match.groupdict()) File Test.py, line 7, in line_action count = count + 1 UnboundLocalError: local variable 'count' referenced before assignment /console How would you do this? Regards, Tito -- http://mail.python.org/mailman/listinfo/python-list
Re: [Newbie] Referring to a global variable inside a function
How would you do this? def line_action(line, match_dictionary): global count # make it a module-global variable, not a function-local count = count + 1 /F OK, I had put it on the global block. Thanks, Ernesto -- http://mail.python.org/mailman/listinfo/python-list
Re: Terminating a subprocess question
Ernesto wrote: I'm opening a telnet session with the subprocess call below. I then wait ten seconds and attempt to terminate the telnet window I created. Unfortuantely, the telnet window remains after the 'TerminateProcess call below. This software works great for opening an executable directly (i.e. Handle = subprocess.Popen(myProgram.exe), but here I'm using the Windows 'start' command inside, which I think has an effect. Is there another way I can force termination of the telnet session I create ? # CODE STARTS HERE TSS_Log_Path = C:\\Log_Outputs\\TSS_Log_Test.txt TSS_Handle = subprocess.Popen(start telnet.exe -f + TSS_Log_Path + localhost 6000,shell=True) time.sleep(10) ctypes.windll.kernel32.TerminateProcess(int(TSS_Handle._handle), -1) # Terminate the TSS_Log # END CODE Actually, the original answer I was looking for to for a hard close of telnet in Windows is: TSS_Handle = subprocess.Popen(TASKKILL /F /IM telnet.exe, shell=True) It is almost definitely true though that it is safer to use telnetlib. I just don't have the time to adjust my entire huge application at the moment. Thanks all. -- http://mail.python.org/mailman/listinfo/python-list
Free Python IDE ?
I'm looking for a tool that I can use to step through python software (debugging environment). Is there a good FREE one (or one which is excellent and moderately priced ) ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Terminating a subprocess question
Diez B. Roggisch wrote: Ernesto wrote: I'm opening a telnet session with the subprocess call below. I then wait ten seconds and attempt to terminate the telnet window I created. Unfortuantely, the telnet window remains after the 'TerminateProcess call below. This software works great for opening an executable directly (i.e. Handle = subprocess.Popen(myProgram.exe), but here I'm using the Windows 'start' command inside, which I think has an effect. Is there another way I can force termination of the telnet session I create ? Maybe using the module telnetlib instead? Diez oh ok great ! But how would I create a log file. Couldn't seem to find that here: http://python.active-venture.com/lib/telnet-objects.html http://pydoc.org/1.6/telnetlib.html Plus, everytime, I tried to use the read_all object, my program crashed pretty hard... tn = telnetlib.Telnet(localhost,6000) print tn.read_all() # CRASH -- http://mail.python.org/mailman/listinfo/python-list
Re: Terminating a subprocess question
Fredrik Lundh wrote: Ernesto wrote: Plus, everytime, I tried to use the read_all object, my program crashed pretty hard... tn = telnetlib.Telnet(localhost,6000) print tn.read_all() # CRASH that's an unusual error message. are you sure you didn't get a traceback? if so, what did it say? /F I was running it directly in a python shell. After the tn.read_all() call, the python shell window freezes up, and I have to do a hard termination of the shell. There is no traceback message, just a freeze. -- http://mail.python.org/mailman/listinfo/python-list
Re: Terminating a subprocess '.exe'
Fredrik Lundh wrote: Ernesto wrote: I launch a Windows executable and wish to close it from Python. The code is below. Normally, my program waits for rib.exe to finish, but I'd like to be able to close it from python if possible. (I suppose if I was going to do this, I wouldn't use .wait() ) Any ideas ? # Launch a program without launching a whole new cmd prompt def launchWithoutConsole(command, args): Launches 'command' windowless and waits until finished startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW return subprocess.Popen([command] + args, startupinfo=startupinfo).wait() ribHandle = launchWithoutConsole(rib.exe,[recovery]) # Is there a way to close rib.exe using ribHandle ? for 2.4 and earlier, see: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/347462 for 2.5 (upcoming) and later, you can use either the ctypes method or the _subprocess.TerminateProcess() call. /F Works EXACTLY the way I want it to. Thanks Fredrik ! -- http://mail.python.org/mailman/listinfo/python-list
Terminating a subprocess '.exe'
I launch a Windows executable and wish to close it from Python. The code is below. Normally, my program waits for rib.exe to finish, but I'd like to be able to close it from python if possible. (I suppose if I was going to do this, I wouldn't use .wait() ) Any ideas ? # Launch a program without launching a whole new cmd prompt def launchWithoutConsole(command, args): Launches 'command' windowless and waits until finished startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW return subprocess.Popen([command] + args, startupinfo=startupinfo).wait() ribHandle = launchWithoutConsole(rib.exe,[recovery]) # Is there a way to close rib.exe using ribHandle ? -- http://mail.python.org/mailman/listinfo/python-list
Send email notification
Is there a special module for mail ? I'd like to send an email [to 'n' unique email addresses] from a python script. Thanks ! -- http://mail.python.org/mailman/listinfo/python-list
Re: Send email notification
I guess that was jerk-off version of: smtplib Thanks a lot. -- http://mail.python.org/mailman/listinfo/python-list
Re: * 'struct-like' list *
Thanks for the approach. I decided to use regular expressions. I'm going by the code you posted (below). I replaced the line re.findall line with my file handle read( ) like this: print re.findall(pattern, myFileHandle.read()) This prints out only brackets []. Is a 're.compile' perhaps necessary ? Raymond Hettinger wrote: # Approach for more loosely formatted inputs import re pattern = '''(?x) Name:\s+(\w+)\s+ Age:\s+(\d+)\s+ Birthday:\s+(\d+)\s+ SocialSecurity:\s+(\d+) ''' print re.findall(pattern, inputData) -- http://mail.python.org/mailman/listinfo/python-list
Regular Expression Syntax Help
I'm trying to get the right syntax for my regular expression. The string I'm trying to parse is: # myString [USELESS DATA] Name: David Dude [USELESS DATA] Right now, I'm using the following code: pattern_Name= '''(?x) Title:\s+(\w+)\s+ ''' names = re.findall(pattern_Name, myString) print names This prints out a list containing only the first names. I want to search the string until it finds a '\n' endline, but I experimented with that, and couldn't find what I need. -- http://mail.python.org/mailman/listinfo/python-list
Re: * 'struct-like' list *
Thanks ! -- http://mail.python.org/mailman/listinfo/python-list
Re: Regular Expression Syntax Help
The word Title there should be Name. What I really need is the pattern for getting the entire string after Name: until a '\n' is found. -- http://mail.python.org/mailman/listinfo/python-list
Re: * 'struct-like' list *
Thanks tons ! -- http://mail.python.org/mailman/listinfo/python-list
Re: Regular Expression Syntax Help
So now I need to add the requirement that only Name: 's which are followed by Request: Play or Request: Next ANYWHERE between the previous titles and the new titles. Can I use RE's for that ? Ernesto wrote: I'm trying to get the right syntax for my regular expression. The string I'm trying to parse is: # myString [USELESS DATA] Name: David Dude [USELESS DATA] Right now, I'm using the following code: pattern_Name= '''(?x) Title:\s+(\w+)\s+ ''' names = re.findall(pattern_Name, myString) print names This prints out a list containing only the first names. I want to search the string until it finds a '\n' endline, but I experimented with that, and couldn't find what I need. -- http://mail.python.org/mailman/listinfo/python-list
tricky regular expressions
I'm trying to get the right syntax for my regular expression. The string I'm trying to parse is: # myString [USELESS DATA] Request: Play [USELESS DATA] Name: David Dude [USELESS DATA] Request: Next [USELESS DATA] Name: Ernesto Python User # Right now, I'm using the following code: pattern_Name= '''(?x) Title:\s+(.+) ''' names = re.findall(pattern_Name, myString) print names This captures all of the names, but I want an added requirement: Only capture names which are followed (not necessarily immediately) by Request: Play or Request: Next. I guess the regular expression would look something like: '''(?x) [Request: Play OR Request: Next][intermediate data]Title:\s+(.+) ''' I didn't see any RE constructs like this in the docs, but I have a feeling it's possible. -- http://mail.python.org/mailman/listinfo/python-list
tricky regular expressions
So regular expressions have been good to me so far, but now my problem is a bit trickier. The string I'm getting data from looks like this: myString = [USELESS DATA] Request : Play [USELESS DATA] Title: Beethoven's 5th [USELESS DATA] Request : next [USELESS DATA] Title: song #2 . I'm using this code to search myString: pattern = '''(?x) Title:\s+(.+) ''' Titles = re.findall(pattern, myString) The problem is that I only want the Titles which are either: a) Followed by Request : Play b) Followed by Request : next I'm not sure if I should use RE's or some other mechanism. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: tricky regular expressions
Xavier Morel wrote: Ernesto wrote: I'm not sure if I should use RE's or some other mechanism. Thanks I think a line-based state machine parser could be a better idea. Much simpler to build and debug if not faster to execute. What is a line-based state machine ? -- http://mail.python.org/mailman/listinfo/python-list
Re: tricky regular expressions
Petr Jakes wrote: PS: just wonder why are you asking the same question in two different topics Thanks for the help Peter. That happened accidentally. I meant to only put that in python topic. Aplogies... -- http://mail.python.org/mailman/listinfo/python-list
read file problem
I'm just want to read in the contents of a (text) file. The text file is filled with semiColon delimited floating point strings... 0.456;1.265;99.742;... For some reason, I can't get the contents back when I call file.read() Here's my code. filePath = C:\\folder\\myFile.txt fileHandle = open(filePath, 'r').read(); print fileHandle.read() # This prints nothing when it should print the above values Thanks for the help -- http://mail.python.org/mailman/listinfo/python-list
Size of list
for line in PM_File_Handle.readlines(): PM_fields = line.split(';') # Is there a way to get the size of PM_Fields here ? # Something like size = PM_fields.size( ) # I could not find this attribute in the python docs. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Size of list
Thanks ! -- http://mail.python.org/mailman/listinfo/python-list
Re: read file problem
Thanks to all. -- http://mail.python.org/mailman/listinfo/python-list
* 'struct-like' list *
I'm still fairly new to python, so I need some guidance here... I have a text file with lots of data. I only need some of the data. I want to put the useful data into an [array of] struct-like mechanism(s). The text file looks something like this: [BUNCH OF NOT-USEFUL DATA] Name: David Age: 108 Birthday: 061095 SocialSecurity: 476892771999 [MORE USELESS DATA] Name I would like to have an array of structs. Each struct has struct Person{ string Name; int Age; int Birhtday; int SS; } I want to go through the file, filling up my list of structs. My problems are: 1. How to search for the keywords Name:, Age:, etc. in the file... 2. How to implement some organized list of lists for the data structure. Any help is much appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Re: Making Popen items terminate when program ends.
Peter Hansen wrote: Please see this page: http://docs.python.org/ref/strings.html and read about escape sequences in strings, and about raw strings. Thanks Peter. Forgot about that one. In a way, I wish it *would* have given me trouble, so I could have found it early rather than later. -- http://mail.python.org/mailman/listinfo/python-list
Run Windows shortcut
Assuming the shortcut is in the current directory, how could I launch the shortcut (without waiting for it to finish) ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Run Windows shortcut
Nevermind this is not the design I need. -- http://mail.python.org/mailman/listinfo/python-list
Launch Windows command window....
I'm trying to launch a seperate telnet window from within my python program. The command I thought I was supposed to use is below: os.system(telnet.exe -f C:\Folder\output.txt localhost 6000) This creates a telnet window inside the current window. This is not desirable. I need it to launch a seperate command window for telnet output. Any ideas ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Launch Windows command window....
I'm one step closer... subprocess.Popen(telnet.exe -f C:\Folder\output.txt localhost 6000) is improved, but still doesn't launch a SEPERATE window... -- http://mail.python.org/mailman/listinfo/python-list
Re: Launch Windows command window....
jay graves wrote: This should work but only lightly tested. subprocess.Popen(start telnet.exe -f C:\Folder\output.txt localhost 6000,shell=True) Thanks a lot, but this still didn't launch a seperate telnet window. I just want the telnet window to open up and do it's thing in the background. Thanks again. -- http://mail.python.org/mailman/listinfo/python-list
Re: Launch Windows command window....
wait a minute, that did work correctly. Thanks ! -- http://mail.python.org/mailman/listinfo/python-list
Making Popen items terminate when program ends.
I used Popen to launch a seperate telnet window, like this: subprocess.Popen(start telnet.exe -f C:\Folder\File.txt localhost 6000,shell=True) I is preferable to have this telnet window with the python program. Is there something I can do to that line of code to make that happen, or perhaps another line I can add to the end to force this ? Thanks -- http://mail.python.org/mailman/listinfo/python-list
OS.MKDIR( ) Overwriting previous folder created...
I couldn't find this with a search, but isn't there a way to overwrite a previous folder (or at least not perform osmkdir( ) if your program detects it already exists). Thanks ! -- http://mail.python.org/mailman/listinfo/python-list
Windows - create text file - (newb)
Can Python be used to create (and/or open, read, and write) a text file in Windows (if the path is known) ? -- http://mail.python.org/mailman/listinfo/python-list
Re: OS.MKDIR( ) Overwriting previous folder created...
Ernesto wrote: I couldn't find this with a search, but isn't there a way to overwrite a previous folder (or at least not perform osmkdir( ) if your program detects it already exists). Thanks ! I suppose this also leads to the question of: Is there a way to determine if a path exists or not? Then I could do: if(path exists){} else{mkdir()} -- http://mail.python.org/mailman/listinfo/python-list
Re: OS.MKDIR( ) Overwriting previous folder created...
NEVERMIND ! Here is the solution... # if (os.path.isdir(C:\\MyNewFolder) == 0): os.mkdir(C:\\MyNewFolder) # - thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows - create text file - (newb)
got it . thanks tons. i'm doing the tutorial now. -- http://mail.python.org/mailman/listinfo/python-list
Capture Windows command line output - put in text file
I'm looking for a way to capture command line output from a cmd session. Is there a way to use python to launch the application from the beggining then stream all of the output to a text file ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Capture Windows command line output - put in text file
Ernesto wrote: I'm looking for a way to capture command line output from a cmd session. Is there a way to use python to launch the application from the beggining then stream all of the output to a text file ? Nevermind. This is a telnet question. I'm trying to get telnet localhost output to a text file. -- http://mail.python.org/mailman/listinfo/python-list
subprocess terminate help
def launchWithoutConsole(command, args): Launches 'command' windowless and waits until finished startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW return subprocess.Popen([command] + args, startupinfo=startupinfo).wait() handle = launchWithoutConsole(program.exe,[disconnect]) -- I've been searching for ways to terminate this process so I can exit my program. program.exe is a text based interface which I'm running with python subprocess in a DOS command window. I tried using 'sys.exit()' to end my program, but nothing works. I think I have to somehow terminate the subprocesses I create. Any suggestions? -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess terminate help
Yeah I know. I posted it b/c I was having the same problems and I'm investigating ways to do this. None of those methods gave me desired results for my program. All I want to do is end my python program and return to the DOS prompt. -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess terminate help
A... I figured out a way around this. I'll use program.exe to shut down itself. That way I won't have to use any extension modules. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess terminate help
program.exe ? I was looking at the Windows task manager after I used a Cntrl + C to manually terminate the running python program. The program.exe is apparently ending when I end the python program. -- http://mail.python.org/mailman/listinfo/python-list
Self terminate a python program
how do you self terminate a python program from within the code? something similar to exit(0) in C. I think the problem is that I'm using subprocess and popen to launch a '.exe' file and python is waiting on the .exe file to finish. since it never does, the python program won't end. how can I force it to end? -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.Popen - terminate
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/347462 Also try searching this group for subprocess kill -- http://mail.python.org/mailman/listinfo/python-list
* TypeError - Need help passings args
My program is below. I'm trying to use two Windows .exe files with my command line python interface. I get user input, then call launchWithoutConsole. This was working OK until I introduced the 'args' part. Now I get the following error everytime I call launchWithoutConsole: return subprocess.Popen([command] + args, startupinfo=startupinfo).wait() TypeError: can only concatenate list (not str) to list I'm not sure if it's the WAY I'm passing it or if it's the function itself (which I retrieved from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/409002 ) Please help. Thanks! import subprocess def launchWithoutConsole(command, args): Launches 'command' windowless and waits until finished startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW return subprocess.Popen([command] + args, startupinfo=startupinfo).wait() infinity = 1 #Get user input in iterative loop while infinity: userCommand = raw_input( ) if userCommand == connect: launchWithoutConsole(devcon.exe,'enable @USB\VID_0403PID_6010MI_00\715E4F681') launchWithoutConsole(devcon.exe,'enable @USB\VID_0403PID_6010MI_01\715E4F6810001') elif userCommand == disconnect: launchWithoutConsole(devcon.exe,'disable @USB\VID_0403PID_6010MI_00\715E4F681') launchWithoutConsole(devcon.exe,'disable @USB\VID_0403PID_6010MI_01\715E4F6810001') else: # include full path to rib.exe in quotes. launchWithoutConsole(rib.exe, userCommand) -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows - Need to process quotes in string...
Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: * TypeError - Need help passings args
Thanks, that ran without errors. The only problem now is that it launches devcon.exe without actually passing the parameters to the program. It's as if I just typed devcon at a Windows command prompt and pressed enter. I can't figure out why it doesn't accept my parameter. -- http://mail.python.org/mailman/listinfo/python-list
Subprocess.Popen - passing args help
I'm trying to use Popen to do some command line work Windows XP style. I have devcon.exe which I would use on a Windows command line like so: devcon disable @USB\VID_05E3PID_0605\52CE74B9E16 Using subprocess.Popen, I have something like this: subprocess.Popen([rdevcon.exe,disable,'USB\VID_05E3PID_0605\52CE74B9E16']).wait(); For some reason, the parameters are not getting passed to devcon correctly. Devcon executes, but doesn't behave the same way it does if I type in the command above at a Win Prompt. Any clues as to how to pass these parameters? Thanks, -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess module under Windows 98
This worked for me on XP... not sure for 98... http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/409002 -- http://mail.python.org/mailman/listinfo/python-list
Re: Subprocess.Popen - passing args help
A nice person from another thread helped me... a = 'disable @USB\VID_0403PID_6010MI_00\715E4F681' print a disable @USB\VID_0403PID_6010MI_0015E4F681 \7 is the ASCII bell so your args may be different from what you think. I thought the quote method I have fixes this problem, but I guess I was wrong. Anyone have suggestions on how I can get that parameter in there without the '\7' part getting lost? -- http://mail.python.org/mailman/listinfo/python-list
Windows - Need to process quotes in string...
I'm trying to use a $ delimeter, but it doesn't seem to work. Here is the code: launchWithoutConsole(devcon.exe,d'$enable @USB\VID_0403PID_6010MI_00\715E4F681$) I want to send the string parameter: enable @USB\VID_0403PID_6010MI_00\715E4F681 to the program devcon. The argument itself is a string, but has quotes inside too. I've tried it many different ways and I keep getting syntax errors. Thanks, -- http://mail.python.org/mailman/listinfo/python-list
Re: Execute C code through Python
Peter Hansen wrote: Google found the following (after I read the docs for subprocess and learned about the startupinfo flag, and searched for subprocess startupinfo). Does this help? http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/409002 -Peter Thanks Peter! That's exactly what I need. -- http://mail.python.org/mailman/listinfo/python-list
Re: Execute C code through Python
So i generated the .exe file myFile.exe This is a Windows - text based application. Right now, when I run: import subprocess subprocess.call(myFile) the application starts in its own console window. Is there a way for it to run inside the python interface? Thanks, -- http://mail.python.org/mailman/listinfo/python-list
Re: Execute C code through Python
Fredrik Lundh wrote: Ernesto wrote: Thanks. Can anyone provide an example of using *subprocess* to run helloWorld.C through the python interpreter. compile helloWorld, and run: import subprocess subprocess.call(helloWorld) (any special reason why you couldn't figure this out yourself, given the example provided by gsteff ?) /F There is a reason (though it is not special). I'm new to Python. I looked at all the documentation on subprocess, as well as popen. I couldn't figure it out, so I thought an example (which I thank you for providing) would help me along (which it did). Is there a special reason for you having a problem with me asking for help? I thought that's what this group is for. -- http://mail.python.org/mailman/listinfo/python-list
Compile C program - .pyc file
Is there a way to compile a C program into a .pyc file that has the same behavior as the compiled C program? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Execute C code through Python
Thanks. Can anyone provide an example of using *subprocess* to run helloWorld.C through the python interpreter. -- http://mail.python.org/mailman/listinfo/python-list
Re: Compile C program - .pyc file
Fredrik Lundh wrote: Ernesto wrote: Is there a way to compile a C program into a .pyc file that has the same behavior as the compiled C program? unless you find a C-Python compiler, no. PYC files contain Python bytecode, C compilers usually generate native code for a given machine platform. /F Yeah, I know it can't really be done in ONE step, but I was hoping it was possible in 'n' steps. -- http://mail.python.org/mailman/listinfo/python-list
Execute C code through Python
What's the easiest and quickest way to execute a compiled C command line interface program THROUGH Python? -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing shared library file...
Where is the ctypes mailing list? -- http://mail.python.org/mailman/listinfo/python-list
Wrapper module for Linux shared lib
What's the best resource for finding out how to write a wrapper module for a shared library file *.so* in Linux? -- http://mail.python.org/mailman/listinfo/python-list
Accessing shared library file...
I'm in the process of moving a Python application from Windows to Linux. This means that the drivers for windows .dll now must be Linux drivers shared library file (.so I think). With Windows, I used: ctypes (from ctypes import windll) Then _dll = windll.NAME I'm not sure how to include this new Linux library. Any suggestions? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing shared library file...
The .dll file is a shared library file that is associated with a programming interface for a semi-conductor chip. The chip drivers come in two different flavors: One is a .dll (for Windows) and the other is a shared library file for Linux. The name of the Linux file is nameofFile.so.0.4.5 The company that makes these drivers (FTDI) says that the API's for both OS's are practically the same (except you obviously cannot use WIN32 functions when running on Linux). I wish I knew more about Linux drivers... -- http://mail.python.org/mailman/listinfo/python-list
Re: Ctypes Install in Linux
THANKS !!! -- http://mail.python.org/mailman/listinfo/python-list
Re: Launching Python programs from Linux shell script
Thanks! How do you add Python in Linux to the path? Similar to setting environment variables in Windows. I want to be able to type python when I'm in any directory to launch the interpreter. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Ctypes Install in Linux
I'm trying to install ctypes for Python in Linux. Linux won't let me create /usr/local/lib/python2.4/site-packages/ctypes ... Permission denied ... Anyone know how I could get it to work? It's probably something I need to chmod or change permissions on... Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Ctypes Install in Linux
Thanks for the help. I'm kind of new to Linux, but I am the only user of this machine (just installed Red Hat). How do I make myself a root-user? For the second method you mentioned, how do I add access the PYTHONPATH environment variable? Thanks again! -- http://mail.python.org/mailman/listinfo/python-list
Launching Python programs from Linux shell script
Does anyone know how to start Python program(s) from a Linux shell script? Is it just $python myscript.py ?? Thanks, -- http://mail.python.org/mailman/listinfo/python-list
Where do .pyc files come from?
I noticed in a python distribution there were 5 python files (.py) and 5 other files with the same name, but with the extension .pyc . Is this some kind of compiled version of the .py files. Thanks, -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI - Windows: Where to get started
THANKS SO MUCH FOR ALL YOUR RESPONSES! I will look into everything and find what's right for my project. -- http://mail.python.org/mailman/listinfo/python-list
GUI - Windows: Where to get started
Hi all, Would anyone know a good place to start for learning how to build simple GUI's in Windows XP? I just want users to be able to select a few parameters from a pull-down menu, then be able to run some batch files using the parameters from the pull down menus. I would also need a Browse menu, so users could point to a place on the local disc (ie C:\PointSystemHere). Can anyone give a noob some tips? THANKS!!! -- http://mail.python.org/mailman/listinfo/python-list
Re: Run batch files in Windows XP
Thanks Peter. The issue is I haven't done very much batch programming. I need to prompt the user for input and each batch file is in a different directory. How do I change directories and prompt for user input? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Run batch files in Windows XP
Thanks. Yeah I started to write in Python. Looks like this: ** import os from os.path import join # Get input from user and make sure it is valid fileDirec = raw_input(\nEnter the path of where your STMP3XXX_SDK_FIRMWARE\nis located (i.e. C:\) : ) if not os.path.exists(fileDirec): exit( ** File or path does not exist... exiting ** ) # Builds all binaries simultaneously for SDK 3.050 def buildBinaries(_path): _bootmanagerPath = join(_path, STMP3XXX_SDK_FIRMWARE\DeviceDriver\Media\SmartMedia\BootManager\STMP3500\make) _usbmscPath = join(_path, STMP3XXX_SDK_FIRMWARE\Projects\Sdk\lcdexample\usbmsc\make) _playerPath = join(_path, STMP3XXX_SDK_FIRMWARE\Projects\Sdk\lcdexample\player\make) _mtpPath = join(_path, STMP3XXX_SDK_FIRMWARE\Projects\Sdk\lcdexample\mtp\make) # First build bootmanager...change to that directory # and run the bootmanager file... Similarly for the others... os.chdir(_bootmanagerPath) os.execl((bootmanager.bat),(BOOTMANAGER ALL)) os.chdir(_usbmscPath) os.execl((usbmsc.bat),(USBMSC ALL UPDATER)) os.chdir(_playerPath) os.execl((player.bat),(PLAYER ALL)) os.chdir(_mtpPath) os.execl((mtp.bat),(MTP ALL)) # After gathering user input, call routine to build binaries... buildBinaries(fileDirec) ** The issue is after the first execution of os.execl, the script stops altogether. In other words after bootmanager.bat executes, its over. I would love to Python if I could get all scripts to execute (executing simultaneously would be a major + !) I'll try os.system THANKS!!! -- http://mail.python.org/mailman/listinfo/python-list
Re: Run batch files in Windows XP
Looks like I'm not getting my parameters to my batch file correctly. I'm using os.system like this: os.system('bootmanager.bat %s' %BOOTMANAGER ALL) where 'BOOTMANAGER ALL' is what I type at the command prompt arguments. That must not be right? -- http://mail.python.org/mailman/listinfo/python-list