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.o
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
:
doSomething3(line)
etc.
Thanks in advance and regards,
Ernesto
--
http://mail.python.org/mailman/listinfo/python-list
> 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
fore 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,
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?
>
>
>
> list = [1,2,3,4,5,6]
>
>
s what I really want. is there some way better?
if (len(list) > 0):
print list[0],
for element in list[1:]:
print ',', element,
Thx,
Ernesto
--
http://mail.python.org/mailman/listinfo/python-list
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
'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
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
> 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
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
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
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 functionalit
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
Thanks a lot!
it did work!!
:)
--
http://mail.python.org/mailman/listinfo/python-list
by the way, iam using pygtk to develop the GUI
Regards.-
--
http://mail.python.org/mailman/listinfo/python-list
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 a
>>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
>
>
OK, I had put it on the global block.
Thanks,
Ernesto
--
http://mail.python.org
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:
import re
import glob
class LineMatcher:
""" Parses a list of text files, matching their lines with the given
regular expression
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 grea
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&
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 'TerminateProce
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
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 =
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 s
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 witho
I guess that was jerk-off version of:
"smtplib"
Thanks a lot.
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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-
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
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
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 syn
Thanks tons !
--
http://mail.python.org/mailman/listinfo/python-list
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
Thanks !
--
http://mail.python.org/mailman/listinfo/python-list
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
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 necess
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
A
Thanks to all.
--
http://mail.python.org/mailman/listinfo/python-list
Thanks !
--
http://mail.python.org/mailman/listinfo/python-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
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(
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.
--
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 an
wait a minute, that did work correctly. Thanks !
--
http://mail.python.org/mailman/listinfo/python-list
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
back
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
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
Nevermind this is not the design I need.
--
http://mail.python.org/mailman/listinfo/python-list
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
got it . thanks tons. i'm doing the tutorial now.
--
http://mail.python.org/mailman/listinfo/python-list
NEVERMIND ! Here is the solution...
#
if (os.path.isdir("C:\\MyNewFolder") == 0):
os.mkdir("C:\\MyNewFolder")
# -
thanks
--
http://mail.python.org/mailman/li
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 deter
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
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
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 g
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
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
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
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
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 = la
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
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
A nice person from another thread helped me...
a = 'disable "@USB\VID_0403&PID_6010&MI_00\7&15E4F68&1&'
print a
disable "@USB\VID_0403&PID_6010&MI_00&15E4F68&1&
\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,
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
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_05E3&PID_0605\5&2CE74B9E&1&6"
Using subprocess.Popen, I have something like this:
subprocess.Popen([r"devcon.exe","disable",'"USB
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.pyt
Thanks.
--
http://mail.python.org/mailman/listinfo/python-list
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
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_0403&PID_6010&MI_00\7&15E4F68&1&"$)
I want to send the string parameter:
enable "@USB\VID_0403&PID_6010&MI_00\7&15E4F68&1&"
to the program devcon.
The
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
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.
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(&q
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
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
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
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
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
Where is the ctypes mailing list?
--
http://mail.python.org/mailman/listinfo/python-list
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
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 includ
THANKS !!!
--
http://mail.python.org/mailman/listinfo/python-list
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/li
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/mai
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
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
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
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
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" me
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/pytho
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:
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
94 matches
Mail list logo