[Tutor] compare

2005-10-31 Thread Shi Mu
What does this line 11 mean in the following code?

1 # calc.py
2 def calc(seq):
3   maximum = 0
4   max_item = []
5   for i in seq:
6 product = (i[0]*100 + i[1]*10 + i[2]) * (i[3]*10 + i[4])
7 if product > maximum:
8maximum = product
9max_item = i
   10 elif product == maximum:
   11max_item += ','+i
   12   return max_item, maximum
   13
   14 seq = [ [5,6,7,8,9], [5,6,7,9,8] ]
   15 max_item, maximum = calc(seq)
   16 print "Maximum at", max_item, ",product", maximum
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie Question - Python vs Perl

2005-10-31 Thread Alan Gauld
> friend told me I should learn Perl over Python as it's more
> prevalent.  I'm going to be using it on a Mac.

In that case you should switch to a PC because they are more prevalent.
Also you should learn to program in COBOL since its the most prevalent
of all computer languages.

And yet most folks in the industry prefer Macs to PCs when they have
a choice and most unbiased observers think COBOL sucks!
Python is a lot easier to learn and work with than Perl...
go figure. :-)


-- 
Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie Question - Python vs Perl

2005-10-31 Thread Jan Eden
Hi Scott,

Scott Clausen wrote on 30.10.2005:

>As a newbie to Python I'd like to know if someone can tell me some
>strengths and weaknesses of this language. The reason I'm asking is
>a friend told me I should learn Perl over Python as it's more
>prevalent.  I'm going to be using it on a Mac.
>
>I'd appreciate hearing any views on this topic. My own view is that
>it's always good to learn new things as you then have more tools to
>use in your daily programming.

I started learning Python approx. 4 months ago. I had been using Perl for about 
4 years at that time. (BTW, I work on a Mac, too)

The motivation for trying Python came when a certain project needed an OOP 
overhaul. While I was able to code an OOP version of the program, the result 
was rather slow and ugly. This was only partly because of my own deficiencies - 
Perl does not really invite you to produce clean code on larger projects (IMHO).

When I re-coded the very same project in Python, I achieved a much better 
(faster, more readable) result within weeks.

Most comparisons of Perl and Python also highlight Python's cleaner syntax, I 
can second that (although I got used to Perl's @$% syntax after a while).

Cheers,

Jan
-- 
Common sense is what tells you that the world is flat.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie Question - Python vs Perl

2005-10-31 Thread Liam Clarke
On 10/31/05, Scott Clausen <[EMAIL PROTECTED]> wrote:
> As a newbie to Python I'd like to know if someone can tell me some
> strengths and weaknesses of this language. The reason I'm asking is a
> friend told me I should learn Perl over Python as it's more
> prevalent.  I'm going to be using it on a Mac.
>
> I'd appreciate hearing any views on this topic. My own view is that
> it's always good to learn new things as you then have more tools to
> use in your daily programming.
>
> Thanks in advance.
>

Hi Scott,

I would say, it really depends on where you're coming from and where
you're going, coding wise. If your background is primarily Linux
scripting with sh, awk, grep, sed, (sed?) etc, then Perl will be a
nice and natural fit.

If you're starting from a clean slate, then I would recommend Python,
speaking as a relative beginner who had to make that choice myself not
too long ago.

Python has a nice clean syntax, which means that your errors are
usually errors of logic and not errors of using an @ instead of a $,
or missing a }, etc.

Perl has an incredibly huge library, and for a beginner, that's
challenging. Python's standard  library encompasses about 98% of
everything I need to do, and in a year of coding in Python, I'm still
not familiar with all of it, but I have a fair idea of where to find
particular functionality. I tried Perl and got incredibly confused by
CPAN.

Python is OO from the get go. Want to subclass integers? Sure, go right ahead.
Whereas, Perl tends to show it's roots in aforementioned shell
scripts, and the OO side feels awkward.

Also, I'll just mention a pet peeve of mine regarding Perl. It
flattens lists using the simple syntax. To nest a list requires
special syntax that most tutorials don't mention...

The classic reasons to prefer one over the other are a) scalability,
and b) maintainability.
Python scales well, and is quite straightforward to maintain, although
I live by the mantra that one can write Perl in any language.

The catch-cry of Perl is "there's more than one way to do it." As a
learner, you'll spend a lot of time asking "But which is the best
way?" In Python, there's generally a straight-forward and obvious way,
and it's usually the best and simplest.

i.e. you can stick the items of a one list in another two ways, a for
loop, and a list method.
x=[1,2,3]
y = [4,5,6]
#either
for item in y:
x.append(item)

#or
x.extend(y)

The extend() method is simpler, and faster.

With regards to where you're going in the future, I don't know what
the future holds for Perl, but watching the .NET framework arise, I
think that Microsoft has the LAMP combination in it's sights. There's
already a Python implementation for the .NET framework, it's called
IronPython, (it's in alpha at the mo).

To be honest, if you still wanted to go with Perl, I'd recommend you
learn Ruby instead.
It originated in Perl, but it's just flat out better. It's the
language that experienced Perl users migrate to, as it has minimal
culture shock. And, Ruby on Rails is a great framework.

Ruby's standard library is quite minimal on the docs at the moment,
and the 3rd party modules aren't there, yet, whereas Python has a
mature community.

Good luck,

Liam Clarke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] compare

2005-10-31 Thread Johan Geldenhuys
In your code that line is not executed. And if it was at some stage, it 
will give you an error.
max_item is a list and you cannot put a string and a list together:  
"TypeError: cannot concatenate 'str' and 'list' objects".

What are trying to do with this line? 'maximum = 0' and so product will 
be greater than maximum. It looks you are trying to append a list to seq 
that is already there?
Maybe it's a bad guess from me, I'm no expert.

Johan

Shi Mu wrote:

>What does this line 11 mean in the following code?
>
>1 # calc.py
>2 def calc(seq):
>3   maximum = 0
>4   max_item = []
>5   for i in seq:
>6 product = (i[0]*100 + i[1]*10 + i[2]) * (i[3]*10 + i[4])
>7 if product > maximum:
>8maximum = product
>9max_item = i
>   10 elif product == maximum:
>   11max_item += ','+i
>   12   return max_item, maximum
>   13
>   14 seq = [ [5,6,7,8,9], [5,6,7,9,8] ]
>   15 max_item, maximum = calc(seq)
>   16 print "Maximum at", max_item, ",product", maximum
>___
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>  
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with prime number program

2005-10-31 Thread Norman Silverstone

> I am trying to write a program that will figure out if a number is prime
> or not. Currently this is the code that I have:
> 
> import math
> 
> def main():
> 
> number=input("Please enter a positive whole number greater than 2: ")
> for value in range(2, number-math.sqrt):
> if number % value == 0:
> print number, "is not prime"
> exit
> print number, "is prime"
> 
> main()

I am a beginner so, I hope what I give, makes sense. In it's simplest
form what is wrong with :-

n = input("Enter a number")
if n % 2 != 0 and n % 3 != 0:
   print n, " Is a prime number"

Comments please.

Norman

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with prime number program

2005-10-31 Thread Kent Johnson
Norman Silverstone wrote:
> I am a beginner so, I hope what I give, makes sense. In it's simplest
> form what is wrong with :-
> 
> n = input("Enter a number")
> if n % 2 != 0 and n % 3 != 0:
>print n, " Is a prime number"
> 
This only gives the correct answer if n < 25. You can't test against a fixed 
list of divisors, there will always be a non-prime whose divisors are not in 
your list.

Kent

-- 
http://www.kentsjohnson.com

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] compare

2005-10-31 Thread Liam Clarke
> >
> >1 # calc.py
> >2 def calc(seq):
> >3   maximum = 0
> >4   max_item = []
> >5   for i in seq:
> >6 product = (i[0]*100 + i[1]*10 + i[2]) * (i[3]*10 + i[4])
> >7 if product > maximum:
> >8maximum = product
> >9max_item = i
> >   10 elif product == maximum:
> >   11max_item += ','+i
> >   12   return max_item, maximum
> >   13
> >   14 seq = [ [5,6,7,8,9], [5,6,7,9,8] ]
> >   15 max_item, maximum = calc(seq)
> >   16 print "Maximum at", max_item, ",product", maximum

Well, it runs and returns [5, 6, 7, 9, 8], 55566.

Is that what you were expecting? If you can tell us what output you
expected and how it deviated, it's always good, details are A Good
Thing. ;-)

Try feeding it seq = [ [5,6,7,8,9], [5,6,7,8,9] ] and  you'll get the
error Johan described, as product will equal maximum. Are you wanting
the output

Maximum at [ [5,6,7,8,9], [5,6,7,8,9] ] ,product 50463? As it looks
like you're trying to join two lists.

I think you've been bitten by some operator overloading wherein
>>> [1,2,3] + [4,5,6]
[1, 2, 3, 4, 5, 6]

Basic rule is, you can use a + between string and string,
integer/float and integer/float, list and list and tuple and tuple,
and "," is a string, so it breaks it. Take it out...

max_item += i #( max_item = max_item + i)

At this point, max_item would equal [5,6,7,8,9] and adding i to it
would produce -
[5,6,7,8,9, 5,6,7,8,9].

You've got various ways to do this.

max_item = [max_item] + [i] #and this is a terrible way to do it,
max_item = [max_item, i] #Better. There's a problem with this however...

Or, you could change line 8 and 11 to
max_item.append(i)

But that would give [[5,6,7,8,9]] if product != maximum the second
time around, but
[[5,6,7,8,9], [5,6,7,8,9]] if product did equal maximum.

The problem with this - max_item = [max_item, i] is that if you entered
seq = [[5,6,7,8,9], [5,6,7,8,9], [5,6,7,8,9] ]

max_item would come out as [ [ [5,6,7,8,9], [5,6,7,8,9] ],[5,6,7,8,9] ]...

If you are going to be handling more than two sequences, I'd recommend
that you change lines 8 and 11 to max_item.append(i) and insert a line
or two before your return statement on line 12, and it would all look
like this -

def calc(seq):
maximum = 0
max_item = []
for i in seq:
product = (i[0]*100 + i[1]*10 + i[2]) * (i[3]*10 + i[4])
if product > maximum:
maximum = product
max_item.append(i) #append is a list method, by the way
elif product == maximum:
max_item.append(i)

#This will remove [[5,6,7,8,9]]
if len(max_item) == 1:
max_item = max_item[0]

return max_item, maximum


Do you see how that works? max_item = [max_item] + [i]  would give you
the same multiplying brackets problem as max_item = [max_item, i],
plus it's mentally harder to debug.

Especially as i is traditionally used as an integer  in 'for loops'
since the days of BASIC...
for i in range(10):
print x[i]

so having [i] sitting out there by itself is confusing.

Good luck.

Regards,

Liam Clarke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with prime number program

2005-10-31 Thread Norman Silverstone
On Mon, 2005-10-31 at 06:12 -0500, Kent Johnson wrote:
> Norman Silverstone wrote:
> > I am a beginner so, I hope what I give, makes sense. In it's simplest
> > form what is wrong with :-
> > 
> > n = input("Enter a number")
> > if n % 2 != 0 and n % 3 != 0:
> >print n, " Is a prime number"
> > 
> This only gives the correct answer if n < 25. You can't test against a fixed 
> list of divisors, there will always be a non-prime whose divisors are not in 
> your list.

Thank you for your comment which, if I understand you correctly, implies
that prime numbers greater than 25 will not be recognised. Surely, that
cannot be correct. However, if it is correct, could you please
demonstrate what you mean for my education.

Norman

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with prime number program

2005-10-31 Thread Glen Wheeler
From: "Norman Silverstone" <[EMAIL PROTECTED]>
> On Mon, 2005-10-31 at 06:12 -0500, Kent Johnson wrote:
>> Norman Silverstone wrote:
>> > I am a beginner so, I hope what I give, makes sense. In it's simplest
>> > form what is wrong with :-
>> >
>> > n = input("Enter a number")
>> > if n % 2 != 0 and n % 3 != 0:
>> >print n, " Is a prime number"
>> >
>> This only gives the correct answer if n < 25. You can't test against a 
>> fixed list of divisors, there will always be a non-prime whose divisors 
>> are not in your list.
>
> Thank you for your comment which, if I understand you correctly, implies
> that prime numbers greater than 25 will not be recognised. Surely, that
> cannot be correct. However, if it is correct, could you please
> demonstrate what you mean for my education.
>

  The problem is that composite numbers over 25 will be recognised.
  11 is prime, but 55 is not.  Your program will tell me that 55 is prime. 
Similarly with 34, etc.
  A reasonably easy to understand prime number generator, that also operates 
quickly, is the classic sieve of Eratosthenes (sp).
  Google is your friend :).

  HTH,
  Glen 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with prime number program

2005-10-31 Thread Kent Johnson
Norman Silverstone wrote:
> On Mon, 2005-10-31 at 06:12 -0500, Kent Johnson wrote:
> 
>>Norman Silverstone wrote:
>>
>>>I am a beginner so, I hope what I give, makes sense. In it's simplest
>>>form what is wrong with :-
>>>
>>>n = input("Enter a number")
>>>if n % 2 != 0 and n % 3 != 0:
>>>   print n, " Is a prime number"
>>>
>>
>>This only gives the correct answer if n < 25. You can't test against a fixed 
>>list of divisors, there will always be a non-prime whose divisors are not in 
>>your list.
> 
> 
> Thank you for your comment which, if I understand you correctly, implies
> that prime numbers greater than 25 will not be recognised. Surely, that
> cannot be correct. However, if it is correct, could you please
> demonstrate what you mean for my education.

More precisely, it will give an incorrect answer for any non-prime that is not 
divisible by 2 or 3, for example 25. 

 >>> def test(n):
 ...   if n % 2 != 0 and n % 3 != 0:
 ... print n, 'is prime'
 ...
 >>> test(2)
 >>> test(3)

Hmm, not looking so good for 2 and 3 either...
 >>> test(4)
 >>> test(5)
5 is prime
 >>> test(25)
25 is prime

Not so sure about that one either!

Kent

-- 
http://www.kentsjohnson.com

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with prime number program

2005-10-31 Thread Norman Silverstone

> > Thank you for your comment which, if I understand you correctly, implies
> > that prime numbers greater than 25 will not be recognised. Surely, that
> > cannot be correct. However, if it is correct, could you please
> > demonstrate what you mean for my education.
> 
> More precisely, it will give an incorrect answer for any non-prime that is 
> not divisible by 2 or 3, for example 25. 
> 
>  >>> def test(n):
>  ...   if n % 2 != 0 and n % 3 != 0:
>  ... print n, 'is prime'
>  ...
>  >>> test(2)
>  >>> test(3)
> 
> Hmm, not looking so good for 2 and 3 either...
>  >>> test(4)
>  >>> test(5)
> 5 is prime
>  >>> test(25)
> 25 is prime
> 
> Not so sure about that one either!

 How right you and Glen are and I am not very bright!! I must think
again and thanks.

Norman


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2005-10-31 Thread Roberts, Alice








Good morning,

 

I’m migrating from DOS scripting to Python, and need a
little help.  I got this sample from a Google search that brought me to effbot.org,
http://effbot.org/librarybook/ftplib.htm.
 Also, I plugged in all my variables when I tested, but replaced with
generics for this email. ie) ftp.website.com.

 

Thank you,

 

Alice Roberts

Ambac Assurance Corp.

 

from ftplib import FTP

import sys

 

def upload(ftp, file):

   
ftp.storlines("STOR " + file, open(file))

 

ftp = ftplib.FTP('ftp.website.com')   # connect to
host, default port

ftp.login('user’, 'pwd')
# user, passwd

ftp.set_debuglevel(1) 

ftp.cwd('/temp')

ftp.delete('fname.txt')

 

upload(ftp, "fname.txt")

 

ftp.quit()

ftp.close()

 

When I ran in debugger, calling the FTP library invokes a no
SOCKS module error that the ftplib seems to be trying to access.

 

>>> --Call--

>>> Unhandled exception
while debugging...

Traceback (most recent call last):

  File
"C:\Python24\lib\ftplib.py", line 42, in ?

    import SOCKS;
socket = SOCKS; del
SOCKS # import SOCKS as socket

ImportError: No module named SOCKS

>>> --Call--

>>> Unhandled exception
while debugging...

Traceback (most recent call last):

  File
"C:\Python24\lib\socket.py", line 50, in ?

    import _ssl

ImportError: No module named _ssl

>>> --Call--

>>> Unhandled exception
while debugging...

Traceback (most recent call last):

  File
"C:\Python24\lib\os.py", line 36, in _get_exports_list

    return
list(module.__all__)

AttributeError: 'module' object has
no attribute '__all__'

[Dbg]>>> Traceback (most
recent call last):

  File "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
line 305, in RunScript

   
debugger.run(codeObject, __main__.__dict__, start_stepping=1)

  File
"C:\Python24\Lib\site-packages\pythonwin\pywin\debugger\__init__.py",
line 60, in run

    _GetCurrentDebugger().run(cmd,
globals,locals, start_stepping)

  File
"C:\Python24\Lib\site-packages\pythonwin\pywin\debugger\debugger.py",
line 595, in run

    exec cmd in
globals, locals

  File "c:\temp\ftp_get_hub.py",
line 13, in ?

    ftp =
ftplib.FTP("ftp.website.com")   # connect to host, default
port

NameError: name 'ftplib' is not
defined

[Dbg]>>> Traceback (most
recent call last):

  File
"C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
line 305, in RunScript

    debugger.run(codeObject,
__main__.__dict__, start_stepping=1)

  File
"C:\Python24\Lib\site-packages\pythonwin\pywin\debugger\__init__.py",
line 60, in run

   
_GetCurrentDebugger().run(cmd, globals,locals, start_stepping)

  File
"C:\Python24\Lib\site-packages\pythonwin\pywin\debugger\debugger.py",
line 595, in run

    exec cmd in
globals, locals

  File "c:\temp\ftp_put_hub.py",
line 3, in ?

    import FTP

ImportError: No module named FTP

[Dbg]>>> Traceback (most
recent call last):

  File
"C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
line 305, in RunScript

   
debugger.run(codeObject, __main__.__dict__, start_stepping=1)

  File
"C:\Python24\Lib\site-packages\pythonwin\pywin\debugger\__init__.py",
line 60, in run

   
_GetCurrentDebugger().run(cmd, globals,locals, start_stepping)

  File
"C:\Python24\Lib\site-packages\pythonwin\pywin\debugger\debugger.py",
line 595, in run

    exec cmd in
globals, locals

  File "c:\temp\ftp_put_hub.py",
line 9, in ?

    ftp =
ftplib.FTP('ftp.website.com')   # connect to host, default port

NameError: name 'ftplib' is not
defined

[Dbg]>>>






___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie Question - Python vs Perl

2005-10-31 Thread Andrew P
If you are interested in learning another tool, please, start with
Python.  If you are interested in scripting UNIX, Perl is a fine
choice.  There prevalence matters, and quite a bit.  But sys admins
are usually very Perl-centric, and in my experience monolingual, and a
bit of an insular community :)

Python is more than the equal of Perl by any measure.  Including
system administration.  But moving beyond that is also a lovely
language for building applications, and everything from lightweight
CGI scripts to using hefty web frameworks, of which there are plenty
to choose from.

Perl is a language of exceptions to the rules.  Python tries very hard
to be consistent, which makes it much easier to learn, and much easier
to use, and much, much easier to apply the concepts you have learned
to other languages.  Including Perl, as a second or third language.

Perl can be coerced into big jobs, but it's not very pleasant.   The
best you can hope to keep in your head at once is your own set of
idioms, which will -not- match anybody elses, and will likely change
from week to week on you anyway.   And really when people tell you
they can't read what they wrote the day before when they come back to
it, they aren't lying!

Having said that, I love Perl, because it -is- quirky and sprawling
and lovable.  It's pretty much the worst case scenario of
everything-and-the-kitchen-sink, and really not so bad for all that,
and definitely more fun for it.  So if that appeals, then you'll have
fun too.

But Python tends to be compared to general purpose languages like Java
and C++ more often.  OOP heavyweights of the world.  Actually, let me
find that quote by Bruce Eckel, who wrote the (very) popular "Thinking
in Java" and "Thinking in C++" books.  Here it is:

"I believe it was definitely worth moving from C to C++, and from C++
to Java. So there was progress there. For something as advanced as
Python is over those languages -- and as different -- there will be
some hesitation."

And:

"When you have the experience of really being able to be as productive
as possible, then you start to get pissed off at other languages. You
think, 'Gee, I've been wasting my time with these other languages.'"

That second quote applies to many "language vs language" comparisons,
obviously.  But it's food for thought.

Oh, and never underestimate the power of the interactive interpreter! 
Don't do it!  Ever!

Take care,

Andrew

On 10/30/05, Scott Clausen <[EMAIL PROTECTED]> wrote:
> As a newbie to Python I'd like to know if someone can tell me some
> strengths and weaknesses of this language. The reason I'm asking is a
> friend told me I should learn Perl over Python as it's more
> prevalent.  I'm going to be using it on a Mac.
>
> I'd appreciate hearing any views on this topic. My own view is that
> it's always good to learn new things as you then have more tools to
> use in your daily programming.
>
> Thanks in advance.
>
> Scott
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2005-10-31 Thread Andrew P
Before you hit the debugger, it might be a good idea to just run the
script normally, either at the command line, or inside IDLE/Pythonwin.

Doing so will spit out:

Traceback (most recent call last):
  File "", line 1, in ?
NameError: name 'ftplib' is not defined

Because you imported with:

from ftplib import FTP"

you don't need to prepend the module name before you call FTP.  If you
do "import ftplib" instead, then it will work.  Conversely, if you
call with just "FTP("ftp.website.com") it will also work.

 It's really a personal choice which you do, but the second choice is
safer, as it has no chance of polluting your module's namespace if you
accidentally call something FTP.

Also, I noticed when pasting into IDLE that you have mismatched quotes:

ftp.login('user', 'pwd') # user, passwd

Using IDLE/Pythonwin will catch problems like that.

Good luck,

Andrew

On 10/31/05, Roberts, Alice <[EMAIL PROTECTED]> wrote:
>
>
>
> Good morning,
>
>
>
> I'm migrating from DOS scripting to Python, and need a little help.  I got
> this sample from a Google search that brought me to effbot.org,
> http://effbot.org/librarybook/ftplib.htm.  Also, I plugged
> in all my variables when I tested, but replaced with generics for this
> email. ie) ftp.website.com.
>
>
>
> Thank you,
>
>
>
> Alice Roberts
>
> Ambac Assurance Corp.
>
>
>
> from ftplib import FTP
>
> import sys
>
>
>
> def upload(ftp, file):
>
> ftp.storlines("STOR " + file, open(file))
>
>
>
> ftp = ftplib.FTP('ftp.website.com')   # connect to host, default port
>
> ftp.login('user', 'pwd') # user, passwd
>
> ftp.set_debuglevel(1)
>
> ftp.cwd('/temp')
>
> ftp.delete('fname.txt')
>
>
>
> upload(ftp, "fname.txt")
>
>
>
> ftp.quit()
>
> ftp.close()
>
>
>
> When I ran in debugger, calling the FTP library invokes a no SOCKS module
> error that the ftplib seems to be trying to access.
>
>
>
> >>> --Call--
>
> >>> Unhandled exception while debugging...
>
> Traceback (most recent call last):
>
>   File "C:\Python24\lib\ftplib.py", line 42, in ?
>
> import SOCKS; socket = SOCKS; del SOCKS # import SOCKS as socket
>
> ImportError: No module named SOCKS
>
> >>> --Call--
>
> >>> Unhandled exception while debugging...
>
> Traceback (most recent call last):
>
>   File "C:\Python24\lib\socket.py", line 50, in ?
>
> import _ssl
>
> ImportError: No module named _ssl
>
> >>> --Call--
>
> >>> Unhandled exception while debugging...
>
> Traceback (most recent call last):
>
>   File "C:\Python24\lib\os.py", line 36, in _get_exports_list
>
> return list(module.__all__)
>
> AttributeError: 'module' object has no attribute '__all__'
>
> [Dbg]>>> Traceback (most recent call last):
>
>   File
> "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
> line 305, in RunScript
>
> debugger.run(codeObject, __main__.__dict__, start_stepping=1)
>
>   File
> "C:\Python24\Lib\site-packages\pythonwin\pywin\debugger\__init__.py",
> line 60, in run
>
> _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
>
>   File
> "C:\Python24\Lib\site-packages\pythonwin\pywin\debugger\debugger.py",
> line 595, in run
>
> exec cmd in globals, locals
>
>   File "c:\temp\ftp_get_hub.py", line 13, in ?
>
> ftp = ftplib.FTP("ftp.website.com")   # connect to host, default port
>
> NameError: name 'ftplib' is not defined
>
> [Dbg]>>> Traceback (most recent call last):
>
>   File
> "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
> line 305, in RunScript
>
> debugger.run(codeObject, __main__.__dict__, start_stepping=1)
>
>   File
> "C:\Python24\Lib\site-packages\pythonwin\pywin\debugger\__init__.py",
> line 60, in run
>
> _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
>
>   File
> "C:\Python24\Lib\site-packages\pythonwin\pywin\debugger\debugger.py",
> line 595, in run
>
> exec cmd in globals, locals
>
>   File "c:\temp\ftp_put_hub.py", line 3, in ?
>
> import FTP
>
> ImportError: No module named FTP
>
> [Dbg]>>> Traceback (most recent call last):
>
>   File
> "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
> line 305, in RunScript
>
> debugger.run(codeObject, __main__.__dict__, start_stepping=1)
>
>   File
> "C:\Python24\Lib\site-packages\pythonwin\pywin\debugger\__init__.py",
> line 60, in run
>
> _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
>
>   File
> "C:\Python24\Lib\site-packages\pythonwin\pywin\debugger\debugger.py",
> line 595, in run
>
> exec cmd in globals, locals
>
>   File "c:\temp\ftp_put_hub.py", line 9, in ?
>
> ftp = ftplib.FTP('ftp.website.com')   # connect to host, default port
>
> NameError: name 'ftplib' is not defined
>
> [Dbg]>>>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with prime number program

2005-10-31 Thread Alan Gauld
> n = input("Enter a number")
> if n % 2 != 0 and n % 3 != 0:
>   print n, " Is a prime number"
> 
> Comments please.

According to this 25 is a prime number

Alan G.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2005-10-31 Thread Alan Gauld
> When I ran in debugger, calling the FTP library invokes a no SOCKS
> module error that the ftplib seems to be trying to access.

Can you tell us which debugger you are using? I don't recognise what's 
going on here.
 
>>> --Call--

This looks like the Python interactive prompt, 
but whats the --Call-- thing?

Its not valid Python syntax and yet the messages below suggest 
that it is being processed in a semi-sane way. 

[Dbg]>>> Traceback (most recent call last):

And I don;t recognise the square brackets [Dbg] either. 
Which debugger is it?

Finally given the number of import errors I'd suggest there is a path
problem somewhere. But without knowing which OS, which IDE 
and where/how you are executing this I can only guess.

Alan G.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2005-10-31 Thread Roberts, Alice








Hi,

 

My os.system() isn’t waiting for exit status, jumping
right into next os.system().

 

import os

 

DIR = 'v:/pam/batch/ambac/'

CMD1 = DIR + 'Prices_Prep.cmd'

CMD2 = DIR + 'positions.cmd'

CMD3 = DIR + 'ftp_hub.cmd'

CMD4 = DIR + 'import_prices.cmd'

 

try:

    

    os.system(CMD1)

    

 

except IOError, (errno, strerror):

    print " E/S(%s): %s" % (errno, strerror)

 

#result=os.system

#    print result

 

try:

 

    os.system(CMD2)

 

except IOError, (errno, strerror):

    print " E/S(%s): %s" % (errno, strerror)    

 

#result=os.system

#    print result

 

try:

 

    os.system(CMD3)

 

except IOError, (errno, strerror):

    print " E/S(%s): %s" % (errno, strerror)    

 

#result=os.system

#    print result

 

try:

 

    os.system(CMD4)

 

except IOError, (errno, strerror):

    print " E/S(%s): %s" % (errno, strerror)    

 

#result=os.system

#    print result

 

 

Any thoughts?

 

Thanks,

Alice Roberts

Ambac Assurance Corp.






___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2005-10-31 Thread Andrew P
If I'm not mistaken, that's the Pythonwin debugger spitting messages
to the interactive prompt.  I just used it to step through your your
games framework example :)

Being the first time I'd used any Python debugger, it didn't occur to
me that the look of it was non-standard.

I actually got the same exceptions popping up running his code, even
after fixing the problems I pointed out.  I figured the debugger shows
caught exceptions.  I noticed it before and hadn't given it much
thought, but looking at his code, there are try/except pairs in all
the spots the debugger highlighted:

from ftplib:

try:
import SOCKS; socket = SOCKS; del SOCKS # import SOCKS as socket
from socket import getfqdn; socket.getfqdn = getfqdn; del getfqdn
except ImportError:
import socket

from os.py:

def _get_exports_list(module):
try:
return list(module.__all__)
except AttributeError:
return [n for n in dir(module) if n[0] != '_']

and socket.py:

try:
import _ssl
from _ssl import *
_have_ssl = True
except ImportError:
pass

Thats why I suspect that this:

File "c:\temp\ftp_put_hub.py", line 9, in ?
ftp = ftplib.FTP('ftp.website.com')   # connect to host, default port

Was the only real error being thrown.


On 10/31/05, Alan Gauld <[EMAIL PROTECTED]> wrote:
> > When I ran in debugger, calling the FTP library invokes a no SOCKS
> > module error that the ftplib seems to be trying to access.
>
> Can you tell us which debugger you are using? I don't recognise what's
> going on here.
>
> >>> --Call--
>
> This looks like the Python interactive prompt,
> but whats the --Call-- thing?
>
> Its not valid Python syntax and yet the messages below suggest
> that it is being processed in a semi-sane way.
>
> [Dbg]>>> Traceback (most recent call last):
>
> And I don;t recognise the square brackets [Dbg] either.
> Which debugger is it?
>
> Finally given the number of import errors I'd suggest there is a path
> problem somewhere. But without knowing which OS, which IDE
> and where/how you are executing this I can only guess.
>
> Alan G.
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2005-10-31 Thread Alan Gauld
> My os.system() isn't waiting for exit status, jumping right into next
> os.system().

Are you sure it isn't just running very quickly?
The time it takes to display stuff on a screen is significant - all those 
phosphorescent pixels :-)

os.system doesn't have to wait for that so it tends to run programs 
much faster than normal...

Just a thought,

Alan G.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2005-10-31 Thread Roberts, Alice
Well, I'm looking into os.spawnl with os.P_WAIT, now.

Thanks,

-Original Message-
From: Alan Gauld [mailto:[EMAIL PROTECTED] 
Sent: Monday, October 31, 2005 1:57 PM
To: Roberts, Alice; tutor@python.org
Subject: Re: [Tutor] (no subject)

> My os.system() isn't waiting for exit status, jumping right into next
> os.system().

Are you sure it isn't just running very quickly?
The time it takes to display stuff on a screen is significant - all
those 
phosphorescent pixels :-)

os.system doesn't have to wait for that so it tends to run programs 
much faster than normal...

Just a thought,

Alan G.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Tainted characters and CGI

2005-10-31 Thread Tim Johnson
Hello:
I need to tighten my handling of CGI transmissions.
I particular, I need to develop a strategy of safely dealing
with "tainted" characters.
I'd appreciate any pointers to documentation and resources
regarding this matter, as well as comments and caveats.
At this time and for the forseeable future, we will be
running our CGI services on *nix systems.
 
Thanks
tim

-- 
Tim Johnson <[EMAIL PROTECTED]>
  http://www.alaska-internet-solutions.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie Question - Python vs Perl

2005-10-31 Thread Tim Johnson
* Scott Clausen <[EMAIL PROTECTED]> [051030 16:30]:
> As a newbie to Python I'd like to know if someone can tell me some  
> strengths and weaknesses of this language. The reason I'm asking is a  
> friend told me I should learn Perl over Python as it's more  
> prevalent.  I'm going to be using it on a Mac.
 
  Prevalent? So what? Forget Perl entirely. Learn python and rebol 
  (www.rebol.com). At the same time.
  That's how we trained programmers here.
  Rebol arguably exceeds both python and perl in terms of sheer
  productivity on a line for line basis, but has a very small 
  user base and fewer modules.

  But the bottom line is to be multi-lingual. 
  Here's a pretty standard coding day for me.
  1)Write rebol code which parses html and generates python, perl
   and javascript code for deployment.
  2)Write python code for the deployment (front end), database
   interaction, server-side data validation etc.
  3)Write Javascript for client-side data validation, dynamic
html etc.
  4)Write elisp code to enhance productivity of my Emacs and Xemacs
Editors.
  5)Use vim/gvim for system wide analysis and editing.

  I believe the rebol is pretty straight-forward and easy to
  install for the mac.

  I use Python for most of the services used directly by customers
  on larger projects 'cuz it scales better (for me). and python teaches
  me good coding practices. IOWS, coding in python makes me a better
  rebol programmer too.

  The bottom line is don't get stuck on one programming language.
  I've seen new programmers go thru a fast learning curve, pick up
  something faster than an ol' fart like me would, but get so
  settled in one programming niche or another that they can't or
  won't change. Not good!

  I think python is the best way to learn *good* programming.
  MTCW
  tim

> I'd appreciate hearing any views on this topic. My own view is that  
> it's always good to learn new things as you then have more tools to  
> use in your daily programming.
> 
> Thanks in advance.
> 
> Scott
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Tim Johnson <[EMAIL PROTECTED]>
  http://www.alaska-internet-solutions.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tainted characters and CGI

2005-10-31 Thread Ron Weidner


--- Tim Johnson <[EMAIL PROTECTED]> wrote:

> Hello:
> I need to tighten my handling of CGI transmissions.
> I particular, I need to develop a strategy of safely
> dealing with "tainted" characters.

Ahh... tainted characters.  If by "tainted" you mean
not UTF-8, there is a c tool called "iconv" that fixes
"tainted" characters.  I believe Python has a wrapper,
but I didn't check before sending this e-mail.  Good
luck and please write back if you implement a working
solution.


--
Ronald Weidner
http://www.techport80.com
PHP Software developer for hire.




__ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] while/if/elif/else loops

2005-10-31 Thread Zameer Manji
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

I'm new to programming and python. I've have recently been experimenting
with while/if/elif/else loops and I've created a simple number guessing
game. Now I want to create a coin tossing game, but I don't know how to
structure it in python. The code I already have (but it's not working)
is below.


#Coin Toss Game

print "This game will simulate 100 coin tosses and then tell you the
number of head's and tails"

import random

tosses = 0
heads = 0
tails = 0

while tosses = 100<0:
   coin = randrange(1)
   tosses +=1
   if coin == 0:
  heads +=1
  print "Heads"
else:
  tails +=1
  Print "Tails"
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.2 (MingW32)

iQEVAwUBQ2accw759sZQuQ1BAQqoyQgAsmVhRidMC1/WpQms6fChX+z62DWSpmRW
qiY9F7bZAYZusyNsHHDUpuTAYdI0LXxgLVmYBKDz3tKhVCbEZTn9FUwgw5A2thYy
I5o82tWXZnIpgmFIN2AysAj2dCI4mSfi/IJjE5JvG+IFELWigMb9Pf6tap4HiB71
IBayql8MN1XrA2zv8fXQs35zVwxnBUSvAHZuUBLi4hDcPxY/d71X/JHqfqpf3svS
ClzUlYqLhXld+39/aiRFKOXHyVCnfsEUcAXB45r110Q3K+7KegwgX4Js8qL5dA66
d74HlLMb6Cp6G5AlNdQoKDin8jlMloxeQpb60hS+HmnBwkEFukyNHA==
=QMuB
-END PGP SIGNATURE-
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tainted characters and CGI

2005-10-31 Thread Tim Johnson
* Ron Weidner <[EMAIL PROTECTED]> [051031 12:38]:
> 
> 
> --- Tim Johnson <[EMAIL PROTECTED]> wrote:
> 
> > Hello:
> > I need to tighten my handling of CGI transmissions.
> > I particular, I need to develop a strategy of safely
> > dealing with "tainted" characters.
> 
> Ahh... tainted characters.  If by "tainted" you mean
> not UTF-8, there is a c tool called "iconv" that fixes
> "tainted" characters.  I believe Python has a wrapper,
> but I didn't check before sending this e-mail.  Good
> luck and please write back if you implement a working
> solution.
 
  Now that's serendipity for ya. I wasn't thinking about
  none-UTF-8 characters, but that's a good thread to
  investigate also.

  Actually, google gives me a thread

  http://mail.python.org/pipermail/tutor/2005-August/040619.html

  regarding handling of characters passed from a CGI post
  that could be exploited by malicious hacking.

  thanks
  tim

-- 
Tim Johnson <[EMAIL PROTECTED]>
  http://www.alaska-internet-solutions.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tainted characters and CGI

2005-10-31 Thread John Fouhy
On 01/11/05, Tim Johnson <[EMAIL PROTECTED]> wrote:
> Hello:
> I need to tighten my handling of CGI transmissions.
> I particular, I need to develop a strategy of safely dealing
> with "tainted" characters.

A friend of mine has written a module that may be useful to you:

"""
zstr is an extension of the Python str class that has a built-in
mechanism for escaping the string for use in different contexts. Most
importantly, a zstr object keeps track of its current display state,
making the escaping operations idempotent.
...
The main intent for zstr is to help with CGI and web-related code. CGI
programming involves a lot of string manipulation. For any given
string, there might be a user input version of it, an HTML-escaped
version of it, a SQL-escaped version of it, and possibly other
customised escaped versions for things like filtering certain HTML
tags but letting others through.
"""

Link: http://www.mcs.vuw.ac.nz/~jester/zstr/

--
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2005-10-31 Thread Hugo González Monteverde
Do you need time to see the output? Then why don't you just use 
time.sleep(5) after each command?

Hugo

Roberts, Alice wrote:
> Well, I'm looking into os.spawnl with os.P_WAIT, now.
> 
> Thanks,
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tainted characters and CGI

2005-10-31 Thread Tim Johnson
* John Fouhy <[EMAIL PROTECTED]> [051031 14:16]:
> On 01/11/05, Tim Johnson <[EMAIL PROTECTED]> wrote:
> > Hello:
> > I need to tighten my handling of CGI transmissions.
> > I particular, I need to develop a strategy of safely dealing
> > with "tainted" characters.
> 
> A friend of mine has written a module that may be useful to you:
 
  Hey - great tip!
  I will be checking this out thoroughly.
  Thanks
  (great word "idempotent")
  tim

> """
> zstr is an extension of the Python str class that has a built-in
> mechanism for escaping the string for use in different contexts. Most
> importantly, a zstr object keeps track of its current display state,
> making the escaping operations idempotent.
> ...
> The main intent for zstr is to help with CGI and web-related code. CGI
> programming involves a lot of string manipulation. For any given
> string, there might be a user input version of it, an HTML-escaped
> version of it, a SQL-escaped version of it, and possibly other
> customised escaped versions for things like filtering certain HTML
> tags but letting others through.
> """
> 
> Link: http://www.mcs.vuw.ac.nz/~jester/zstr/
> 
> --
> John.
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Tim Johnson <[EMAIL PROTECTED]>
  http://www.alaska-internet-solutions.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Talking to UDPServer

2005-10-31 Thread Carroll, Barry








Greetings:

 

I am writing a browser-based interface to a server program
which extends SocketServer.UDPServer.  The program listens on a well-known
socket, receiving commands, verifying them and using their content to drive our
test hardware, returning status to the client.  The current client
interface is a command line interface that allows the user to type in a command
and sends it to the server, receives the status response and displays it for
the user.  My job is to duplicate the client functionality in a set of web
pages.  

 

My problem is that, while I can find documentation on
UDPServer, I cannot find anything on how a remote client talks to the
server.  How is this done in Python?  Can someone point me to a
how-to, tutorial or the like?  

 

Thanks in advance.

 

Barry

 

 

 






___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] while/if/elif/else loops

2005-10-31 Thread Pujo Aji
Let's comment something:1. If you have error please show us your error message.2. When you code python be aware of indention, be persistent for example use tab space 4.3. import should be on the top of your code.
4. to choose random between integer 1 or 0 use randint(0,1)5. your last code use Print it should be print (small letter please).Cheers,pujoOn 10/31/05, 
Zameer Manji <[EMAIL PROTECTED]> wrote:
-BEGIN PGP SIGNED MESSAGE-Hash: SHA512I'm new to programming and python. I've have recently been experimentingwith while/if/elif/else loops and I've created a simple number guessinggame. Now I want to create a coin tossing game, but I don't know how to
structure it in python. The code I already have (but it's not working)is below.#Coin Toss Gameprint "This game will simulate 100 coin tosses and then tell you thenumber of head's and tails"
import randomtosses = 0heads = 0tails = 0while tosses = 100<0:   coin = randrange(1)   tosses +=1   if coin == 0:  heads +=1  print "Heads"else:
  tails +=1  Print "Tails"-BEGIN PGP SIGNATURE-Version: GnuPG v1.4.2 (MingW32)iQEVAwUBQ2accw759sZQuQ1BAQqoyQgAsmVhRidMC1/WpQms6fChX+z62DWSpmRWqiY9F7bZAYZusyNsHHDUpuTAYdI0LXxgLVmYBKDz3tKhVCbEZTn9FUwgw5A2thYy
I5o82tWXZnIpgmFIN2AysAj2dCI4mSfi/IJjE5JvG+IFELWigMb9Pf6tap4HiB71IBayql8MN1XrA2zv8fXQs35zVwxnBUSvAHZuUBLi4hDcPxY/d71X/JHqfqpf3svSClzUlYqLhXld+39/aiRFKOXHyVCnfsEUcAXB45r110Q3K+7KegwgX4Js8qL5dA66d74HlLMb6Cp6G5AlNdQoKDin8jlMloxeQpb60hS+HmnBwkEFukyNHA==
=QMuB-END PGP SIGNATURE-___Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Talking to UDPServer

2005-10-31 Thread Kent Johnson
Carroll, Barry wrote:
> I am writing a browser-based interface to a server program which extends 
> SocketServer.UDPServer.  The program listens on a well-known socket, 
> receiving commands, verifying them and using their content to drive our 
> test hardware, returning status to the client.  The current client 
> interface is a command line interface that allows the user to type in a 
> command and sends it to the server, receives the status response and 
> displays it for the user.  My job is to duplicate the client 
> functionality in a set of web pages. 
> 
> My problem is that, while I can find documentation on UDPServer, I 
> cannot find anything on how a remote client talks to the server.  How is 
> this done in Python?  Can someone point me to a how-to, tutorial or the 
> like? 

Are you trying to write a browser-based client, or a Python client? As far as I 
know, it is not possible to write a browser client in Python, or a browser UDP 
client. You can write a UDP client in Python, I think you have to use the 
socket module directly.

Kent

-- 
http://www.kentsjohnson.com

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] : [Slightly OT] Using Python to intercept audio from a program

2005-10-31 Thread Orri Ganel
Title: [Tutor]: [Slightly OT] Using Python to intercept audio from a
program




Hello all,

A week or two ago I sent in a few emails regarding using threads in
automating conversion between wav's and mp3's using lame.  However, the
program I use to generate these wav's, Audacity (a great program,
btw), can't record directly from another program, but instead catches
all audio directed at the speakers.  Being the person I am, I'm never
patient enough to sit there and do nothing else while I record these
wav's, so I do other things in the background.  Unfortunately, with the
current setup, any sounds generated by these background activities end
up in the wav files.  So I asked on the audacity-help mailing list
whether audacity has the capability to record directly from another
program, and the answer, sadly, was no. At least, not for Windows.  So
what I would like to do is attempt the same with Python, though right
now I have only the vaguest of ideas on how to proceed.  If anyone
could point me in the right direction, I would be very grateful.

Thanks in advance,
Orri
-- 
Email: singingxduck AT gmail DOT com
AIM: singingxduck
Programming Python for the fun of it.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Talking to UDPServer

2005-10-31 Thread Johan Geldenhuys




Maybe you could tel us if you already have the server listening on the
socket that you expec connections on? If, yes, do you want an example
of how a client connects to that socket?

Johan

Carroll, Barry wrote:

  
  
  
  
  Greetings:
   
  I am writing a
browser-based interface to a server program
which extends SocketServer.UDPServer.  The program listens on a
well-known
socket, receiving commands, verifying them and using their content to
drive our
test hardware, returning status to the client.  The current client
interface is a command line interface that allows the user to type in a
command
and sends it to the server, receives the status response and displays
it for
the user.  My job is to duplicate the client functionality in a set of
web
pages.  
   
  My problem is that, while
I can find documentation on
UDPServer, I cannot find anything on how a remote client talks to the
server.  How is this done in Python?  Can someone point me to a
how-to, tutorial or the like?  
   
  Thanks in advance.
   
  Barry
   
   
   
  
  

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
  



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] : [Slightly OT] Using Python to intercept audio from a program

2005-10-31 Thread Orri Ganel
By the way, if it makes a difference, the program I intend to attempt 
this with is Rhapsody , a part of the 
RealPlayer collection of media software.

-- 
Email: singingxduck AT gmail DOT com
AIM: singingxduck
Programming Python for the fun of it.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] while/if/elif/else loops

2005-10-31 Thread R. Alan Monroe

> while tosses = 100<0:

I didn't run the program, but this immediately caught my eye as
looking kind of suspect. Was it a typo? Most programs usually
have a need for comparisons of equal, or greater/less, but it's really
rare to need both combined in one statement...

Also if you really _do_ want to check two things being equal, don't
forget to use double equal ( == ).

Alan

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with prime number program

2005-10-31 Thread Danny Yoo


On Mon, 31 Oct 2005, Kent Johnson wrote:

> Norman Silverstone wrote:
> > I am a beginner so, I hope what I give, makes sense. In it's simplest
> > form what is wrong with :-
> >
> > n = input("Enter a number")
> > if n % 2 != 0 and n % 3 != 0:
> >print n, " Is a prime number"
> >
> This only gives the correct answer if n < 25. You can't test against a
> fixed list of divisors, there will always be a non-prime whose divisors
> are not in your list.

Kent's comment is actually a paraphrase of Euclid's "There are an infinite
number of primes" argument used in mathematics.  *grin*

http://mathworld.wolfram.com/EuclidsTheorems.html


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Turning kwargs into scalars

2005-10-31 Thread Steve Bergman
Say I have a function:

def f(self, **kwargs) :

and I want to take the key/value pairs and create a set of variables 
with the names of the keys.

For example, if I say:

f(x=5, y=2)

I want to create local variables 'x' and 'y' in the function, with 
values of 5 and 2 respectively.

How could I do this?

Thanks,
Steve Bergman




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Random Q on Python's internals?

2005-10-31 Thread Liam Clarke
Hi all,

I was perusing the standard library, and was wondering if anyone knew
how the internals of Python work, roughly or no.

Basically, I assume os.pipe() resides in a DLL somewhere, yet when I
open up Python24.DLL in PEexplorer I can't find mention of pipes
anywhere...

am I looking the right place?

Regards,

Liam Clarke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Turning kwargs into scalars

2005-10-31 Thread Danny Yoo


On Mon, 31 Oct 2005, Steve Bergman wrote:

> Say I have a function:
>
> def f(self, **kwargs) :
>
> and I want to take the key/value pairs and create a set of variables
> with the names of the keys.
>
> For example, if I say:
>
> f(x=5, y=2)
>
> I want to create local variables 'x' and 'y' in the function, with
> values of 5 and 2 respectively.

Hi Steve,

It's technically possible to do this in Python, but it's not advised to do
it, just because it becomes difficult to control what local variables will
be created.  That can make debugging very hard.  It also wrecks havoc with
lint-like programs like pychecker: http://pychecker.sourceforge.net/.

I guess I'm trying to say: are you really sure you want to do this?
*grin*

We can access those values through the kwargs dictionary though; is this
sufficient?  It's a very rare case where we want to really make local
variable names in such a dynamic way; perhaps there's another approach to
the problem you're solving?  If you can show us more of what you're trying
to do, we can give more suggestions.


Best of wishes!

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] while/if/elif/else loops

2005-10-31 Thread Alan Gauld
> import random
> 
> 
> while tosses = 100<0:
>   coin = randrange(1)

You need to preped random:

coin = random.randrange(1)

Otherwise it looks OKAlthough

>   tosses +=1
>   if coin == 0:
>  heads +=1
>  print "Heads"

You might want to output the count too

print heads, " heads"

Or maybe at the end just print a summary...

HTH,

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Random Q on Python's internals?

2005-10-31 Thread Danny Yoo


> I was perusing the standard library, and was wondering if anyone knew
> how the internals of Python work, roughly or no.
>
> Basically, I assume os.pipe() resides in a DLL somewhere, yet when I
> open up Python24.DLL in PEexplorer I can't find mention of pipes
> anywhere...

Hi Liam,


os.pipe() comes from the block of code near the top of os.py:

http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Lib/os.py?rev=1.58.2.4&view=markup

where it starts to talk to platform-specific modules like 'nt' and
'posix'.  The 'os.py' module is a sponge that absorbs the content of
platform-specific modules in an attempt to make things look platform
independent.  *grin*

pipe() really comes from the posix/nt module, whose implementation can be
found here:

http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Modules/posixmodule.c?view=markup


Best of wishes!

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor