Re: Noob questions about Python

2007-10-19 Thread Grant Edwards
On 2007-10-19, Hendrik van Rooyen <[EMAIL PROTECTED]> wrote: > "Arnaud Delobelle" wrote: > >> In binary 2 is 10. When you multiply by 10, you shift all your digits >> left by 1 place. >> When you multiply by 10**n (which is 1 followed by n zeroes), you >> shift all your digits left by n places. >

Re: Noob questions about Python

2007-10-19 Thread Hendrik van Rooyen
"Arnaud Delobelle" wrote: > In binary 2 is 10. When you multiply by 10, you shift all your digits > left by 1 place. > When you multiply by 10**n (which is 1 followed by n zeroes), you > shift all your digits left by n places. I read somewhere: Only 1 person in 1000 understands binary. The oth

Re: Noob questions about Python

2007-10-19 Thread A.T.Hofkamp
On 2007-10-19, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > On Oct 19, 1:44 am, MRAB <[EMAIL PROTECTED]> wrote: >> On Oct 18, 7:05 am, Michele Simionato <[EMAIL PROTECTED]> >> >> if number == 0: >> return "0" >> > > Hey, > > Isn't > if not number: > return "0" > > faster? Depends o

Re: Noob questions about Python

2007-10-19 Thread cokofreedom
On Oct 19, 1:44 am, MRAB <[EMAIL PROTECTED]> wrote: > On Oct 18, 7:05 am, Michele Simionato <[EMAIL PROTECTED]> > wrote:> On Oct 17, 5:58 pm, Ixiaus <[EMAIL PROTECTED]> wrote: > > > > def bin2dec(val): > > > li = list(val) > > > li.reverse() > > > res = [int(li[x])*2**x for x in range(l

Re: Noob questions about Python

2007-10-18 Thread Michele Simionato
On Oct 18, 7:44 pm, MRAB <[EMAIL PROTECTED]> wrote: > It returns '' when number == 0, so you need to test for that case: > > > def baseN(number, N=2): > > """ > > >>> baseN(9, 2) > > '1001' > > """ > > assert 2 <= N <= 10 > > assert isinstance(number, int) and number >= 0 >

Re: Noob questions about Python

2007-10-18 Thread Ixiaus
That was a very helpful answer Steven, thank you for taking the time to write it! -- http://mail.python.org/mailman/listinfo/python-list

Re: Noob questions about Python

2007-10-18 Thread MRAB
On Oct 18, 7:05 am, Michele Simionato <[EMAIL PROTECTED]> wrote: > On Oct 17, 5:58 pm, Ixiaus <[EMAIL PROTECTED]> wrote: > > > def bin2dec(val): > > li = list(val) > > li.reverse() > > res = [int(li[x])*2**x for x in range(len(li))] > > print sum(res) > > > It basically does the sam

Re: Noob questions about Python

2007-10-18 Thread Steven D'Aprano
On Wed, 17 Oct 2007 23:06:24 -0700, Ixiaus wrote: > I know '<<' is shifting x over by n bits; but could you point me to some > literature that would explain why it is the same as "x*2**n"? (Googling > only returns bit shift, but doesn't necessarily explain the manner in > which you are using it)

Re: Noob questions about Python

2007-10-18 Thread Arnaud Delobelle
On Oct 18, 7:06 am, Ixiaus <[EMAIL PROTECTED]> wrote: [...] > I know '<<' is shifting x over by n bits; but could you point me to > some literature that would explain why it is the same as "x*2**n"? I haven't got literature but I've got a (hopefully straightforward) explanation: In binary 2 is 10

Re: Noob questions about Python

2007-10-18 Thread Bruno Desthuilliers
Stargaming a écrit : > On Wed, 17 Oct 2007 22:05:36 +0200, Bruno Desthuilliers wrote: > [snip] >> Note that there's also the reverse() function that returns a reverse >> iterator over any sequence, so you could also do: >> >> li = list('allo') >> print ''.join(reverse(li)) >> > > Note this certain

Re: Noob questions about Python

2007-10-18 Thread Stargaming
On Wed, 17 Oct 2007 22:05:36 +0200, Bruno Desthuilliers wrote: [snip] > > Note that there's also the reverse() function that returns a reverse > iterator over any sequence, so you could also do: > > li = list('allo') > print ''.join(reverse(li)) > Note this certainly should've been `reversed()`

Re: Noob questions about Python

2007-10-17 Thread Ixiaus
> Right idea: now to remove all those intermediate lists you construct. > 1. reversed(val) creates an iterator that runs over the elements (here > of a string) in reverse order. > 2. enumerate() is usually better than using an explicit list index. > 3. You can use a generator in your sum to avoid c

Re: Noob questions about Python

2007-10-17 Thread Michele Simionato
On Oct 17, 5:58 pm, Ixiaus <[EMAIL PROTECTED]> wrote: > def bin2dec(val): > li = list(val) > li.reverse() > res = [int(li[x])*2**x for x in range(len(li))] > print sum(res) > > It basically does the same thing int(string, 2) does. > > Thank you for the responses! BTW, here is the

Re: Noob questions about Python

2007-10-17 Thread George Sakkis
On Oct 17, 6:23 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > On Oct 17, 10:58 pm, Ixiaus <[EMAIL PROTECTED]> wrote: > > > > > Thank you for the quick responses. > > > I did not know that about integer literals beginning with a '0', so > > thank you for the explanation. I never really use PHP except

Re: Noob questions about Python

2007-10-17 Thread hg
Ixiaus wrote: > I have recently (today) just started learning/playing with Python. So > far I am excited and impressed (coming from PHP background). > > I have a few questions regarding Python behavior... > > val = 'string' > li = list(val) > print li.reverse() > > returns nothing, but, > > va

Re: Noob questions about Python

2007-10-17 Thread [EMAIL PROTECTED]
On Oct 17, 4:58 pm, Ixiaus <[EMAIL PROTECTED]> wrote: > Thank you for the quick responses. > > I did not know that about integer literals beginning with a '0', so > thank you for the explanation. I never really use PHP except for > handling basic forms and silly web stuff, this is why I picked up >

Re: Noob questions about Python

2007-10-17 Thread Paul Hankin
On Oct 17, 10:58 pm, Ixiaus <[EMAIL PROTECTED]> wrote: > Thank you for the quick responses. > > I did not know that about integer literals beginning with a '0', so > thank you for the explanation. I never really use PHP except for > handling basic forms and silly web stuff, this is why I picked up

Re: Noob questions about Python

2007-10-17 Thread Ixiaus
Thank you for the quick responses. I did not know that about integer literals beginning with a '0', so thank you for the explanation. I never really use PHP except for handling basic forms and silly web stuff, this is why I picked up Python because I want to teach myself a more powerful and broad

Re: Noob questions about Python

2007-10-17 Thread Bjoern Schliessmann
Ixiaus wrote: > val = 'string' > li = list(val) > print li.reverse() > > returns nothing, but, Yes -- li.reverse() returns None. "print None" prints nothing. > val = 'string' > li = list(val) > li.reverse() > print li > > returns what I want. I'm afraid not. li.reverse() still returns None,

Re: Noob questions about Python

2007-10-17 Thread Neil Cerutti
On 2007-10-17, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Ixiaus a écrit : >> val = 00110 >> >> as the integer 72 instead of returning 00110, why does Python >> do that? > > Literal integers starting with '0' (zero) are treated as octal. > It's a pretty common convention (like 0x for hexa).

Re: Noob questions about Python

2007-10-17 Thread Paul Hankin
On Oct 17, 8:37 pm, Ixiaus <[EMAIL PROTECTED]> wrote: > I have a few questions regarding Python behavior... > as the integer 72 instead of returning 00110, why does Python do that? > (and how can I get around it?) You can do this: def bin(x): return int(x, 2) val = bin('00110') -- Paul Hank

Re: Noob questions about Python

2007-10-17 Thread Bruno Desthuilliers
Ixiaus a écrit : > I have recently (today) just started learning/playing with Python. So > far I am excited and impressed Welcome onboard then !-) > (coming from PHP background). > > I have a few questions regarding Python behavior... > > val = 'string' > li = list(val) > print li.reverse() >

Re: Noob questions about Python

2007-10-17 Thread Adam Atlas
On Oct 17, 3:37 pm, Ixiaus <[EMAIL PROTECTED]> wrote: > I have recently (today) just started learning/playing with Python. So > far I am excited and impressed (coming from PHP background). > > I have a few questions regarding Python behavior... > > val = 'string' > li = list(val) > print li.reverse

Re: Noob questions about Python

2007-10-17 Thread Furkan Kuru
li.reverse() does not return a list it just changes the list li. val = 00110 is evaluated in base 8 try without leading 0s On 10/17/07, Ixiaus <[EMAIL PROTECTED]> wrote: > > I have recently (today) just started learning/playing with Python. So > far I am excited and impressed (coming from PHP b

Re: Noob questions about Python

2007-10-17 Thread Grant Edwards
On 2007-10-17, Ixiaus <[EMAIL PROTECTED]> wrote: > val = 'string' > li = list(val) > print li.reverse() > > returns nothing, but, > > val = 'string' > li = list(val) > li.reverse() > print li > > returns what I want. Why does Python do that? Because it does. :) > Also I have been playing around

Noob questions about Python

2007-10-17 Thread Ixiaus
I have recently (today) just started learning/playing with Python. So far I am excited and impressed (coming from PHP background). I have a few questions regarding Python behavior... val = 'string' li = list(val) print li.reverse() returns nothing, but, val = 'string' li = list(val) li.reverse(

Noob questions about Python

2007-10-17 Thread Ixiaus
I have recently (today) just started learning/playing with Python. So far I am excited and impressed (coming from PHP background). I have a few questions regarding Python behavior... val = 'string' li = list(val) print li.reverse() returns nothing, but, val = 'string' li = list(val) li.reverse(

Re: noob questions

2007-04-24 Thread Robert Kern
T.Crane wrote: > I'm new to python and I seem to get different behavior depending on... > well who knows what. Here's my question concerning importation of > packages/modules. > > I want to use scipy. So at the prompt (using iPython, installed with > Enthought edition on Windows XP) I type: > >

Re: noob questions

2007-04-24 Thread Steve Holden
T.Crane wrote: > I'm new to python and I seem to get different behavior depending on... > well who knows what. Here's my question concerning importation of > packages/modules. > > I want to use scipy. So at the prompt (using iPython, installed with > Enthought edition on Windows XP) I type: > >

noob questions

2007-04-24 Thread T.Crane
I'm new to python and I seem to get different behavior depending on... well who knows what. Here's my question concerning importation of packages/modules. I want to use scipy. So at the prompt (using iPython, installed with Enthought edition on Windows XP) I type: ln [1]: from scipy import * N

Re: More Noob Questions

2006-10-27 Thread Omar
Roberto Bonvallet wrote: > Omar wrote: > > more to come! > > Please, use a more meaningful subject next time, like "Integration of > Python and Flash" or "Where can I find vido tutorials". That way it will > be easier to people that knows about the subject to find your message and > answer you. >

Re: More Noob Questions

2006-10-27 Thread Omar
thank you all for your replies -- http://mail.python.org/mailman/listinfo/python-list

Re: More Noob Questions

2006-10-19 Thread Roberto Bonvallet
Omar wrote: > more to come! Please, use a more meaningful subject next time, like "Integration of Python and Flash" or "Where can I find vido tutorials". That way it will be easier to people that knows about the subject to find your message and answer you. And please think of us, non-native Engl

Re: More Noob Questions

2006-10-19 Thread Ravi Teja
> 1) I'm also learning to program flash movies while I learn to do > python. How can one implement flash movies into their python code? Depending on what "implementing flash movies into Python code" means. Python and Flash can be complementary. You can develop the UI in Flash and have it talk to

Re: More Noob Questions

2006-10-18 Thread Diez B. Roggisch
Omar schrieb: > 1) I'm also learning to program flash movies while I learn to do > python. How can one implement flash movies into their python code? You can't - flash uses action script, a variant of ECMA script. There is a PyPy-javascript-backend available, but I guess that's a little bit bey

More Noob Questions

2006-10-18 Thread Omar
Hi all...this is a good group so I'm sure you'll tolerate some more noobish questions... 1) I'm also learning to program flash movies while I learn to do python. How can one implement flash movies into their python code? 2) besides Chieh's tutorials on the python.org site, anyone know of any oth

Re: [noob] Questions about mathematical signs...

2005-02-10 Thread administrata
Steve Holden <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > administrata wrote: > > > Hi! I'm programming maths programs. > > And I got some questions about mathematical signs. > > > > 1. Inputing suqare like a * a, It's too long when I do time-consuming > >things. Can it

Re: [noob] Questions about mathematical signs...

2005-02-07 Thread Lou Pecora
In article <[EMAIL PROTECTED]>, Steve Holden <[EMAIL PROTECTED]> wrote: > > 2. Inputing fractions like (a / b) + (c / d), It's tiring work too. > >Can it be simplified? Can't this just be written as a/b+c/d ? How much simpler can it get? I would think you need at least one symbol per op

Re: [noob] Questions about mathematical signs...

2005-02-06 Thread Steve Holden
administrata wrote: Hi! I'm programming maths programs. And I got some questions about mathematical signs. 1. Inputing suqare like a * a, It's too long when I do time-consuming things. Can it be simplified? You mean you have to write a*a*a*a when you want the fourth power? You need the exponent

Re: [noob] Questions about mathematical signs...

2005-02-06 Thread Jeff Epler
On Sun, Feb 06, 2005 at 12:26:30PM -0800, administrata wrote: > Hi! I'm programming maths programs. > And I got some questions about mathematical signs. > > 1. Inputing suqare like a * a, It's too long when I do time-consuming >things. Can it be simplified? You can write powers with the "**"

[noob] Questions about mathematical signs...

2005-02-06 Thread administrata
Hi! I'm programming maths programs. And I got some questions about mathematical signs. 1. Inputing suqare like a * a, It's too long when I do time-consuming things. Can it be simplified? 2. Inputing fractions like (a / b) + (c / d), It's tiring work too. Can it be simplified? 3. How can i