(self):
self.yeast = None
def setYeast(self, yeast):
self.yeast = self.yeasts[yeast]()
w = World()
w.setYeast('good')
##
But I confess that I have not read or run your code, so I'm not sure
if this is the best way forward for you..
--
John
os.system('python %s %s %s' % (script2, input, output))
2. You can import your second script and call its main function
directly. How well this works will depend on the structure of the
second script.
--
John.
___
Tutor maillist - Tutor
On 11/09/2007, max baseman [EMAIL PROTECTED] wrote:
basically the problem is to find a bunch of ways to put 1,2,3,4,5
into different math problems to that equal 1-25, i haven't spent to
much time thinking about how to do this but i cant think of a way to
do it it without writing making the
I've just noticed that you can use the import statement to import variables,
such that a simple file such as vars.py:
# File with predefined variables
var1= 'some text'
var2= 2
var3=['a','b','c']
Would then, upon import, provide:
vars.var1
'some text'
vars.var2
2
vars.var3
['a','b','c']
This
Hello everyone,
Here's my solution for reading binary data (unformatted mixed types) and
packing it into a dictionary. It works, but somehow doesn't seem so
'pythonic'. Just seeking comments on how I might make it more efficient.
Thanks!
def readheader(filename):
import struct
Hello,
I have an unformatted mixed type binary file I'm trying to read into Python.
So far, I've gotten as far as:
f2=file(infile,'rb')
Dfmt=['3i','13s','7i','2f','2i','2f','2i','i'] #format for binary reading
first bits
if f2:
print infile + ' has been opened'
#for ft in Dfmt:
#
, attrs[key])
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
the pythonic
way to check is to catch the exception:
while True:
user_input = raw_input()
try:
num = int(user_input)
break
except TypeError:
print 'Oops, try again!'
HTH!
--
John.
___
Tutor maillist - Tutor@python.org
http
for an object:
select tag from tagTable where objectID = ?
Find objects matching a tag:
select objectID from tagTable where tag = ?
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
for n in xrange(1,101) if str(n) != str(n)[::-1] and n %
int(str(n)[::-1]) == 0 and n % 10 != 0]
[8712, 9801, 87912, 98901, 879912, 989901]
:-)
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
/Reversal.html
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
then need
to look into python libraries like urllib.
(actually, with some sites, you could get by without form submission.
Eg, for Wikipedia, you would just need to fetch the url
'http://en.wikipedia.org/wiki/Special:Search?search=%s' %
searchString)
--
John
Really? What are you having trouble with? I have used pyexcelerator
under Windows without problems.
--
John.
On 16/08/07, Kirk Bailey [EMAIL PROTECTED] wrote:
looks good. works bad; this is a windows workplace. ouch. Advice please
(other than change operating systems)?
John Fouhy wrote
)
Instead, do this:
decomma(*n)
1234567
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
, which means that
using '8' or '9' is a syntax error. Also, even if you don't get the
syntax error, the numbers will come out differently.
decomma(1,024)
120
It'll be fixed in Python 3000 :-)
--
John.
___
Tutor maillist - Tutor@python.org
http
/2007-April/053725.html
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
. I encourage you to go through the tutorial :-)
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
I'm not sure about PRAGMA, but you can do introspection in sqlite by
examining the table 'sqlite_master'.
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
On 03/08/07, Terry Carroll [EMAIL PROTECTED] wrote:
On Thu, 2 Aug 2007, John Fouhy wrote:
I'm not sure about PRAGMA, but you can do introspection in sqlite by
examining the table 'sqlite_master'.
Thanks. That's how I get the table names, actually. But it doesn't give
the column names
On 01/08/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
John, I spent the last two hours trying to understand what you wrote, and I
feel I'm missing something:
a_dict = {'one':1, 'two':2, 'three':3}
class A(object):
def __init__(self, **kwargs):
for var in kwargs
/typesseq.html
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
On 13/07/07, encore jane [EMAIL PROTECTED] wrote:
Does anyone know about a good native Excel file reader that is platform
independent?
I have had success with pyExcelerator:
http://sourceforge.net/projects/pyexcelerator
--
John.
___
Tutor maillist
the whole index file (which will be much
shorter than the main quote file), select one at random, then use
.seek() and .read() to read just the bytes you are interested in from
the main file.
--
John.
___
Tutor maillist - Tutor@python.org
http
On 7/11/07, Andre Roberge [EMAIL PROTECTED] wrote:
It is a standard convention. Lots of tools are built on the
assumption that translatable strings are going to be enclosed in
_(...)
These tools extract the strings from programs, and put them in files
(.po) that are easily editable by human
(TREE):
print value
### treetest.py #
HTH!
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
, ...)
Check the python docs (library reference, under Sequence types) for
more information.
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
I'm editing some code from Mailman and seeing:
legend = _(%(hostname)s Mailing Lists)
Can anyone tell me what the _( means in that context?
Thanks,
John
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
On 7/11/07, Dave Kuhlman [EMAIL PROTECTED] wrote:
On Wed, Jul 11, 2007 at 11:03:18AM -0400, John Morris wrote:
I'm editing some code from Mailman and seeing:
legend = _(%(hostname)s Mailing Lists)
The outer parentheses are a function call. The underscore
is a name that has a callable
This is how you put a newline or linebreak in a string: \n
-just adding that for someone's search later on, since 'newline' and
'linebreak' hadn't been mentioned yet ;)
(Should I be doing something else!?)
___
Tutor maillist - Tutor@python.org
all North. However, the West / East issue is another story.
Anyone have a more elegant solution?
-john
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Just a quick follow up.. it doesn't work :s
There are definitely some problems... ideas are welcome!
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Weiss [EMAIL PROTECTED] wrote:
John: One way to handle the situation of longitude is to make everything
west of the Greenwich meridan a negative value until -180 degrees and
everything east of Greenwich a positive value. HTH.
Albert
*John [EMAIL PROTECTED]*
Sent by: [EMAIL PROTECTED
A little closer, this seems to work, but it's not catching the 'W' or 'S'
cases to make it negative...
for i in range(0,20):
y=d[i][2].split('\xb0')
x=d[i][3].split('\xb0')
ydeg,ymin=int(y[0].rstrip()),float(y[1].strip('\' N'))
xdeg,xmin=int(x[0].rstrip()),float(x[1].rstrip(\'
I will work with this further, and report back once I find Alan's method...
but for now, this seems to work:
for i in range(0,20):
y=d[i][2].split('\xb0')
x=d[i][3].split('\xb0')
ydeg,ymin=int(y[0].rstrip()),float(y[1].strip('\' N'))
xdeg,xmin=int(x[0].rstrip()),float(x[1].rstrip(\' E).rstrip(\'
the variable 'line' to each line of the file in turn.
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
, not a file-like object. This also causes the
behaviour you get when iterating 'for line in file'...
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
On 06/07/07, Richard Querin [EMAIL PROTECTED] wrote:
I'm writing a very simple python script which writes out some
predefined text to a file (which will later become part of an html
file). I need to write out a pound sign '#' to the file and I can't
figure out how to escape it. I've tried '\#'
#
If you run the first script, it will create a pickle of the list
['one', 'two', 'three']. You'll be able to see the file in the
directory where you ran the script; you can even look at it if you
like. The second script will read the pickle and reconstruct the
list.
Hope this helps!
--
John
?
It's IPython -- http://ipython.scipy.org/moin/
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
into a sqlite in-memory
database, then use SQL to pull it back out.
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
On 26/06/07, Terry Carroll [EMAIL PROTECTED] wrote:
Is there any way of getting to the schema of an sqlite database from
within Python? In particular, a list of tables in the DB.
Try 'select * from sqlite_master'.
--
John.
___
Tutor maillist
don't know of a equivalent for Unix/Linux platforms, however.
HTH,
John
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
msec per loop
So, that's about a factor of 25 difference.
HTH!
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
.
capwords = [s.capitalize() for s in raw.split()] # this will give you
a list of capitalized words
capstr = ' '.join(capwords)# join them together, with spaces between
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman
module. I don't have the ability to test this
right now, but try something like:
import itertools
lst = [1,2,3,5]
t = ('r', 'g', 'b')
itertools.izip(lst, itertools.cycle(t))
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman
constants that are
quite useful. Only those string functions that exist as string
methods (and are on the deprecated list) will eventually die.
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
. My guess is I am
missing something about how cgi can work.
I bet Python has a simple way to receive a XML post so I do not have to look
for a specific form name?
Any help would be appreciated.
Thanks,
John
Web page code to post XML in a text area
form action=http:///cgi-bin
the module docstring, 'help(Foo.Foo)' would
give me the class docstring, and so on.
Check out the source code for python modules on your system (in the
lib directory of your install) for lots of examples.
--
John.
___
Tutor maillist - Tutor
as this code but I do not even get to that part...the mmap call is
bad. I have never used mmap before so this is new to me. I am running python
2.4
John
# code
from mmap import mmap
import os
from bisect import bisect_left
import sys
class Zipcodes(object):
Use mmap to treat
unfortunately. Sometimes pressing the button
registers in my logs and sometimes it does not. Pressing the button
twice in rapid succession may cause a hit to register if a single click
did not. Pressing the button 5 or 6 times will cause 4 or 5 hits. What
is it I am not understanding?
John
I have a Dictionary, that is made up of keys which are email
addresses, and values which are a list of firstname, lastnamet,
address, etc...
If I run the following:
#! /bin/python
import csv
last = {}
rdr = csv.DictReader(file(reg-data.csv))
for row in rdr:
#print row
On 22/05/07, John Washakie [EMAIL PROTECTED] wrote:
I have a Dictionary, that is made up of keys which are email
addresses, and values which are a list of firstname, lastnamet,
address, etc...
If I run the following:
last = {}
[...]
for k,v in last:
print Email: %s , has the Last
I have been playing with pywinauto http://pywinauto.pbwiki.com/ for a
few hours. Pywinauto allows you to use python to automate the GUI of
Windows using Python in very intuitive ways. What are the closest
analogs for this under OS X and Linux?
John
, despite being divisible by 4. But
y2k was a leap year, because it was a multiple of 400.
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
WAY too large a project I'm afraid. Yes, that would be the one which
would make me an 'expert' in Python ;)
Too bad there's just no time right now...
On 5/10/07, Bob Gailer [EMAIL PROTECTED] wrote:
John Washakie wrote:
I have access to the source code.
Did you tell us why you want to keep
special. Check out this
page; it may help you:
http://www.python.org/download/releases/2.2.3/descrintro/#__new__
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
of tuples. Each element is a triple (value,
text, time).
measurements = []
Then, later on, when you get a new measurement, something like:
measurements.append((value, text, time))
You can find the mean in the same way:
mean = sum(m[0] for m in measurements)/len(measurement)
--
John
the timeit module. Type
'import timeit' and then 'help(timeit)' from the python interpreter.
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
I have access to the source code. And I probably could pass the data
to stdout, so maybe .popen would work! I'll have a look... thanks!
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
I want to create a fully functional program that actually does something
USEFUL.
And just what would that be? Ask yourself that.. then perhaps folks on
the list could guide you in the right direction...
-j
___
Tutor maillist - Tutor@python.org
of this in the Cookbook and the Nutshell for
something more about error-checking strategies.
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
of actor
self.xp = 100
self.yp = 600
# create maze, etc.
def onClickVertical(self, newY, xp, yp):
# etc
HTH!
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
I have a FORTRAN program which reads in unformatted sparse matrix
data. Rather than rewriting the code in Python, I was hoping there is
a way to call the Fortran program, passing filename variables TO
Fortran, and returning the data (which is an array) back to my .py
code for use there.
Is there
/nycpython/
Hope to see you there!
-John
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
(dur/step)
# you may need to add a call to canvas1.update_idletasks() here
# untested
HTH!
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
I can't recall how to do this:
I want:
a = [int(x) for x in tmp]
but, my tmp has some empty elements, so it fails...
Therefore I want to be able to say:
a = [int(x) for x in tmp IF x in tmp]
I know there's a way! Ive seen it before, but now cannot find it! 'if'
is a pretty generic thing to
Thanks
Depending on what an 'empty' element is you may have to refine that.
I also noted, if I used:
tmp = data[6].strip().split()
rather than:
tmp = data[6].strip().split(' ')
I eliminated the 'empty' elements...
___
Tutor maillist -
Jessica,
Assuming you have python installed on your system (Windows?, *nix?),
then all you have to do is double click the .py file and it will run.
If you want, you can run it from the command line:
C:\ python yourfile.py
On 5/1/07, Jessica Brink [EMAIL PROTECTED] wrote:
I know this
Hello, I'm trying to calculate an average for columns in my
array(data), there's a catch though, I want to create a new array of
shorter length (NOTE: this crashes at line 8):
1) tinit = data[0][0]
2)for d in data:
3)if d[0] = tinit+60:
4)sum = sum+d
5)else:
6)
Thanks for the feedback,
The average was a little bit goofed up. Here's what I have now:
for d in data:
if d[0] = tinit+60:
d = column_stack(d)
cnt=cnt+1
sum = sum+d
else:
avg = sum/cnt
if init==0:
newData =
Ug,
It still doesn't make sense due to the sum/cnt where cnt is just an
int, and sum is a 1-dimensional array!
I'm missing something here about working with numpy arrays...
___
Tutor maillist - Tutor@python.org
It aint pretty! And if I had just walked away, it probably would've
taken half the time in the morning, but here's what I've come up with
(any suggestions for improvements, or course are welcome):
for d in data:
w = len(d)
if d[0] = tinit+60:
d = column_stack(d)
And of course, thanks all!
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
On 02/05/07, John Washakie [EMAIL PROTECTED] wrote:
It aint pretty! And if I had just walked away, it probably would've
taken half the time in the morning, but here's what I've come up with
(any suggestions for improvements, or course are welcome):
I'm still not sure exactly what you want
Hello all,
I'm trying to write a program which will take a path, look in it for
all files matching a certain pattern, then create javascript player to
play them. A key part of the code at this point is:
searchPath = imageRoot + '*' + imgExt
avail = glob.glob(searchPath) #will glob work over
directories on http servers are not readable, even if a readable
image is located in them... but that's another question for another
time.
Thanks,
john
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
be three lines:
cat raw.html |
sed 's/ImagePathReplaceMe/NewPathToImage/g' |
sed 's/TitleReplaceMe/NewTitle/g' new.html
However, this is going to be part of an Plone product so I want to use
Python. What is the best method to accomplish this?
Thanks,
john
, John Washakie [EMAIL PROTECTED] wrote:
cat raw.html |
sed 's/ImagePathReplaceMe/NewPathToImage/g' |
sed 's/TitleReplaceMe/NewTitle/g' new.html
One line's sufficient:
sed -e 's/ImagePathReplaceMe/NewPathToImage/g;s/TitleReplaceMe/NewTitle/g'
raw.html new.html
However, this is going
Excellent. Thanks Luke, that seems to be working
On 4/25/07, Luke Paireepinart [EMAIL PROTECTED] wrote:
John Washakie wrote:
Tested. Failed...
I thought it would be something like that, but that doesn't work..
perhaps because 'ImagePathReplaceMe' isn't separate from the rest
) for x in zip(*orig)]
[30, 20, 50]
HTH! :-)
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Michael Lange [EMAIL PROTECTED] wrote:
Usually there is no need to pass extra arguments to configure.
My guess is that you missed to install Tcl / Tk and/or the Tcl/Tk development
packages before compiling python.
That was it: I had both Tcl and Tk installed, but not the development
packages
, and
it is there (dated the last time I recompiled Python 2.5).
What else can I try?
Thank you,
~John
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Python interpreter to use, I believe,
so you could direct it at one of your other installs for now until you
get 2.5 working
I think it's more of a system/configuration problem than one
specifically with 2.5. The other Python versions give the same exact
error.
Thanks,
~John
that there is a text book
out there called Database Access Patterns, can anyone provide a
recommendation or a critique of the book? Are there other (better)
references I should be consulting in designing the database interaction
layer of my application?
Thanks,
-John Clark
Kent and Alan: better?
.j
import zipfile
import os
import pylab as P
iFile = raw_input(Which file to process?)
def openarchive(filename):
open the cmet archive and read contents of file into memory
z = zipfile.ZipFile(filename, r)
for filename in z.namelist():
print filename
to give to building security to make sure you can gain access to
the building. RSVP to [EMAIL PROTECTED] to add your name to the list.
More information can be found on the yahoo group page:
http://tech.groups.yahoo.com/group/nycpython
Hope to see you there!
-John
_
From: [EMAIL
:-)
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Bob Gailer wrote:
Andreas Pfrengle wrote:
Hello,
I want to change the value of a variable whose name I don't know, but
this name is stored as a string in another variable, like:
x = 1
var = 'x'
Now I want to change the value of x, but address it via var.
exec is the statement for doing
Be aware that by default the Apache web server _WILL_ use the shebang line
even when running on Windows to try to find the Python interpreter when
python is run as a CGI script.
There is a setting in the configuration file that controls whether to use
the shebang line or to reference the
/nycpython/
Hope to see you there!
-John
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
).
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
where the NameError occurs)
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
option, using the in operator:
for f in fruit:
if f not in [apples, pairs]:
print f, is not an apple or pair.
HTH!
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
python modules in C and
incorporate them into your python programs.
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
.
To continue your example, you can do this:
f = open('test.conf', 'w')
conf.write(f)
f.close()
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
the same.
[note that this code will not produce strings like 'IV' for 4. OTOH,
as I recall, the Romans didn't do that consistently either..]
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
for this one too.
Ahh, good point. I was thinking in terms of extra logic to figure out
the subtraction rules, but you could just use extra symbols :-)
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
this; look about half-way down the page:
http://docs.python.org/tut/node5.html
HTH!
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
= [1,2,3,4]
555 == 555 in lst
False
(555 == 555) in lst
True
1 == 1 in lst
True
(this works because 1 == True)
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
from foo order by whatever limit 5'.
--
John.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
401 - 500 of 958 matches
Mail list logo