Laszlo Nagy wrote:
I would like to create a hierarchy classes, where the leaves have a
special attribute called producer_id. In addition, I would like to
have a function that can give me back the class assigned to any
producer_id value. I tried to implement this with a metaclass, but I
Without looking into the details -- the (subclass of) type is meant to be
the class of the class, or the other way round, your normal classes are
instances of (a subclass of) type. You determine the factory Python uses to
make a class by adding
__metaclass__ = factory
to the class body,
I am beginning to use python primarily to organize data into formats
needed for input into some statistical packages. I do not have much
programming experience outside of LaTeX and R, so some of this is a bit
new. I am attempting to write a program that reads in a text file that
contains some
Harold To illustrate, assume I have a text file, call it test.txt, with
Harold the following information:
Harold X11 .32
Harold X22 .45
Harold My goal in the python program is to manipulate this file such
Harold that a new file would be created that looks like:
Hello,
I'm new to python and I'm having difficulty understanding the following
code. Why doesn't the variable a contain [[{}, {'x': 0}, {}], [{},
{'x': 1}, {}]] instead. Doesn't {} allocate new memory for the
dictionary each time? It almost appears as if the 2nd dictionary
created overwrites the
erik gartz [EMAIL PROTECTED] writes:
Doesn't {} allocate new memory for the dictionary each time? It
almost appears as if the 2nd dictionary created overwrites the first
one.
URL:http://effbot.org/pyfaq/how-do-i-create-a-multidimensional-list.htm
--
\There are only two ways to
erik gartz wrote:
I'm new to python and I'm having difficulty understanding the following
code. Why doesn't the variable a contain [[{}, {'x': 0}, {}], [{},
{'x': 1}, {}]] instead. Doesn't {} allocate new memory for the
dictionary each time?
each time it's *executed*, yes. [{}]*3 doesn't
The problem:
I have two classes:
class X:
def __init__(self):
pass
class Y:
def __init__(self):
self.a=1
self.b=X()
and I would like to make 'a' visible inside 'x'. Is there a way to refer to
the Y class from the X? To make things easier :), each class is in a
different file,
Ángel Gutiérrez Rodríguez wrote:
The problem:
I have two classes:
class X:
def __init__(self):
pass
class Y:
def __init__(self):
self.a=1
self.b=X()
and I would like to make 'a' visible inside 'x'. Is there a way to refer
to the Y class from the X? To make
Dennis Lee Bieber wrote:
On Wed, 28 Jun 2006 10:35:10 +0200, Diez B. Roggisch
[EMAIL PROTECTED] declaimed the following in comp.lang.python:
class X:
def __init__(self, my_y):
self.my_y
self.my_y = my_y
*argl*
Thanks :)
No tea so far...
Diez
--
That wa sneat! Thanks!
--
Ángel Gutiérrez Rodríguez - [EMAIL PROTECTED]
Instituto de Ciencia de los Materiales de Madrid - CSIC
SpLine - European Syncrothorn Radiation Facility - Grenoble - France
Postal adress: Departamento de Química Física y Analítica
Universidad de Oviedo - c/Julián
I'm pretty stuck at the moment and wondering if anyone can spot the problem.
Trying to create a function that will read a text file into a list and
return that list.
I wrote the following function and saved it as 'fileloader.py'
def fileload(fname):
infile=open(fname)
dates =[]
Luke wrote:
I'm pretty stuck at the moment and wondering if anyone can spot the problem.
Trying to create a function that will read a text file into a list and
return that list.
I wrote the following function and saved it as 'fileloader.py'
def fileload(fname):
infile=open(fname)
Luke wrote:
I'm pretty stuck at the moment and wondering if anyone can spot the problem.
Trying to create a function that will read a text file into a list and
return that list.
I wrote the following function and saved it as 'fileloader.py'
def fileload(fname):
infile=open(fname)
Thanks to both of you for the help, much appreciated!
Luke
--
http://mail.python.org/mailman/listinfo/python-list
Hello. I'm having my way with exceptions in a little program I've done, and I'm wondering... What is a decent way of dealing with them? By a decent way I mean, what should I do when I see that an exception has occurred? I've seen that Python's default action is to print a stack trace. As far as I
I need to build-up an arg list to pass to a function.
Suppose I have a dictionary:
opts = { 'user' : 'jack', 'addr' : 'Green Str.'}
and I want to build a cmd line like this:
select( user='jack', addr='Green Str.' )
I'm clueless...
TIA
sandro
*:-)
--
Sandro Dentella *:-)
Sandro Dentella [EMAIL PROTECTED] wrote:
I need to build-up an arg list to pass to a function.
Suppose I have a dictionary:
opts = { 'user' : 'jack', 'addr' : 'Green Str.'}
and I want to build a cmd line like this:
select( user='jack', addr='Green Str.' )
select(**opts)
should
# Fibonacci series:
... # the sum of two elements defines the next
... a, b = 0, 1
while b 10:
... print b
... a, b = b, a+b
...
1
1
2
3
5
8
a, b = 0, 1
while b 10:
print b
a = b
b = a+b
1
2
4
8
Why a, b = b, a+b isn't a = b; b = a+b ?
Joon wrote:
# Fibonacci series:
... # the sum of two elements defines the next
... a, b = 0, 1
while b 10:
... print b
... a, b = b, a+b
...
1
1
2
3
5
8
a, b = 0, 1
while b 10:
print b
a = b
b = a+b
1
2
4
8
Why a, b = b,
Joon wrote:
a, b = 0, 1
while b 10:
print b
a = b
b = a+b
1
2
4
8
Why a, b = b, a+b isn't a = b; b = a+b ?
Because you changed a before you added it to b.
Let's call your existing a and b a0 and b0, and the next a and b
a1 and b1. When you do a, b = b, a+b
The case is that Python in attribution commands solves first the right
side, so he atributes the vars.
So the a+b expression is executed first.
Joon escreveu:
# Fibonacci series:
... # the sum of two elements defines the next
... a, b = 0, 1
while b 10:
... print b
... a, b
Yes, i see.
Thank you very much for the fast help!
--
http://mail.python.org/mailman/listinfo/python-list
Steve -
Good catch - in v1.3, I added some Unicode support for pyparsing,
although I have not gotten much feedback that anyone is using it, or
how well it works. So it is preferable to test against basestring
instead of str.
-- Paul
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
Hi,
Thanks for your reply! A new thing learned
Allow me to follow that up with another question:
Let's say I have a result from a module called pyparsing:
Results1 = ['abc', 'def']
Results2 = ['abc']
They are of the ParseResults type:
type(Results1)
Reinhold Birkenfeld [EMAIL PROTECTED] wrote in
message news:[EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
Hi,
Thanks for your reply! A new thing learned
Allow me to follow that up with another question:
Let's say I have a result from a module called pyparsing:
Results1 = ['abc', 'def']
David -
I'm not getting the same results. Run this test program:
---
import pyparsing as pp
import sys
def test(s):
results = pp.OneOrMore( pp.Word(pp.alphas) ).parseString( s )
print repr(s),-,list(results)
print Python version:, sys.version
print pyparsing version:,
John -
I just modified my test program BNF to use ZeroOrMore instead of
OneOrMore, and parsed an empty string. Calling list() on the returned
results gives an empty list. What version of pyparsing are you seeing
this None/object/list behavior?
-- Paul
--
On Mon, Jun 27, 2005 at 08:21:41AM -0600, John Roth wrote:
Unfortunately, I've seen that behavior a number of times:
no output is None, one output is the object, more than one
is a list of objects. That forces you to have checks for None
and list types all over the place.
maybe you can at
Modified version of test program, to handle empty strings - empty
lists.
import pyparsing as pp
import sys
def test(s):
results = pp.ZeroOrMore( pp.Word(pp.alphas) ).parseString( s )
print repr(s),-,list(results)
print Python version:, sys.version
print pyparsing version:,
Hi Paul and everyone else,
I ran the script and here's what I got:
Python version: 2.4.1 (#2, Mar 31 2005, 00:05:10)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)]
pyparsing version: 1.3
'abc def' - ['abc', 'def']
'abc' - ['abc']
It seems to work fine.
I figured out what my problem was:
[EMAIL PROTECTED] wrote:
if type(input) == str:
You might consider writing this as:
if isinstance(input, basestring):
I don't know if pyparsing ever produces unicode objects, but in case it
does (or it starts to in the future), isinstance is a better call here.
STeVe
--
Hello everyone,
I want to convert a tuple to a list, and I expected this behavior:
list(('abc','def')) - ['abc','def']
list(('abc')) - ['abc']
But Python gave me this behavior:
list(('abc','def')) - ['abc','def']
list(('abc')) - ['a','b','c']
How do I do get Python to work like the in former
('abc') is not a tuple - this is an unfortunate result of using ()'s as
expression grouping *and* as tuple delimiters. To make ('abc') a
tuple, you must add an extra comma, as ('abc',).
list( ('abc',) )
['abc']
-- Paul
--
http://mail.python.org/mailman/listinfo/python-list
Hi,
Thanks for your reply! A new thing learned
Allow me to follow that up with another question:
Let's say I have a result from a module called pyparsing:
Results1 = ['abc', 'def']
Results2 = ['abc']
They are of the ParseResults type:
type(Results1)
class 'pyparsing.ParseResults'
Robert Kern wrote:
Greg Ewing wrote:
[about the from xxx import * syntax]
Better still, don't even *mention* it to a beginner.
They don't need to know about it. At all. Really.
Well, the OP's use is precisely why from xxx import * exists: the
interactive prompt.
In that case (and, really,
Elliot Temple wrote:
from math import *
log10(15625)
It's always a good idea, especially when answering a beginner's
question, to add the caution that this form (from xxx import *) has
certain dangers** associated with it, and is widely considered poor
style, and should really only rarely be
import math
math.log10(15625)
To find out the names of function in the math module without checking the
docs, do
dir(math) #same for any other module
To get more info, do
help(math) # same for any other module with a doc string
Terry J. Reedy
--
Peter Hansen [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Elliot Temple wrote:
from math import *
log10(15625)
It's always a good idea, especially when answering a beginner's
question, to add the caution that this form (from xxx import *) has
certain dangers** associated with
Peter Hansen wrote:
It's always a good idea, especially when answering a beginner's
question, to add the caution that this form (from xxx import *) has
certain dangers** associated with it, and is widely considered poor
style, and should really only rarely be used.
Better still, don't
Greg Ewing wrote:
Peter Hansen wrote:
It's always a good idea, especially when answering a beginner's
question, to add the caution that this form (from xxx import *) has
certain dangers** associated with it, and is widely considered poor
style, and should really only rarely be used.
Hey everyone! I'm a math student working on a short script involving
logs. I have a function on my scientific calculator, and was wondering
if there was a similar funtion in python.
For example:
(log65536)/(log4)= 8
I've searched around a bit and haven't been able to find anything.
Thanks!
Svens wrote:
Hey everyone! I'm a math student working on a short script involving
logs. I have a function on my scientific calculator, and was wondering
if there was a similar funtion in python.
For example:
(log65536)/(log4)= 8
I've searched around a bit and haven't been able to find
Hey thanks...
Still getting an error message though. Here's what i'm doing:
--
import math
log10(15625)
--
-It says that log10 is not defined, but it is since the module is
imported, right?
--
http://mail.python.org/mailman/listinfo/python-list
Svens wrote:
Hey thanks...
Still getting an error message though. Here's what i'm doing:
--
import math
log10(15625)
--
-It says that log10 is not defined, but it is since the module is
imported, right?
No, read the tutorial.
import math
math.log10(15625)
--
Robert Kern
Svens wrote:
Hey thanks...
Still getting an error message though. Here's what i'm doing:
--
import math
log10(15625)
--
-It says that log10 is not defined, but it is since the module is
imported, right?
try this:
import math
math.log10(15625)
--
On Jun 1, 2005, at 9:04 PM, Svens wrote:
Hey thanks...
Still getting an error message though. Here's what i'm doing:
--
import math
log10(15625)
--
-It says that log10 is not defined, but it is since the module is
imported, right?
do either
import math
math.log10(15625)
Hello,
I
am facing a bit of a problem due to python implicitly attaching
a type to an object. I will briefly
tell you the problem that
I am facing. I am trying to print
the docstring of a test case in
my pyUnit base test class. I accept
the name of the test class as
a command
Uppal, Deepali wrote:
Hello,
Hello, and welcome to the world of Python. Don't take anything we say
too personally, it is meant to help.
I am facing a bit of a problem due to python implicitly
attaching a type to an object.
Ooh. In general, don't say 'implicit'. For the most part, Python
just read the ne stuuf. i went to DIP right after work anf found in
nice intro to unittest. not to bad (i thinK) now that I can see it work)
--
http://mail.python.org/mailman/listinfo/python-list
fred.dixon [EMAIL PROTECTED] writes:
:) unit test is something on my to-learn list. seems involved and i
haven't seen any straight forward tutorials yet. as yet i still
consider myself a hobbyist at best.
I would recommend Test Driven Development by Kent Beck
(Addison-Wesley).
Thomas
--
fred.dixon wrote:
:) unit test is something on my to-learn list. seems involved and i
haven't seen any straight forward tutorials yet. as yet i still
consider myself a hobbyist at best.
Hmm, I believe you are right. I can't see any straight-forward tutorials
which use Python. I found a
Duncan Booth wrote:
fred.dixon wrote:
:) unit test is something on my to-learn list. seems involved and i
haven't seen any straight forward tutorials yet. as yet i still
consider myself a hobbyist at best.
Hmm, I believe you are right. I can't see any straight-forward tutorials
which use Python.
Duncan Booth wrote:
Hmm, I believe you are right. I can't see any straight-forward
tutorials
which use Python. I found a tutorial at onlamp.com, but it doesn't
seem to
me to explain TDD at all clearly.
Mark Pilgrim's 'Dive Into Python' (http://diveintopython.org/) has a
couple of chapters on
when i am roughing out my functions and classes i out a pass statement
as my first line just as a place holder and a convenient place to put a
break when i am testing. no other good reason.
--
http://mail.python.org/mailman/listinfo/python-list
fred.dixon wrote:
when i am roughing out my functions and classes i out a pass statement
as my first line just as a place holder and a convenient place to put a
break when i am testing. no other good reason.
A better idea when roughing out functions and classes is to insert a
docstring
I want to use OPTIONS as a global var.
In this particular case I am trying to set a global debug constant so I
can have some debug logging happen when my program is run with a
-debug option.
what will actuall end up in OPTIONS is OPTIONS.debug = True as i am
using optparse module.
--
fred.dixon wrote:
I want to use OPTIONS as a global var.
In this particular case I am trying to set a global debug constant so I
can have some debug logging happen when my program is run with a
-debug option.
what will actuall end up in OPTIONS is OPTIONS.debug = True as i am
using optparse
how would i use the following if OPTIONS was in a module ?
---
from optparse import OptionParser
usage = usage: %prog [options] arg
parser = OptionParser(usage)
parser.add_option(-d, --debug, ction=store_true, dest=verbose)
(OPTIONS = parser.parse_args()
ps
Im not anywhere
fred.dixon wrote:
how would i use the following if OPTIONS was in a module ?
---
from optparse import OptionParser
usage = usage: %prog [options] arg
parser = OptionParser(usage)
parser.add_option(-d, --debug, ction=store_true, dest=verbose)
(OPTIONS = parser.parse_args()
Just
ok I'm sorry, I'm not sure what your doing there.
if i have to guess it looks like yo might me modifying the imported
modules dict with another dict.
isn't there a way i can just assign to a var and have it seen no matter
what part of the code is currently executing ?
--
it seems that i can import __main__ where i set the global and then
access the var from my local func.
is ther any gotcha's involveld in this ?
--
http://mail.python.org/mailman/listinfo/python-list
fred.dixon wrote:
ok I'm sorry, I'm not sure what your doing there.
if i have to guess it looks like yo might me modifying the imported
modules dict with another dict.
Yes, this takes all the atrributes of the options object and sets them
as attributes of the module. If you're afraid of
this is what i am using to test with.
my program is not much more involved just longer
and with a GUI.
I did test it and everything works, just wondered if there was
something evil and bad about importing main.
#
#global1.py
import global2
import
fred.dixon wrote:
#global1.py
import global2
import global3
import sys
constant = 'dumb'
option = sys.argv[1:]
pass
#global2.func1()
a=global2.class1()
a.func1()
print newvar
#global2.py
import __main__
pass
class class1:
def func1(self):
__main__.newvar = string
pass
The other
i have read the book and searched the group too
--
im not gettin it.
i want to read a global (OPTIONS) from file1 from a class method
(func1) in file2
i want to understand how this works.
--
#file1.py
import
fred.dixon wrote:
i have read the book and searched the group too
--
im not gettin it.
i want to read a global (OPTIONS) from file1 from a class method
(func1) in file2
i want to understand how this works.
--
Thanks for the tip. I knew it was something easy like that.
Brian van den Broek [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Todd_Calhoun said unto the world upon 2005-03-24 16:13:
I'm trying to generate a random number, and then concetate it to a word
to create a password.
I'm trying to generate a random number, and then concetate it to a word to
create a password.
I get the number and assign it to a variable:
+
word = dog
import random
rannum = random.randrange(100,999)
str(rannum)
word + rannum
+
But
str() returns a string, it doesn't change rannum which is still a number...
try -
rannum = str(rannum)
jw
On Thu, 24 Mar 2005 13:13:25 -0800, Todd_Calhoun [EMAIL PROTECTED] wrote:
I'm trying to generate a random number, and then concetate it to a word to
create a password.
I get the number
Todd_Calhoun said unto the world upon 2005-03-24 16:13:
I'm trying to generate a random number, and then concetate it to a word to
create a password.
I get the number and assign it to a variable:
+
word = dog
import random
rannum = random.randrange(100,999)
201 - 271 of 271 matches
Mail list logo