Re: [Tutor] module to parse XMLish text?

2011-01-14 Thread Stefan Behnel
Wayne Werner, 15.01.2011 03:25: On Fri, Jan 14, 2011 at 4:42 PM, Terry Carroll wrote: On Fri, 14 Jan 2011, Karim wrote: from xml.etree.ElementTree import ElementTree I don't think straight XML parsing will work on this, as it's not valid XML; it just looks XML-like enough to cause confusion.

Re: [Tutor] When I print random.random

2011-01-14 Thread bob gailer
Please always reply to the list, not just to me. On 1/14/2011 10:42 PM, walter weston wrote: I want a whole number thats 5 digits long, I want to use it as a password and if I just type random.random() I get a long float. random.randint(a, b) Return a random integer N such that a <= N <= b.

Re: [Tutor] When I print random.random

2011-01-14 Thread Steven D'Aprano
walter weston wrote: when I print random.random() it always returns a float why is this? how do I change it to a whole number? Because random.random() is defined to always return a float between 0 and 1. That's what it does. If you want a random whole number, you can call random.randint or

Re: [Tutor] When I print random.random

2011-01-14 Thread Wayne Werner
On Fri, Jan 14, 2011 at 9:25 PM, bob gailer wrote: > On 1/14/2011 10:02 PM, walter weston wrote: > > when I print random.random() it always returns a float why is this? how do > I change it to a whole number? > > > That depends on what behavior you want. > > If you RTFM you will see: > random.r

Re: [Tutor] how come this doesnt work

2011-01-14 Thread Dave Angel
On 01/-10/-28163 02:59 PM, walter weston wrote: I generate a random number(supposedly a password, in my case its just a long floating point lol),I want the user to reinput that number and I want to print a string if the number entered is correct. so if m==num(num is the number generated and m

Re: [Tutor] When I print random.random

2011-01-14 Thread bob gailer
On 1/14/2011 10:02 PM, walter weston wrote: when I print random.random() it always returns a float why is this? how do I change it to a whole number? That depends on what behavior you want. If you RTFM you will see: random.random() Return the next random floating point number in the range

Re: [Tutor] how come this doesnt work

2011-01-14 Thread Noah Hall
Adding reply to list - On Sat, Jan 15, 2011 at 2:55 AM, walter weston wrote: > I only want to generate a random number once > Then you don't need a for loop. Think of a for loop as something you need when you want to run a piece of code several times, for example for x in range(1,6): print('

Re: [Tutor] how come this doesnt work

2011-01-14 Thread Noah Hall
> import random > for x in range(0,1): >     num = random.random() >     print (num) >     m=input('input pass:') >     if m==num: >     print('you entered correctly, proceed') Your problem lines in the differences in between the types - your num variable is a float, whereas your m variable i

Re: [Tutor] how come this doesnt work

2011-01-14 Thread Alex Hall
On 1/14/11, walter weston wrote: > > I generate a random number(supposedly a password, in my case its just a long > floating point lol),I want the user to reinput that number and I want to > print a string if the number entered is correct. so if m==num(num is the > number generated and m is the va

Re: [Tutor] module to parse XMLish text?

2011-01-14 Thread Wayne Werner
On Fri, Jan 14, 2011 at 4:42 PM, Terry Carroll wrote: > > > On Fri, 14 Jan 2011, Karim wrote: > > from xml.etree.ElementTree import ElementTree >> > > I don't think straight XML parsing will work on this, as it's not valid > XML; it just looks XML-like enough to cause confusion. > > It's worth

[Tutor] how come this doesnt work

2011-01-14 Thread walter weston
I generate a random number(supposedly a password, in my case its just a long floating point lol),I want the user to reinput that number and I want to print a string if the number entered is correct. so if m==num(num is the number generated and m is the variable which stores the input ) then I w

Re: [Tutor] Python on Ubuntu 10.10?

2011-01-14 Thread Corey Richardson
On 01/14/2011 08:17 PM, Joel Knoll wrote: > Hello, > > I am new to programming and to Python. I've been using Python with IDLE > on Windows Vista for a few weeks now. > (And I'm loving it!) However, I'm thinking about switching to Ubuntu > 10.10. If I download Ubuntu, will I still be able to u

Re: [Tutor] color of "print" function

2011-01-14 Thread Bill DeBroglie
On Jan 14, 2011, at 8:03 PM, bob gailer wrote: On 1/14/2011 7:48 PM, Bill DeBroglie wrote: Hello all, I don't have a problem per se, but have noticed something that I'd like to figure out... Sometimes the "print" function appears orange for me, sometimes it appears purple. Why does this

[Tutor] Python on Ubuntu 10.10?

2011-01-14 Thread Joel Knoll
Hello, I am new to programming and to Python. I've been using Python with IDLE on Windows Vista for a few weeks now. (And I'm loving it!) However, I'm thinking about switching to Ubuntu 10.10. If I download Ubuntu, will I still be able to use the IDLE environment? I am really quite fond

Re: [Tutor] how to print random number multiply

2011-01-14 Thread Alan Gauld
"walter weston" wrote I have mostly studied python and now I'm ready to start writing code. Its usually best to study programming languages *by* writing code. However since you have now reached that stage of readiness that's irrelevant advice :-) I want to print random numbers a certain am

Re: [Tutor] how to print random number multiply

2011-01-14 Thread David Hutto
On Fri, Jan 14, 2011 at 8:01 PM, David Hutto wrote: > Sorry , the tab button doesn't work for text in google mail, and it > jumped to send > >>> > >   import random >> for x in range(1,10): num = random.random() >       print (num) this should 'bind' your variable to a knew random each t

Re: [Tutor] color of "print" function

2011-01-14 Thread Alan Gauld
"Bill DeBroglie" wrote Sometimes the "print" function appears orange for me, sometimes it appears purple. Why does this happen and what's the difference anyway? THere is probably no difference but one of several things could be causing it. First though, the colouring is done by your edit

Re: [Tutor] how to print random number multiply

2011-01-14 Thread bob gailer
On 1/14/2011 7:46 PM, walter weston wrote: I have mostly studied python and now I'm ready to start writing code. I want to print random numbers a certain ammount of times I am using the code import random print (random.random()) I tried bind the print statement to a variable and when I call

Re: [Tutor] color of "print" function

2011-01-14 Thread bob gailer
On 1/14/2011 7:48 PM, Bill DeBroglie wrote: Hello all, I don't have a problem per se, but have noticed something that I'd like to figure out... Sometimes the "print" function appears orange for me, sometimes it appears purple. Why does this happen and what's the difference anyway? This seem

Re: [Tutor] how to print random number multiply

2011-01-14 Thread David Hutto
Sorry , the tab button doesn't work for text in google mail, and it jumped to send >>  import random > for x in range(1,10): print (random.random()) This assigns a new random each time, where as outside the for loop it assigns it once. ___ Tut

Re: [Tutor] color of "print" function

2011-01-14 Thread Steven D'Aprano
Bill DeBroglie wrote: Hello all, I don't have a problem per se, but have noticed something that I'd like to figure out... Sometimes the "print" function appears orange for me, sometimes it appears purple. Why does this happen and what's the difference anyway? Can you explain the context?

Re: [Tutor] color of "print" function

2011-01-14 Thread Corey Richardson
On 01/14/2011 07:48 PM, Bill DeBroglie wrote: > Hello all, > > I don't have a problem per se, but have noticed something that I'd > like to figure out... > > Sometimes the "print" function appears orange for me, sometimes it > appears purple. Why does this happen and what's the difference any

Re: [Tutor] how to print random number multiply

2011-01-14 Thread Steven D'Aprano
walter weston wrote: I have mostly studied python and now I'm ready to start writing code. I want to print random numbers a certain ammount of times I am using the code import random print (random.random()) I tried bind the print statement to a variable and when I call x for example I

Re: [Tutor] how to print random number multiply

2011-01-14 Thread David Hutto
>  import random for x in range(1,10) > print (random.random()) -- Sometimes...my mama...says I get over excited about technology. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/li

Re: [Tutor] how to print random number multiply

2011-01-14 Thread Corey Richardson
On 01/14/2011 07:46 PM, walter weston wrote: > I have mostly studied python and now I'm ready to start writing code. I > want to print random numbers a certain ammount of times I am using the > code > > import random > print (random.random()) > > I tried bind the print statement to a varia

[Tutor] color of "print" function

2011-01-14 Thread Bill DeBroglie
Hello all, I don't have a problem per se, but have noticed something that I'd like to figure out... Sometimes the "print" function appears orange for me, sometimes it appears purple. Why does this happen and what's the difference anyway? This seems to be the only function that varies like

[Tutor] how to print random number multiply

2011-01-14 Thread walter weston
I have mostly studied python and now I'm ready to start writing code. I want to print random numbers a certain ammount of times I am using the code import random print (random.random()) I tried bind the print statement to a variable and when I call x for example I want it to print new

Re: [Tutor] module to parse XMLish text?

2011-01-14 Thread Terry Carroll
On Fri, 14 Jan 2011, Stefan Behnel wrote: Terry Carroll, 14.01.2011 03:55: Does anyone know of a module that can parse out text with XML-like tags as in the example below? I emphasize the "-like" in "XML-like". I don't think I can parse this as XML (can I?). Sample text between the dashed line

Re: [Tutor] Object/Class Beginner Questions

2011-01-14 Thread Ben Ganzfried
* I meant that*: A method actually can be called from the command prompt, but the syntax is quite different than that used to call a function from the command prompt. On Fri, Jan 14, 2011 at 2:37 PM, Ben Ganzfried wrote: > I actually just figured it out (since the tutorial talks about the > diffe

Re: [Tutor] Object/Class Beginner Questions

2011-01-14 Thread Ben Ganzfried
I actually just figured it out (since the tutorial talks about the difference in indentation between a method and a function in a later chapter). Basically, a method is within a class and therefore cannot be called from the command prompt whereas a function that stands by itself in a script can be

Re: [Tutor] Object/Class Beginner Questions

2011-01-14 Thread Steven D'Aprano
Ben Ganzfried wrote: Hey guys, I'm using a tutorial geared for a 2.x version of Python and I am currently using Python 3.1-- so it is possible that my confusion has to do with different notations between them. But in any case, here is what I have: My questions are the following: 1) Why is th

Re: [Tutor] Object/Class Beginner Questions

2011-01-14 Thread Alex Hall
On 1/14/11, Ben Ganzfried wrote: > Hey guys, > > I'm using a tutorial geared for a 2.x version of Python and I am currently > using Python 3.1-- so it is possible that my confusion has to do with > different notations between them. But in any case, here is what I have: > type(Time) > t

[Tutor] Object/Class Beginner Questions

2011-01-14 Thread Ben Ganzfried
Hey guys, I'm using a tutorial geared for a 2.x version of Python and I am currently using Python 3.1-- so it is possible that my confusion has to do with different notations between them. But in any case, here is what I have: >>> type(Time) >>> t1 = Time() >>> type(t1) where: class Time:

Re: [Tutor] Refcount in C extensions

2011-01-14 Thread Stefan Behnel
Izz ad-Din Ruhulessin, 14.01.2011 19:49: Thanks for your quick reply and clearing the issue up for me. Using your answer, I rewrote the function to this: double Py_GetAttr_DoubleFromFloat(PyObject *obj, const char *attr) { PyObject *get_attr, *py_float; int has_attr; //Check if the given

Re: [Tutor] Refcount in C extensions

2011-01-14 Thread Izz ad-Din Ruhulessin
Hi Stefan, Thanks for your quick reply and clearing the issue up for me. Using your answer, I rewrote the function to this: double Py_GetAttr_DoubleFromFloat(PyObject *obj, const char *attr) > > { > > PyObject *get_attr, *py_float; > > int has_attr; > > >> //Check if the given object has the give

Re: [Tutor] no luck with sqlinsert

2011-01-14 Thread Steve Willoughby
On 14-Jan-11 09:03, Jason Staudenmayer wrote: Don't build you sql separate from the execute (or so I was told when I was doing something similar) cur.execute(INSERT INTO tkindbtal (kommune, komnr, i2005, i2006, i2007 \ , i2008, i2009, i2010) VALUES (%s, %s, %s, %s, %s, %s,\ %s, %s)% (cols[0], col

Re: [Tutor] Refcount in C extensions

2011-01-14 Thread Stefan Behnel
Izz ad-Din Ruhulessin, 14.01.2011 17:52: I am writing a Python C extension and I have some trouble understanding how reference counting works exactly. Though I think I understand the practice on simple operations (see my question at stackoverflow: http://stackoverflow.com/questions/4657764/py-inc

Re: [Tutor] no luck with sqlinsert

2011-01-14 Thread Alan Gauld
"Tommy Kaas" wrote I get a invalid syntax error when I try to run this script - and it's con.commit() which is highlighted when I get the error. Aren't you one closing parenthesis short? cur.execute(sqlinsert, (cols[0],

Re: [Tutor] no luck with sqlinsert

2011-01-14 Thread Jason Staudenmayer
Don't build you sql separate from the execute (or so I was told when I was doing something similar) cur.execute(INSERT INTO tkindbtal (kommune, komnr, i2005, i2006, i2007 \ , i2008, i2009, i2010) VALUES (%s, %s,%s, %s, %s, %s,\ %s, %s) % (cols[0], cols[1], int(cols[2

[Tutor] Refcount in C extensions

2011-01-14 Thread Izz ad-Din Ruhulessin
Hello, I am writing a Python C extension and I have some trouble understanding how reference counting works exactly. Though I think I understand the practice on simple operations (see my question at stackoverflow: http://stackoverflow.com/questions/4657764/py-incref-decref-when), but on more "comp

[Tutor] no luck with sqlinsert

2011-01-14 Thread Tommy Kaas
I get a invalid syntax error when I try to run this script - and it's con.commit() which is highlighted when I get the error. I can't see what is wrong. I think it looks like other scripts I'm running without problems. The scraping part works fine. And the table exists in the mysql db. I have just

Re: [Tutor] turn a path into nested list

2011-01-14 Thread ingo
On Fri, Jan 14, 2011 at 1:21 AM, Alan Gauld wrote: for t in os.walk('Root'): > > ...    print t > ... > And the result is:('Root', ['D1', 'D2', 'D3'], ['FA.txt', 'FB.txt']) > ('Root/D1', ['D1-1'], ['FC.txt']) As I only need the first result presented I didn't favor os.walk, yet tried it any

Re: [Tutor] module to parse XMLish text?

2011-01-14 Thread Stefan Behnel
Terry Carroll, 14.01.2011 03:55: Does anyone know of a module that can parse out text with XML-like tags as in the example below? I emphasize the "-like" in "XML-like". I don't think I can parse this as XML (can I?). Sample text between the dashed lines:: - Blah,

Re: [Tutor] module to parse XMLish text?

2011-01-14 Thread Karim
Hello, *from xml.etree.ElementTree import ElementTree _/#Parsing:/_ doc = ElementTree() doc.parse(xmlFile) * /_*#Find tag element:*_/ *doc.find('mytag')* *_/#iteration over tag element:/_ lname = [] for lib in doc.iter('LibTag'): libName = lib.attrib['name'] lname.append(libName) * R

Re: [Tutor] errors in "Python Programming for the Absolute Beginner"??

2011-01-14 Thread Bill Allen
I will agree that it seems odd, but here is a sample run from my system. I promise I am not pulling anyone's leg! :-)) wallenpb@Ubuntu-D810:~$ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>