Re: newbee

2014-08-14 Thread alister
On Wed, 13 Aug 2014 15:31:37 -0400, Terry Reedy wrote:

> On 8/13/2014 7:55 AM, alister wrote:
>>
>> I am not in the same league as many of the posters here when it comes
>> to Python but fortunately i do have two Raspberry Pi's :-)
> 
> Great! We really someone with hands-on experience.

I Hope the missing word there is welcome :-)
> 
>> if you are running the Pi connected to a TV/Monitor with the Gui
>> enabled then you should have access to Idle
> 
> Have you verified that Idle *does* (not just *should*) run on RPi? (That
> would mean having tcl/tk running, with whatever *it* requires on linux.)
> I am working on Idle and the idea of people (especially hobbyists,
> students, and other amateurs) running it on microsystems would really
> please me.
> 
Yes it does, but i tend to run mine headless (X forwarding is still an 
option though) but I prefer Geany, which i do run on the pi (with x 
forwarding) with no issues, just remember the Pi is not a particularly 
fast device.
 
>> If you have any more questions post them back &I hope I can help (Maybe
>> I can become useful to this group as the R-Pi expert,
> 
> Answering questions, sometimes after experiment and research, is a great
> way to learn.

I would say it is the ONLY way to really learn, you never really 
understand something until you have broken it and then fixed it or tried 
to teach it to someone.




-- 
Dungeons and Dragons is just a lot of Saxon Violence.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: newbee

2014-08-13 Thread Bob Martin
in 726715 20140813 103037 Chris Angelico  wrote:
>On Wed, Aug 13, 2014 at 9:57 AM, Frank Scafidi  wrote:
>> I just acquired a Raspberry Pi and want to program in Python. I was a PL/1
>> programmer back in the 60's & 70's and Python is similar. I am struggling
>> with some very fundamental things that I am not finding in the
>> documentation. Can someone help me with the basics like how do I save a
>> program I've written, reload it in Python, list the program once it's
>> loaded? How do I edit a program? Are these command line functions?
>
>These sound like RPi questions, rather than Python questions. You may
>find knowledgeable people here on this list, but if not, I would
>advise hunting down an RPi mailing list or newsgroup and asking there.
>Most of us here use full computers, where questions like "how do I
>save a file?" are trivially easy... you may find, actually, that
>starting on a PC and then pushing the file to the RPi is the easiest
>way to work.

comp.sys.rapberry-pi
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: newbee

2014-08-13 Thread Chris “Kwpolska” Warrick
On Aug 13, 2014 9:34 PM, "Terry Reedy"  wrote:
> Have you verified that Idle *does* (not just *should*) run on RPi? (That
would mean having tcl/tk running, with whatever *it* requires on linux.) I
am working on Idle and the idea of people (especially hobbyists, students,
and other amateurs) running it on microsystems would really please me.

I don't have a RPi, but I know it is just a glorified ARM computer with
terrible specs. But it is enough to run LXDE or other lightweight graphical
environments, which means tcl/tk is VERY likely to work. You could also
look up packages for Raspbian or other RPi-friendly distros and see
python-tk there, or various Python tutorials for the device:

http://davidbriddock.blogspot.com/2013/04/learn-python-installing-tkinter.html

-- 
Chris “Kwpolska” Warrick 
Sent from my SGS3.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: newbee

2014-08-13 Thread Larry Hudson

On 08/12/2014 04:57 PM, Frank Scafidi wrote:

I just acquired a Raspberry Pi and want to program in Python. I was a PL/1 
programmer back in
the 60's & 70's and Python is similar. I am struggling with some very 
fundamental things that I
am not finding in the documentation. Can someone help me with the basics like 
how do I save a
program I've written, reload it in Python, list the program once it's loaded? 
How do I edit a
program? Are these command line functions?

Thanks
Frank


You've already received a lot of suggestions, but I'll add one more...

If you don't mind shelling out for some dead-tree documentation, there is a book in the "Sam's 
Teach Yourself in 24 Hours" series -- Python Programming for Raspberry Pi.


It is a pretty good basic tutorial for Python in general, and specifically written for the RPi. 
 You might check it out.  (Current Amazon price -- $25.81)


 -=- Larry -=-

--
https://mail.python.org/mailman/listinfo/python-list


Re: newbee

2014-08-13 Thread Terry Reedy

On 8/13/2014 7:55 AM, alister wrote:


I am not in the same league as many of the posters here when it comes to
Python but fortunately i do have two Raspberry Pi's :-)


Great! We really someone with hands-on experience.


if you are running the Pi connected to a TV/Monitor with the Gui enabled
then you should have access to Idle


Have you verified that Idle *does* (not just *should*) run on RPi? 
(That would mean having tcl/tk running, with whatever *it* requires on 
linux.) I am working on Idle and the idea of people (especially 
hobbyists, students, and other amateurs) running it on microsystems 
would really please me.



If you have any more questions post them back &I hope I can help
(Maybe I can become useful to this group as the R-Pi expert,


Answering questions, sometimes after experiment and research, is a great 
way to learn.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: newbee

2014-08-13 Thread William Ray Wing
On Aug 13, 2014, at 9:57 AM, alister  wrote:

> On Wed, 13 Aug 2014 15:13:34 +0200, Mok-Kong Shen wrote:
> 
>> Am 13.08.2014 13:55, schrieb alister:
>> [snip]
>> 
>> A related question: How could one write a Python program and have it run
>> on a mobile phone in general (independent of a PC)?
>> 
>> M. K. Shen
> 
> you would need a python interpreter for that device, IIRC there is one 
> available for android, I do not know about IOS
> 

There are several for iOS, but because of Apple’s sandboxing they don’t have as 
much reach as you might want.

-Bill
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: newbee

2014-08-13 Thread alister
On Wed, 13 Aug 2014 15:13:34 +0200, Mok-Kong Shen wrote:

> Am 13.08.2014 13:55, schrieb alister:
> [snip]
> 
> A related question: How could one write a Python program and have it run
> on a mobile phone in general (independent of a PC)?
> 
> M. K. Shen

you would need a python interpreter for that device, IIRC there is one 
available for android, I do not know about IOS



-- 
It's not hard to admit errors that are [only] cosmetically wrong.
-- J.K. Galbraith
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: newbee

2014-08-13 Thread Mok-Kong Shen

Am 13.08.2014 13:55, schrieb alister:
[snip]

A related question: How could one write a Python program and
have it run on a mobile phone in general (independent of a PC)?

M. K. Shen
--
https://mail.python.org/mailman/listinfo/python-list


Re: newbee

2014-08-13 Thread alister
On Tue, 12 Aug 2014 19:57:14 -0400, Frank Scafidi wrote:

> I just acquired a Raspberry Pi and want to program in Python. I was a
> PL/1 programmer back in the 60's & 70's and Python is similar. I am
> struggling with some very fundamental things that I am not finding in
> the documentation. Can someone help me with the basics like how do I
> save a program I've written, reload it in Python, list the program once
> it's loaded? How do I edit a program? Are these command line functions?
> 
> Thanks Frank  style="font-family:georgia,serif;font-size:small;color:#3366ff">I just
> acquired a Raspberry Pi and want to program in Python. I was a PL/1
> programmer back in the 60's & 70's and Python is similar. I
> am struggling with some very fundamental things that I am not finding in
> the documentation. Can someone help me with the basics like how do I
> save a program I've written, reload it in Python, list the program
> once it's loaded? How do I edit a program? Are these command line
> functions? 
>  style="font-family:georgia,serif;font-size:small;color:#3366ff"> class="gmail_default"
> style="font-family:georgia,serif;font-size:small;color:#3366ff">Thanks class="gmail_default"
> style="font-family:georgia,serif;font-size:small;color:#3366ff">
> Frank style="font-family:georgia,serif;font-size:small;color:#3366ff">


I am not in the same league as many of the posters here when it comes to 
Python but fortunately i do have two Raspberry Pi's :-)

if you are running the Pi connected to a TV/Monitor with the Gui enabled 
then you should have access to Idle as well as a number of text editors 
(Geany works well if installed)

if you are using it from the commands line then as previously stated you 
need to use a text editor to write the code (Nano is part of the basic 
Raspian Distro and easier to use than VI/Vim)

once you have created your code file type python  at the 
command prompt

remember if you are connecting to the Pi remotely Via SSH it is useful to 
have multiple connections open, one for the text editor & 1 to enable you 
to run the code or execute other Linux commands.

If you have any more questions post them back &I hope I can help
(Maybe I can become useful to this group as the R-Pi expert, hopefully 
more productively than some of the groups other 'Experts')



-- 
Expect the worst, it's the least you can do.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: newbee

2014-08-13 Thread Duncan Booth
Peter Otten <__pete...@web.de> wrote:

> Frank Scafidi wrote:
> 
>> I just acquired a Raspberry Pi and want to program in Python. I was a
>> PL/1 programmer back in the 60's & 70's and Python is similar. I am
>> struggling with some very fundamental things that I am not finding in
>> the documentation. Can someone help me with the basics like how do I
>> save a program I've written, reload it in Python, list the program
>> once it's loaded? How do I edit a program? Are these command line
>> functions? 
> 
> You can use any text editor to write a python script. A simple editor
> which might be present ont the Pi is called "nano". It shows the
> hotkeys to store the text and quit the editor, and thus should be
> self-explanatory: 
> 
> $ nano helloworld.py
> 
> Once you have written your simple script you can look at it with the
> "cat" command:
> 
> $ cat helloworld.py 
> #!/usr/bin/env python
> print "Hello world"
> 
> Invoke it with:
> 
> $ python helloworld.py 
> Hello world
> 
> You can also make your script "executable" which means that the first
> line controls which program is used to run it:
> 
> $ chmod +x helloworld.py 
> $ ./helloworld.py 
> Hello world
> $
> 
> If the script is in a directory listed in the PATH environment
> variable you can omit the path (the "./" in the above example):
> 
> $ mv helloworld.py ~/bin
> $ helloworld.py 
> Hello world
> 
> PS: I ran the above demo on a Linux system, but not on the Raspberry
> Pi, so if something doesn't work as shown above it's probably due to
> the difference between the two systems.
> 

All of the above should work just fine on a Pi. The only thing I thing 
you could have added is that you also have the option of using Idle to 
edit and run Python programs. If you are running Raspian on your Pi then 
you will find an icon to run Idle sitting on the initial desktop. 
There's an introduction to using Idle on the Raspberry Pi at 
http://www.raspberrypi.org/documentation/usage/python/


-- 
Duncan Booth
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: newbee

2014-08-13 Thread Peter Otten
Frank Scafidi wrote:

> I just acquired a Raspberry Pi and want to program in Python. I was a PL/1
> programmer back in the 60's & 70's and Python is similar. I am struggling
> with some very fundamental things that I am not finding in the
> documentation. Can someone help me with the basics like how do I save a
> program I've written, reload it in Python, list the program once it's
> loaded? How do I edit a program? Are these command line functions?

You can use any text editor to write a python script. A simple editor which 
might be present ont the Pi is called "nano". It shows the hotkeys to store 
the text and quit the editor, and thus should be self-explanatory:

$ nano helloworld.py

Once you have written your simple script you can look at it with the "cat" 
command:

$ cat helloworld.py 
#!/usr/bin/env python
print "Hello world"

Invoke it with:

$ python helloworld.py 
Hello world

You can also make your script "executable" which means that the first line 
controls which program is used to run it:

$ chmod +x helloworld.py 
$ ./helloworld.py 
Hello world
$

If the script is in a directory listed in the PATH environment variable you 
can omit the path (the "./" in the above example):

$ mv helloworld.py ~/bin
$ helloworld.py 
Hello world

PS: I ran the above demo on a Linux system, but not on the Raspberry Pi, so 
if something doesn't work as shown above it's probably due to the difference 
between the two systems.


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: newbee

2014-08-13 Thread Chris Angelico
On Wed, Aug 13, 2014 at 9:57 AM, Frank Scafidi  wrote:
> I just acquired a Raspberry Pi and want to program in Python. I was a PL/1
> programmer back in the 60's & 70's and Python is similar. I am struggling
> with some very fundamental things that I am not finding in the
> documentation. Can someone help me with the basics like how do I save a
> program I've written, reload it in Python, list the program once it's
> loaded? How do I edit a program? Are these command line functions?

These sound like RPi questions, rather than Python questions. You may
find knowledgeable people here on this list, but if not, I would
advise hunting down an RPi mailing list or newsgroup and asking there.
Most of us here use full computers, where questions like "how do I
save a file?" are trivially easy... you may find, actually, that
starting on a PC and then pushing the file to the RPi is the easiest
way to work.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: newbee

2014-08-13 Thread Joel Goldstick
On Tue, Aug 12, 2014 at 7:57 PM, Frank Scafidi  wrote:
> I just acquired a Raspberry Pi and want to program in Python. I was a PL/1
> programmer back in the 60's & 70's and Python is similar. I am struggling
> with some very fundamental things that I am not finding in the
> documentation. Can someone help me with the basics like how do I save a
> program I've written, reload it in Python, list the program once it's
> loaded? How do I edit a program? Are these command line functions?

I've not worked with Rasberry Pi, but it has some kind of linux on it.
So find a text editor (maybe vim is on it).


Write your code with text editor and save.

To run it type:

python my_program.py

See python.org website and read the tutorial
>
> Thanks
> Frank
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Newbee question about running a script

2013-01-06 Thread Miki Tebeka
On Sunday, January 6, 2013 8:03:43 AM UTC-8, marc.assin wrote:
> I wonder how I could specify a parameter on the command line from
> within the interpreter.
Guido wrote some advice a while back - 
http://www.artima.com/weblogs/viewpost.jsp?thread=4829

Import your module and call its main.

The other way is to execute in another process:
from subprocess import check_call
import sys
check_call([sys.executable, 'myscript.py', 'arg1', 'arg2'])
-- 
http://mail.python.org/mailman/listinfo/python-list



Re: newbee: Simple Backend Python Script Question

2007-09-14 Thread Steve Holden
joe shoemaker wrote:
> I need to create python script that is threaded. So the main program 
> will run in infinite loop and just retrieving messages and putting them 
> in a queue. (Main thread)
> 
> I need child threads from a pool to process the queue. When there is no 
> stuff in the queue, they go to the pool and become available but they 
> don't terminate. This has to be done continuously.
> 
> Main program need to keep putting stuff in the queue, when there are no 
> messages, then it sleeps for short time and check back to see any messages.
> 
> To do this, I guess you don't write joinAll(), so that the main threads 
> just don't wait for the child but goes to work.
> 
> am I right?
> 
Pretty much. The way I usually do this is to start a number of threads 
reading work items of some sort from a Queue.Queue. The thread will 
block automatically if there's nothing on the queue, resuming when 
something appears (and if I want orderly termination I use None as a 
dummy work unit, and the threads terminate when they receive a None, but 
any sentinel value would do).

> Also, child threads (a function that is threaded) will make connecitons 
> to the database. I am planning to use threadpool, so that threads reuse 
> the connections. So do you close the database connection at the end of 
> the function? If not then the connection will be opened forever?
> 
You don't want a thread pool, you want a connection pool, but there's 
little advantage to having one that is only shared between your threads. 
You really need a system-wide connection pool. Alternatively, you might 
find that your database module is thread-safe to the extent that 
different threads can use cursors created on the same connection without 
interference.

If you want each thread to be able to process transactions that are 
invisible to the other threads before they are committed you should 
ensure that you have a sufficient isolation level, which might imply the 
need for a connection-per-thread architecture, in which case you might 
expect some benefit from connection pooling.

regards
  Steve

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee Question

2007-08-21 Thread Dave Hansen
On Aug 21, 2:57 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
[...]
>
> pay = min(num, 22) * 0.4 + max(num-22, 0) * 1.4

   pay = num*0.4 + (num>22)*(num-22)

;-)

   -=Dave

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee Question

2007-08-21 Thread sentientholon
On Aug 21, 11:52 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> I tryed your code and got an error message #I use Wing IDE:
> Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)]
> Type "help", "copyright", "credits" or "license" for more information.
>
> Evaluating lines 1-16 from truckStops.py
> :7: Warning: 'yield' will become a reserved keyword in the
> future
> Could not execute because an error occurred:
>   invalid syntax: , line 7, pos 19:
>   yield stops, wage

Python 2.2.3 is three versions behind.  Generators only work in 2.2 by
saying:

from __future__ import generators

And by default in anything from 2.3 on.

Fred

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee Question

2007-08-21 Thread [EMAIL PROTECTED]
On Aug 21, 4:38 am, Ant <[EMAIL PROTECTED]> wrote:
> On Aug 20, 11:47 pm, [EMAIL PROTECTED] wrote:
> ...
>
> > Thanks for the help. By the way I am trying to learn the python after
> > work and on weekends. If it was a dumb question, to this group, I will
> > not bother you all again.
>
> It's not so much that it was a dumb question, but that it was asked in
> a dumb way :-) You'll get the most help in this group if you can show
> some evidence that you've had a go (the size of this thread ironically
> trounces that argument of course ;-) .)
>
> It's better to learn if people give you a critique of your own attempt
> at the code, rather than looking at other peoples efforts. There's a
> guide on how to ask good questions 
> here:http://www.catb.org/~esr/faqs/smart-questions.html
>
> For what it's worth, here's a gratuitous version using generators, and
> one you should come back to once you've mastered the basics of Python:
>
> def counter(std_rate, over_rate, limit):
> stops = 0
> while True:
> stops += 1
> wage = stops * std_rate + max(0, stops - limit) * (over_rate -
> std_rate)
> yield stops, wage
>
> truck = counter(0.4, 1.4, 22)
>
> for i in range(30):
> print "Stopped %s times, with accumulated wage of $%s" %
> truck.next()
>
> --
> Ant...
>
> http://antroy.blogspot.com/
I tryed your code and got an error message #I use Wing IDE:
Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)]
Type "help", "copyright", "credits" or "license" for more information.
>>>
Evaluating lines 1-16 from truckStops.py
:7: Warning: 'yield' will become a reserved keyword in the
future
Could not execute because an error occurred:
  invalid syntax: , line 7, pos 19:
  yield stops, wage

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee Question

2007-08-21 Thread Steve Holden
[EMAIL PROTECTED] wrote:
[...]
> 
> Thanks for the help. By the way I am trying to learn the python after
> work and on weekends. If it was a dumb question, to this group, I will
> not bother you all again.
> Without help it will take me longer to learn. Thanks
> 
Don't worry about it. There is also a list specifically for learners, 
which you can find out about at

   http://mail.python.org/mailman/listinfo/tutor

Welcome to the Python community!

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee Question

2007-08-21 Thread Ant
On Aug 20, 11:47 pm, [EMAIL PROTECTED] wrote:
...
> Thanks for the help. By the way I am trying to learn the python after
> work and on weekends. If it was a dumb question, to this group, I will
> not bother you all again.

It's not so much that it was a dumb question, but that it was asked in
a dumb way :-) You'll get the most help in this group if you can show
some evidence that you've had a go (the size of this thread ironically
trounces that argument of course ;-) .)

It's better to learn if people give you a critique of your own attempt
at the code, rather than looking at other peoples efforts. There's a
guide on how to ask good questions here: 
http://www.catb.org/~esr/faqs/smart-questions.html

For what it's worth, here's a gratuitous version using generators, and
one you should come back to once you've mastered the basics of Python:

def counter(std_rate, over_rate, limit):
stops = 0
while True:
stops += 1
wage = stops * std_rate + max(0, stops - limit) * (over_rate -
std_rate)
yield stops, wage

truck = counter(0.4, 1.4, 22)

for i in range(30):
print "Stopped %s times, with accumulated wage of $%s" %
truck.next()

--
Ant...

http://antroy.blogspot.com/


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee Question

2007-08-21 Thread Asun Friere
On Aug 21, 5:51 pm, Asun Friere <[EMAIL PROTECTED]> wrote:
> On Aug 21, 5:41 pm, Asun Friere <[EMAIL PROTECTED]> wrote:> over = 
> Decimal('1.40)
>
> oops, that should of course be:
> over = Decimal('1.40')

oh boy ... and it should also be
normal = Decimal('0.40')

I really need to test before posting ...

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee Question

2007-08-21 Thread Asun Friere
On Aug 21, 5:41 pm, Asun Friere <[EMAIL PROTECTED]> wrote:
> over = Decimal('1.40)
oops, that should of course be:
over = Decimal('1.40')

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee Question

2007-08-21 Thread Asun Friere
Oh well since a few solutions have already been posted I thought I
might add another, just so you at the very least you have to do some
work making up your mind which one to choose.  Using an incremental
approach just to be different ...

from decimal import Decimal

normal = Decimal('0.04')
over = Decimal('1.40)

def calcStopPay (stops) :
pay = Decimal('0.00')
while stops :
incr = normal if stops < 23 else over
pay += incr
stops -= 1
return pay

#testing:
for x in range(50) :
print "Stop pay for %s stops: $%s" % (x, calcStopPay(x))

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee Question

2007-08-20 Thread James Stroud
[EMAIL PROTECTED] wrote:
> On Aug 20, 11:06 am, [EMAIL PROTECTED] wrote:
> 
>>On Aug 20, 9:58 am, "Shawn Milochik" <[EMAIL PROTECTED]> wrote:
>>
>>
>>
>>
>>
>>
>>>On 8/20/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>>
On Aug 20, 9:23 am, "HD1956" <[EMAIL PROTECTED]> wrote:

>This is probably a simple code. I am a truck driver who gets paid by
>stops and cases. I am trying to figure out how to code my stop pay. I
>get 40 cents per stop up to 22 stops, and $1.40 per stops after that.
>>
def calc(num):
if num < 23:
return 0.4 * num
else:
overtime = num - 22
x = 0.4 * 22
x += overtime * 1.4
return x
>>
# Use your own brain next time
>>
Mike
>>
--
http://mail.python.org/mailman/listinfo/python-list
>>
>>>Mike,
>>
>>>I wonder if we were both just duped into helping someone with their 
>>>homework...
>>
>>>Shawn
>>
>>I like to write code, so it's not a big deal when it's something so
>>simple. Still, that is beyond dumb! Nice code, by the way.
>>
>>Mike- Hide quoted text -
>>
>>- Show quoted text -
> 
> 
> Thanks for the help. By the way I am trying to learn the python after
> work and on weekends. If it was a dumb question, to this group, I will
> not bother you all again.
> Without help it will take me longer to learn. Thanks
> 

Throw out an example of what you tried with an error message and/or 
unexpected results. Ask particulars--this will keep you from giving 
truck drivers a bad name.

Sticking-my-fist-out-window-and-making-pulling-down-gesture-ly yours,

James



-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee Question

2007-08-20 Thread hd1956
On Aug 20, 11:06 am, [EMAIL PROTECTED] wrote:
> On Aug 20, 9:58 am, "Shawn Milochik" <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > On 8/20/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > > On Aug 20, 9:23 am, "HD1956" <[EMAIL PROTECTED]> wrote:
> > > > This is probably a simple code. I am a truck driver who gets paid by
> > > > stops and cases. I am trying to figure out how to code my stop pay. I
> > > > get 40 cents per stop up to 22 stops, and $1.40 per stops after that.
>
> > > def calc(num):
> > > if num < 23:
> > > return 0.4 * num
> > > else:
> > > overtime = num - 22
> > > x = 0.4 * 22
> > > x += overtime * 1.4
> > > return x
>
> > > # Use your own brain next time
>
> > > Mike
>
> > > --
> > >http://mail.python.org/mailman/listinfo/python-list
>
> > Mike,
>
> > I wonder if we were both just duped into helping someone with their 
> > homework...
>
> > Shawn
>
> I like to write code, so it's not a big deal when it's something so
> simple. Still, that is beyond dumb! Nice code, by the way.
>
> Mike- Hide quoted text -
>
> - Show quoted text -

Thanks for the help. By the way I am trying to learn the python after
work and on weekends. If it was a dumb question, to this group, I will
not bother you all again.
Without help it will take me longer to learn. Thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee Question

2007-08-20 Thread Neil Cerutti
On 2007-08-20, HD1956 <[EMAIL PROTECTED]> wrote:
> This is probably a simple code. I am a truck driver who gets
> paid by stops and cases. I am trying to figure out how to code
> my stop pay. I get 40 cents per stop up to 22 stops, and $1.40
> per stops after that. 

I wish *I* could make a deal like that. I stop working all the
time!

-- 
Neil Cerutti
Customers who consider our waitresses uncivil ought to see the manager --sign
at New York restaurant
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee Question

2007-08-20 Thread Paul McGuire
On Aug 20, 9:23 am, "HD1956" <[EMAIL PROTECTED]> wrote:
> This is probably a simple code. I am a truck driver who gets paid by
> stops and cases. I am trying to figure out how to code my stop pay. I
> get 40 cents per stop up to 22 stops, and $1.40 per stops after that.

You'll get top marks for turning in the shortest program!

norm = 0.4
ot = 1.4-norm
otStart = 22
calcPay = lambda stops : norm*stops+ot*max(stops-otStart,0)

-- Paul

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee Question

2007-08-20 Thread Wildemar Wildenburger
Diez B. Roggisch wrote:
> Sounds a bit like homework. Which usually isn't simply delivered here.
>
>   
Wrong! Usually that happens pretty quickly here (as proven again in this 
case). Not that it should, but only the seniors seem to detect lazy 
learners.

/W
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee Question

2007-08-20 Thread Shawn Milochik
> I like to write code, so it's not a big deal when it's something so
> simple. Still, that is beyond dumb! Nice code, by the way.
>
> Mike

Yeah, it was fun to write anyway. Thanks for the compliment on the
code. I still consider myself a Python newbie, so it's good to know
I'm not trying to write it like Perl or VBScript anymore. ^_^

Shawn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee Question

2007-08-20 Thread kyosohma
On Aug 20, 9:58 am, "Shawn Milochik" <[EMAIL PROTECTED]> wrote:
> On 8/20/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Aug 20, 9:23 am, "HD1956" <[EMAIL PROTECTED]> wrote:
> > > This is probably a simple code. I am a truck driver who gets paid by
> > > stops and cases. I am trying to figure out how to code my stop pay. I
> > > get 40 cents per stop up to 22 stops, and $1.40 per stops after that.
>
> > def calc(num):
> > if num < 23:
> > return 0.4 * num
> > else:
> > overtime = num - 22
> > x = 0.4 * 22
> > x += overtime * 1.4
> > return x
>
> > # Use your own brain next time
>
> > Mike
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> Mike,
>
> I wonder if we were both just duped into helping someone with their 
> homework...
>
> Shawn

I like to write code, so it's not a big deal when it's something so
simple. Still, that is beyond dumb! Nice code, by the way.

Mike

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee Question

2007-08-20 Thread Diez B. Roggisch
HD1956 schrieb:
> This is probably a simple code. I am a truck driver who gets paid by 
> stops and cases. I am trying to figure out how to code my stop pay. I 
> get 40 cents per stop up to 22 stops, and $1.40 per stops after that. 
> 

Sounds a bit like homework. Which usually isn't simply delivered here.

Can you show us some code you worked on, then we might suggest enhancements.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee Question

2007-08-20 Thread Shawn Milochik
On 8/20/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> On Aug 20, 9:23 am, "HD1956" <[EMAIL PROTECTED]> wrote:
> > This is probably a simple code. I am a truck driver who gets paid by
> > stops and cases. I am trying to figure out how to code my stop pay. I
> > get 40 cents per stop up to 22 stops, and $1.40 per stops after that.
>
> def calc(num):
> if num < 23:
> return 0.4 * num
> else:
> overtime = num - 22
> x = 0.4 * 22
> x += overtime * 1.4
> return x
>
> # Use your own brain next time
>
> Mike
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>




Mike,

I wonder if we were both just duped into helping someone with their homework...

Shawn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee Question

2007-08-20 Thread Shawn Milochik
#!/usr/bin/env python

normalPay = 0.4
overPay = 1.4
normalLimit = 22

def calcPay(numStops):

pay = 0

if numStops > normalLimit:
pay = overPay * (numStops - normalLimit)
numStops = normalLimit

return pay + (numStops * normalPay)

if __name__ == "__main__":

print "Pay for 1 stops: %.2f." % calcPay(1)
print "Pay for 10 stops: %.2f." % calcPay(10)
print "Pay for 17 stops: %.2f." % calcPay(17)
print "Pay for 25 stops: %.2f." % calcPay(25)
print "Pay for 30 stops: %.2f." % calcPay(30)
print "Pay for 31 stops: %.2f." % calcPay(31)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee Question

2007-08-20 Thread kyosohma
On Aug 20, 9:23 am, "HD1956" <[EMAIL PROTECTED]> wrote:
> This is probably a simple code. I am a truck driver who gets paid by
> stops and cases. I am trying to figure out how to code my stop pay. I
> get 40 cents per stop up to 22 stops, and $1.40 per stops after that.

def calc(num):
if num < 23:
return 0.4 * num
else:
overtime = num - 22
x = 0.4 * 22
x += overtime * 1.4
return x

# Use your own brain next time

Mike

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbee I have an object how to check what's his class?

2006-11-10 Thread Gabriel Genellina

At Friday 10/11/2006 18:05, consternation wrote:


def __init__
 self.mem={}
I googled a way how  to add elements to dict,  I have read the code not the
description below


self.mem[key] = value

I strongly suggest you read some introductory Python docs, like 
http://docs.python.org/tut/tut.html or http://www.diveintopython.org



isinstance(x,X)
True:-)
type(x) is X
False:( ??
__main__.X
X
 temporarily it solves my probblems I'm just curious why type can't handle
the test.


You still didn't show enough code, but I bet that X is an old-style 
class, that is, you wrote:

class X: blablabla
instead of
class X(object): blablabla
For old-style class instances, type(x) is InstanceType, not the actual class.


--
Gabriel Genellina
Softlab SRL 


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: newbee I have an object how to check what's his class?

2006-11-10 Thread consternation

I think I know now where my problems come from. I spare you boring 
implementation code.
The case look like this: I parse xml file something a like
 
1   <\a>
 2  <\a>


3 <\a>
 4<\b>
<\X>



   <\a>
   <\a>


 <\a>
 <\b>
<\X>

I  succesfully constructlop-level X objects - I see all components when i 
print X0, X1 out with _repr_.
I store my X's in memory. I had some problems with this. I googled, red 
newsgoup ad foud a solution that seemd to be perfect for me (...till now). 
In the parser- Y class a have a dictionary
def __init__
 self.mem={}
I googled a way how  to add elements to dict,  I have read the code not the 
description below
##copied from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66516
   def addItem(self,word,pagenumber):
self.mem.setdefault(word,[]).append(pagenumber)
   
So my dict looks like{
(id of top-level X)  0 :  (the X itself) X0,
2 :X2,
4..
}
I wrote it some time and I was tired I haven't pay attention to  the 
breackets at he beginning of outprint
TOP LEVEL X WITH ID=0
[ <
1<\a>
2<\a>

3<\a>
 4<\a>
   <\class  X>
<\class  X>]
One can clearly see it's a list :( Shame on me.
I did a trick. If my X object is stored in a list and it's the only element 
of the list I can simply use it like:
print v[0]
print" isinstance(x,X)"
print isinstance(v[0],X)
print "type(x) is X"
print type(v[0]) is X
print v[0].__class__
print v[0].__class__.__name__
and results
 
2<\a>

3<\a>
 4<\a>
   <\class  X>
<\class  X>

isinstance(x,X)
True:-)
type(x) is X
False:( ??
__main__.X
X
 temporarily it solves my probblems I'm just curious why type can't handle 
the test.
Thank you for help, and making me think :-) 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbee I have an object how to check what's his class?

2006-11-10 Thread Jerry Hill
On 11/10/06, consternation <[EMAIL PROTECTED]> wrote:
result:isinstance(x,X)Falsetype(x) is XFalselistI think you need to show us more of your code.  Your variable, v, is not of type X in this example.  Instead, it is of type list.  What is 
self.mem.items()?  It isn't a dictionary like your comment seems to imply, or you would get a TypeError on that line because dictionaries aren't callable.Please give us enough sample code that we can actually run it and see what you're seeing.
-- Jerry
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: newbee I have an object how to check what's his class?

2006-11-10 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, consternation wrote:

> Thank You for reply but 
> I found solution suggested by You in a tutorial yesterday. For some reason
> it doesn't work in my case.
> 
> code:
> #mem-dictionary in Y class for storing objects
> #Y doesn't inherit from X
>   for (i,v) in self.mem.items(): 
>   print " isinstance(x,X)"
>   print  isinstance(v,X)
>   print "type(x) is X"
>   print type(v) is X
>   print v.__class__.__name__
>   print v.__class__
> 
> result:
> isinstance(x,X)
> False
> type(x) is X
> False
> 
> list

Define "doesn't work".  Obviously lists are not instances of your `X`
class.  So where's the problem?  What did you expect and why?

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbee I have an object how to check what's his class?

2006-11-10 Thread consternation
Thank You for reply but 
I found solution suggested by You in a tutorial yesterday. For some reason
it doesn't work in my case.

code:
#mem-dictionary in Y class for storing objects
#Y doesn't inherit from X
  for (i,v) in self.mem.items(): 
  print " isinstance(x,X)"
  print  isinstance(v,X)
  print "type(x) is X"
  print type(v) is X
  print v.__class__.__name__
  print v.__class__

result:
isinstance(x,X)
False
type(x) is X
False

list

Well I can handle my problem. I will give an extra field in class with it's
name. But I thought that when a language has tools to learn a class of an
object one should use it. 


[EMAIL PROTECTED] wrote:

> This doesn't answer your whole post because it asked a lot of
> questions. But as to finding out whether something is an instance of a
> class:
> 
> class X(object):
>   # ... defined as in your post
> 
 x = X('Fred')
 x
> class X contains:
 type(x) is X
> True
 isinstance(x,X)
> True
 x.__class__.__name__
> 'X'
> 
> Now for subclasses:
> 
> class Y(X):
> extrastuffinY = 1
> 
 y = Y('Joe')
 type(y) is X
> False
 isinstance(y,X)
> True
> 
> 
> consternation:
> 
>> I can't find  neither in tutorial nor with google It's all about
>> isinstance,  or  __class__.
>> How to test that an object is an instance of my X class??

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbee I have an object how to check what's his class?

2006-11-10 Thread paul . keating
This doesn't answer your whole post because it asked a lot of
questions. But as to finding out whether something is an instance of a
class:

class X(object):
  # ... defined as in your post

>>> x = X('Fred')
>>> x
class X contains:
>>> type(x) is X
True
>>> isinstance(x,X)
True
>>> x.__class__.__name__
'X'

Now for subclasses:

class Y(X):
extrastuffinY = 1

>>> y = Y('Joe')
>>> type(y) is X
False
>>> isinstance(y,X)
True


consternation:

> I can't find  neither in tutorial nor with google It's all about
> isinstance,  or  __class__.
> How to test that an object is an instance of my X class??

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbee question : List of packages

2005-06-01 Thread Simon Brunning
On 6/1/05, Sébastien V. <[EMAIL PROTECTED]> wrote:
> I'm quite new in Python and I discover every day very interesting new
> packages in this newsgroup : Is there somewhere on the web a list (as
> complete as possible) in which main features of external packages are listed

Try , or the (older)
.

That said, these days I usually just google for whatever I'm looking for.

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list