Re: [Tutor] Question about subprocess

2014-01-11 Thread eryksun
On Sat, Jan 11, 2014 at 12:46 AM, Danny Yoo d...@hashcollision.org wrote:
 There is a warning in the documentation on subprocess that might be
 relevant to your situation:

 Warning:
 Use communicate() rather than .stdin.write, .stdout.read or
 .stderr.read to avoid deadlocks due to any of the other OS pipe
 buffers filling up and blocking the child process.

 Reference: http://docs.python.org/2/library/subprocess.html

 It's possible that the process is deadlocking due to this situation.
 Do you run into this issue if you use communicate()?

If more than one standard file is piped (not the case for the OP),
`communicate` avoids deadlocks by using `poll` or `select` on POSIX.
On Windows, it uses the current thread to write to stdin and uses
separate threads to read from stdout and stderr.

If only one standard file is piped, then there's no deadlock. It's
just blocked while waiting for the buffer to fill. `communicate` does
nothing special in this case (at least prior to 3.3):

http://hg.python.org/cpython/file/3a1db0d2747e/Lib/subprocess.py#l767

In 3.3, the new `timeout` option for `communicate` also uses the
select/thread implementation.

stdout FILE stream buffering could be a problem if output is
intermittent and the program doesn't `fflush` the buffer. On Linux the
`stdbuf` program may be able to circumvent this. It injects code (i.e.
libstdbuf.so is added to LD_PRELOAD) that calls `setvbuf` before the
target's `main` runs. This allows you to set the stream to line
buffering mode (unless the program itself calls `setvbuf`). I don't
think a similar utility exists on Windows.

http://linux.die.net/man/1/stdbuf
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question about subprocess

2014-01-11 Thread eryksun
On Sat, Jan 11, 2014 at 12:51 AM, Steven D'Aprano st...@pearwood.info wrote:

 However, when I writed it into a .py file and execute the .py file, it
 blocked at temp=p.readline().

 Of course it does. You haven't actually called the .exe file, all you
 have done is created a Popen instance and then grabbed a reference to
 it's stdout. Then you sit and wait for stdout to contain data, which it
 never does.

Popen.__init__ calls Popen._execute_child, which on Windows is defined
to call _subprocess.CreateProcess. So the issue can't be that the OP
hasn't called the .exe.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question about subprocess

2014-01-11 Thread eryksun
On Fri, Jan 10, 2014 at 11:48 PM, daedae11 daeda...@126.com wrote:
 p = subprocess.Popen(['E:/EntTools/360EntSignHelper.exe',
 'E:/build/temp/RemoteAssistSetup.exe'],
  stdout=subprocess.PIPE, shell=True).stdout

Is 360EntSignHelper supposed to run RemoteAssistSetup as a child
process? Or rather is it that from the command line you're piping the
output from the former into the latter? You'll need to provide more
information about what you mean by running the code in command line.

Some general suggestions:

Remove shell=True. There's no reason to involve the shell here.
subprocess hides the window when you use shell=True, so maybe that's
why you're using it. But you can do that by setting the startupinfo
parameter to the following:

si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
si.wShowWindow = subprocess.SW_HIDE

Also, as a matter of style, `p` is a bad name for stdout. It's not an
instance of [P]open representing a process.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question about subprocess

2014-01-11 Thread Steven D'Aprano
On Sat, Jan 11, 2014 at 04:26:00AM -0500, eryksun wrote:
 On Sat, Jan 11, 2014 at 12:51 AM, Steven D'Aprano st...@pearwood.info wrote:
 
  However, when I writed it into a .py file and execute the .py file, it
  blocked at temp=p.readline().
 
  Of course it does. You haven't actually called the .exe file, all you
  have done is created a Popen instance and then grabbed a reference to
  it's stdout. Then you sit and wait for stdout to contain data, which it
  never does.
 
 Popen.__init__ calls Popen._execute_child, which on Windows is defined
 to call _subprocess.CreateProcess. So the issue can't be that the OP
 hasn't called the .exe.

Thanks for the correction.


-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Windows Install Issue

2014-01-11 Thread Matthew Ngaha
Hi I'm trying to install pyqt5.2 for Windows Vista (Python3.3). 1st i
need to install sip but i run into this issue.

after ./configure, a MAKEFILE is created. I'm supposed to do 'make'
and 'make install', but i get this cmd error:

C:\pathmake
'make' is not recognized as an internal or external command,
operable program or batch file.

I'm not really sure what i should do?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Windows Install Issue

2014-01-11 Thread Mark Lawrence

On 11/01/2014 14:08, Matthew Ngaha wrote:

Hi I'm trying to install pyqt5.2 for Windows Vista (Python3.3). 1st i
need to install sip but i run into this issue.

after ./configure, a MAKEFILE is created. I'm supposed to do 'make'
and 'make install', but i get this cmd error:

C:\pathmake
'make' is not recognized as an internal or external command,
operable program or batch file.

I'm not really sure what i should do?


On Windows finding a binary installer is always the first thing to do, 
makefiles indeed.  Go here 
http://www.riverbankcomputing.co.uk/software/pyqt/download5, find the 
section Binary Packages and this gives Windows 32 and 64 bit installers.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Windows Install Issue

2014-01-11 Thread Matthew Ngaha
On Sat, Jan 11, 2014 at 2:55 PM, Mark Lawrence breamore...@yahoo.co.uk wrote:

 On Windows finding a binary installer is always the first thing to do,
 makefiles indeed.  Go here
 http://www.riverbankcomputing.co.uk/software/pyqt/download5, find the
 section Binary Packages and this gives Windows 32 and 64 bit installers.

sorry i forgot to explain. i cant get the binary:
http://www.riverbankcomputing.co.uk/software/pyqt/download5

Unfortunately it is not possible to use both the PyQt4 and PyQt5
installers at the same time. If you wish to have both PyQt4 and PyQt5
installed at the same time you will need to build them yourself from
the source packages.

after seeing this i thought it was better not to try it and maybe
currupt my files
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Windows Install Issue

2014-01-11 Thread Mark Lawrence

On 11/01/2014 15:24, Matthew Ngaha wrote:

On Sat, Jan 11, 2014 at 2:55 PM, Mark Lawrence breamore...@yahoo.co.uk wrote:


On Windows finding a binary installer is always the first thing to do,
makefiles indeed.  Go here
http://www.riverbankcomputing.co.uk/software/pyqt/download5, find the
section Binary Packages and this gives Windows 32 and 64 bit installers.


sorry i forgot to explain. i cant get the binary:
http://www.riverbankcomputing.co.uk/software/pyqt/download5

Unfortunately it is not possible to use both the PyQt4 and PyQt5
installers at the same time. If you wish to have both PyQt4 and PyQt5
installed at the same time you will need to build them yourself from
the source packages.

after seeing this i thought it was better not to try it and maybe
currupt my files


http://stackoverflow.com/questions/16846501/how-to-install-pyqt5-on-windows

--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Question

2014-01-11 Thread wolfrage8...@gmail.com
 It will also be helpful if you tell us your OS and Python Version.
Can you also tell us if you are writing the code to a file and
executing, using IDLE or some other IDE, or are you using the
interpreter interactively?

On Fri, Jan 10, 2014 at 8:57 PM, Amy Davidson amydavid...@sympatico.ca wrote:
 Hey Danny,

 I just started taking the course (introduction to Computer Science) on last 
 Tuesday, so I am not to familiar. I have been doing my best to understand  
 the material by reading the text book, Learn Python the hard way.

 In my quest to answer the question given to me, I have searched the internet 
 high and low of other functions thus, I am familiar with the basic knowledge 
 of them (i.e. starting with def) as well as examples.

 We can attempt the approach to the method that you prefer.

 Thans for helping me, by the way.
 On Jan 10, 2014, at 5:25 PM, Danny Yoo d...@hashcollision.org wrote:

 On Fri, Jan 10, 2014 at 2:00 PM, Keith Winston keithw...@gmail.com wrote:
 Amy, judging from Danny's replies, you may be emailing him and not the
 list. If you want others to help, or to report on your progress,
 you'll need to make sure the tutor email is in your reply to:

 Hi Amy,

 Very much so.  Please try to use Reply to All if you can.

 If you're wondering why I'm asking for you to try to recall any other
 example function definitions, I'm doing so specifically because it is
 a general problem-solving technique.  Try to see if the problem that's
 stumping you is similar to things you've seen before.  Several of the
 heuristics from Polya's How to Solve It refer to this:

http://en.wikipedia.org/wiki/How_to_Solve_It

 If you haven't ever seen any function definition ever before, then we
 do have to start from square one.  But this would be a very strange
 scenario, to be asked to write a function definition without having
 seen any previous definitions before.

 If you have seen a function before, then one approach we might take is
 try to make analogies to those previous examples.  That's an approach
 I'd prefer.


 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Question

2014-01-11 Thread Amy Davidson
Hey!
So luckily with the texts that were sent to me, I was able to figure out the 
answer(yay)!

Unfortunately I am now stuck on a different question.

Write a function called highlight() that prompts the user for a string.
Your code should ensure that the string is all lower case.
Next, prompt the user for a smaller 'substring' of one or more characters. 
Then replace every occurrence of the substring in the first string with an 
upper case.
Finally, report to the user how many changes were made (i.e., how many 
occurrences of the substring there were).”
On Jan 11, 2014, at 1:04 AM, Alex Kleider aklei...@sonic.net wrote:

 On 2014-01-10 17:57, Amy Davidson wrote:
 Hey Danny,
 I just started taking the course (introduction to Computer Science) on
 last Tuesday, so I am not to familiar. I have been doing my best to
 understand  the material by reading the text book, Learn Python the
 hard way.
 
 A lot of people seem to think the Hard Way is the way to go.  I disagree.  
 I found that Allen Downey's book is excellent and free (although the book is 
 also available in 'real' print which works better for me.)
 
 http://www.greenteapress.com/thinkpython/
 
 My copy covers Python 2.7, you use Python 3 I believe, but I doubt that that 
 will be too much of a problem.  At the intro level the differences are few.
 
 ak
 
 In my quest to answer the question given to me, I have searched the
 internet high and low of other functions thus, I am familiar with the
 basic knowledge of them (i.e. starting with def) as well as examples.
 We can attempt the approach to the method that you prefer.
 Thans for helping me, by the way.
 On Jan 10, 2014, at 5:25 PM, Danny Yoo d...@hashcollision.org wrote:
 On Fri, Jan 10, 2014 at 2:00 PM, Keith Winston keithw...@gmail.com wrote:
 Amy, judging from Danny's replies, you may be emailing him and not the
 list. If you want others to help, or to report on your progress,
 you'll need to make sure the tutor email is in your reply to:
 Hi Amy,
 Very much so.  Please try to use Reply to All if you can.
 If you're wondering why I'm asking for you to try to recall any other
 example function definitions, I'm doing so specifically because it is
 a general problem-solving technique.  Try to see if the problem that's
 stumping you is similar to things you've seen before.  Several of the
 heuristics from Polya's How to Solve It refer to this:
   http://en.wikipedia.org/wiki/How_to_Solve_It
 If you haven't ever seen any function definition ever before, then we
 do have to start from square one.  But this would be a very strange
 scenario, to be asked to write a function definition without having
 seen any previous definitions before.
 If you have seen a function before, then one approach we might take is
 try to make analogies to those previous examples.  That's an approach
 I'd prefer.
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 https://mail.python.org/mailman/listinfo/tutor
 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help

2014-01-11 Thread Mark Lawrence

On 11/01/2014 14:52, S Tareq wrote:

how can i do this on python using py game:



No idea as what you've sent isn't readable when you try to reply. Also I 
can't see any code so sorry but I'm not doing your homework for you :(


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Question

2014-01-11 Thread bruce
hey amy..

ok.. before we jump to coding (and forgive me if what I'm about to
type is really basic!) let's play a bit with what's called
psuedo-code.

psuedo-code is a technique to kind of put your thoughts about a
problem/approach in a hash of code/english.. kind of lets you lay out
what you're trying to solve/program.

so for you issue:

you need to think about what you're trying to do.

you want to give the user back something, based on you doing something
to the thing the user gives you.

so this means, you need some way of getting user input
you want to do something to the input, so you need some way of
capturing the input to perform the something (better known as an
operation) on the user's input..

then you want to redisplay stuff back to the user, so you're going to
need a way of displaying back to the user the data/output..

create the psuedo-code, post it, and we'll get this in no time!



On Sat, Jan 11, 2014 at 12:23 PM, Amy Davidson amydavid...@sympatico.ca wrote:
 Hey!
 So luckily with the texts that were sent to me, I was able to figure out the
 answer(yay)!

 Unfortunately I am now stuck on a different question.

 Write a function called highlight() that prompts the user for a string.
 Your code should ensure that the string is all lower case.
 Next, prompt the user for a smaller 'substring' of one or more characters.
 Then replace every occurrence of the substring in the first string with an
 upper case.
 Finally, report to the user how many changes were made (i.e., how many
 occurrences of the substring there were).”
 On Jan 11, 2014, at 1:04 AM, Alex Kleider aklei...@sonic.net wrote:

 On 2014-01-10 17:57, Amy Davidson wrote:

 Hey Danny,
 I just started taking the course (introduction to Computer Science) on
 last Tuesday, so I am not to familiar. I have been doing my best to
 understand  the material by reading the text book, Learn Python the
 hard way.


 A lot of people seem to think the Hard Way is the way to go.  I disagree.
 I found that Allen Downey's book is excellent and free (although the book is
 also available in 'real' print which works better for me.)

 http://www.greenteapress.com/thinkpython/

 My copy covers Python 2.7, you use Python 3 I believe, but I doubt that that
 will be too much of a problem.  At the intro level the differences are few.

 ak

 In my quest to answer the question given to me, I have searched the
 internet high and low of other functions thus, I am familiar with the
 basic knowledge of them (i.e. starting with def) as well as examples.
 We can attempt the approach to the method that you prefer.
 Thans for helping me, by the way.
 On Jan 10, 2014, at 5:25 PM, Danny Yoo d...@hashcollision.org wrote:

 On Fri, Jan 10, 2014 at 2:00 PM, Keith Winston keithw...@gmail.com wrote:

 Amy, judging from Danny's replies, you may be emailing him and not the
 list. If you want others to help, or to report on your progress,
 you'll need to make sure the tutor email is in your reply to:

 Hi Amy,
 Very much so.  Please try to use Reply to All if you can.
 If you're wondering why I'm asking for you to try to recall any other
 example function definitions, I'm doing so specifically because it is
 a general problem-solving technique.  Try to see if the problem that's
 stumping you is similar to things you've seen before.  Several of the
 heuristics from Polya's How to Solve It refer to this:
   http://en.wikipedia.org/wiki/How_to_Solve_It
 If you haven't ever seen any function definition ever before, then we
 do have to start from square one.  But this would be a very strange
 scenario, to be asked to write a function definition without having
 seen any previous definitions before.
 If you have seen a function before, then one approach we might take is
 try to make analogies to those previous examples.  That's an approach
 I'd prefer.

 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 https://mail.python.org/mailman/listinfo/tutor




 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 https://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help

2014-01-11 Thread Walter Prins
Hi,


On 11 January 2014 14:52, S Tareq stare...@yahoo.com wrote:

 how can i do this on python using py game:


You need to tell us more about what you've tried and where you're stuck.
Needless to say we're not a solution provision service, but we'd be happy
to help you get unstuck if you've already done some programming and have
gotten to a point where you're actually stuck.  :)

For the reference of others, I've managed to track down the full task
description here:
http://www.kirkbiekendal.cumbria.sch.uk/index.php/public-documents/school/general-information?download=339:2014-component-1-gaming-scenario-candidate-booklet

As this is therefore clearly homework that you'll be handing in, please
note we absolutely cannot provide you with concrete solutions to this
assignment.

As to your reference to PyGame -- I'd like to gently suggest that perhaps
you should not worry about PyGame if you're just starting out.  You can get
started without it and build a more basic solution first (maybe just simple
text mode) and then deal with whether you want to enhance/modify your
solution to use PyGame at some later time.

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] python query

2014-01-11 Thread Reuben
Hi All,

I would like to know the difference between GUI programming v/s web
designing...To be more specific lets compare Django(used for web
programming) v/s Tkinter(used for GUI programming)


I wish to have a more clear difference regarding this.

Regards,
Reuben
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python query

2014-01-11 Thread Alan Gauld

On 11/01/14 18:53, Reuben wrote:


I would like to know the difference between GUI programming v/s web
designing...To be more specific lets compare Django(used for web
programming) v/s Tkinter(used for GUI programming)


What do you mean by the difference in programming? Do you want to know 
about the programming paradigms or the difference in deployment or the 
difference in the nature of the apps (I hope you already understand that 
but maybe not...)


Django is on the web so all the interactions take place over a network. 
The UI is displayed in a browser which interprets HTML sent from the 
server. Because of the relatively long latency between client and server 
web apps tend to be slower and less responsive than
desktop apps. To get round that they tend to cram more into a single 
screen. More modern apps also move a lot of functionality into 
Javascript on the browser and rely on lightweight protocols like JSON to 
fetch data from the server(this is known as Ajax style programming)


Tkinter is a desktop GUI toolkit where the application responds to users 
events and draws pictures(widgets) on the screen. All logic
and display happens locally, although some apps communicate with a 
server somewhere (this is called client server design).


OK, That's a start, what specifically do you want beyond that?

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 115, Issue 28

2014-01-11 Thread Alan Gauld

On 12/01/14 00:17, Jerry Val wrote:

I am trying to perfect myself in creating functions and looping, am
using python 3,can you help me with a few basic tips so i can create my
own functions and loops without making random mistakes?!


Please set a meaningful subject line, it makes finding posts in the 
archive much easier.


Also do not send the full digest content.
a) Most folks have already received the messages and don't want to see 
them, again
b) some folks pay for their bandwidth and don't want to pay for stuff 
they don't need
c) it obscures your message. Always cut it down to the lines that are 
pertinent. That way you are more likely to get sensible answers.


And for bonus points put your question after the cited context. Most 
readers prefer that to so called top posting.


As to your question. The best advice is to read what you type
carefully.
And know what you are trying to do before you type it.
In other words, think about the design of your code don't
just type randomly. That way you are less likely to
get random errors.

Other than that we will need some more specifics about what kind of 
errors you are getting. Usually most folks make the same kind of errors 
over and over. But the kind varies by individual. So until we know your 
style we can't help much.


HTH,
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Basic tips - was Re: Tutor Digest, Vol 115, Issue 28

2014-01-11 Thread Mark Lawrence

On 12/01/2014 00:17, Jerry Val wrote:

I am trying to perfect myself in creating functions and looping, am
using python 3,can you help me with a few basic tips so i can create my
own functions and loops without making random mistakes?!



IMHO the most important thing is to try your code snippets at the 
interactive prompt.  The second most important thing to get help here is 
*NOT* to reply to a four month old digest without changing the title, 
and worse still sending the whole completely irrelevant contents.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 115, Issue 28

2014-01-11 Thread Jerry Val
I am trying to perfect myself in creating functions and looping, am using
python 3,can you help me with a few basic tips so i can create my own
functions and loops without making random mistakes?!
 On Sep 12, 2013 11:19 PM, tutor-requ...@python.org wrote:

 Send Tutor mailing list submissions to
 tutor@python.org

 To subscribe or unsubscribe via the World Wide Web, visit
 https://mail.python.org/mailman/listinfo/tutor
 or, via email, send a message with subject or body 'help' to
 tutor-requ...@python.org

 You can reach the person managing the list at
 tutor-ow...@python.org

 When replying, please edit your Subject line so it is more specific
 than Re: Contents of Tutor digest...


 Today's Topics:

1. Re: class data member and objects of class in python
   (Felix Dietrich)
2. Re: class data member and objects of class in python (zubair alam)
3. Re: class data member and objects of class in python (Alan Gauld)
4. Re: Tutor Digest, Vol 115, Issue 27 (Dino Bekte?evi?)
5. Re: class data member and objects of class in python (Dave Angel)


 --

 Message: 1
 Date: Thu, 12 Sep 2013 02:59:51 +0200
 From: Felix Dietrich felix.dietr...@sperrhaken.name
 To: tutor@python.org
 Subject: Re: [Tutor] class data member and objects of class in python
 Message-ID: 87hadqx3aw@sperrhaken.name
 Content-Type: text/plain

  i am learning how a __class__ data member behaves in python as
  compared to static data member in java [...]

 The error is not related to class variables. Also could you elaborate on
 what you intended to find out with this snippet?

  class PizzaShop():
  pizza_stock = 10
 
  def get_pizza(self):
  while not PizzaShop.pizza_stock:
  PizzaShop.pizza_stock -= 1
  yield take yours pizza order, total pizzas left
 {}.format(PizzaShop.pizza_stock)

 The condition in the while loop is wrong. bool(PizzaShop.pizza_stock) is
 True for all values but 0. (All numbers but 0 are considered True.) The
 while loop does its commands while the condition holds True. When you do

 not PizzaShop.pizza_stock

 it will return False for values other than 0, therefor the loop is never
 run and on exit of get_pizza it raises StopIteration to indicate that
 there are no more values to be yielded.

  mypizza_shop = PizzaShop()
  pizza_order = mypizza_shop.get_pizza() # iterator is obtained
  print a pizza pls!! {}:.format(pizza_order.next())
  print a pizza pls!! {}:.format(pizza_order.next())

 You might want to catch StopIteration here so that you can handle the
 case that the shop runs out of the initial stack of pizzas. ;)

 --
 Felix Dietrich


 --

 Message: 2
 Date: Thu, 12 Sep 2013 14:40:08 +0530
 From: zubair alam zubair.alam@gmail.com
 To: Marc Tompkins marc.tompk...@gmail.com
 Cc: tutor tutor@python.org
 Subject: Re: [Tutor] class data member and objects of class in python
 Message-ID:
 
 cagqec76+un1_+yw3uc78f10nj8uszdpgtd90jnbkuxpo2ba...@mail.gmail.com
 Content-Type: text/plain; charset=iso-8859-1

 class PizzaShop():
 pizza_stock = 10
 def get_pizza(self):
 while PizzaShop.pizza_stock:
 PizzaShop.pizza_stock -= 1
 yield take yours pizza order, total pizzas left
 {}.format(PizzaShop.pizza_stock)

 mypizza_shop = PizzaShop()
 pizza_order = mypizza_shop.get_pizza()
 # print {}.format(repr(pizza_order.next()))

 for order in pizza_order:
 print {}.format(repr(order))

 domino_pizza_store = mypizza_shop.get_pizza()
 print {}.format(repr(domino_pizza_store.next()))

 mypizza_shop.pizza_stock = 10

 domino_pizza_store = mypizza_shop.get_pizza()
 print {}.format(repr(domino_pizza_store.next()))


 can't we again use the same object mypizza_shop once its generator is
 exhausted


 On Thu, Sep 12, 2013 at 6:53 AM, Marc Tompkins marc.tompk...@gmail.com
 wrote:

  On Wed, Sep 11, 2013 at 5:40 AM, zubair alam zubair.alam@gmail.com
 wrote:
 
  i am learning how a __class__ data member behaves in python as compared
  to static data member in java, but following code is throwing error
 
 
  class PizzaShop():
  pizza_stock = 10
  def get_pizza(self):
  while not PizzaShop.pizza_stock:
  PizzaShop.pizza_stock -= 1
  yield take yours pizza order, total pizzas left
  {}.format(PizzaShop.pizza_stock)
 
  mypizza_shop = PizzaShop()
  pizza_order = mypizza_shop.get_pizza() # iterator is obtained
  print a pizza pls!! {}:.format(pizza_order.next())
  print a pizza pls!! {}:.format(pizza_order.next())
 
  output:
  Traceback (most recent call last):
File /home/scott/pythonfiles/core_python/pizza.py, line 10, in
  module
  print a pizza pls!! {}:.format(pizza_order.next())
  StopIteration
 
 
  don't know where i am doing mistakeany help will be appreciated... i
  have other questions on based on this class
 
 
 
  Change while not 

Re: [Tutor] another better way to do this ?

2014-01-11 Thread Alan Gauld

On 11/01/14 21:24, Roelof Wobben wrote:


I have two strings a and b

Now I have to check if the characters of b are all in a.
But they do have to be in the same order.


I'm not sure exactly what you mean? Can you give some examples of
data that pass and that fail the criteria?

Your algorithm below might meet one definition of the spec but
its not valid code since it uses return but is not a function.


length = len(b)
start = 1
while start  length :
   check = a.find (b[start])
   if check == -1 :
 return False
   start = start + 1
return True


Problems I see are:
1) you start testing at b[1] not b[0]
2) you don't check if the letters are in the same sequence in a as in b
3) you probably could tidy it up using a for loop over b rather than 
indexing



But according to the site this can be solved in a one-liner.


That depends on the spec.
And have you covered regular expressions? That is probably one
way to do a one-liner...

But just because you can do it in one line doesn't mean you
should. It's better for code to be readable than short.


HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] another better way to do this ?

2014-01-11 Thread Roelof Wobben
Hello, 
 
I try to learn python by following the audicity page.
 
Now I have the following problem.
 
I have two strings a and b 
 
Now I have to check if the characters of b are all in a.
But they do have to be in the same order. 
 
So I thought about this solution.
 
length = len(b)
start = 1 
while start  length :
  check = a.find (b[start])
  if check == -1 : 
return False 
  start = start + 1 
return True 
 
But according to the site this can be solved in a one-liner. 
 
So can someone give me pointers how this can be done and if my solution can 
work. 
 
Roelof
 
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Windows Install Issue

2014-01-11 Thread eryksun
On Sat, Jan 11, 2014 at 10:24 AM, Matthew Ngaha chigga...@gmail.com wrote:

 Unfortunately it is not possible to use both the PyQt4 and PyQt5
 installers at the same time. If you wish to have both PyQt4 and PyQt5
 installed at the same time you will need to build them yourself from
 the source packages.

 after seeing this i thought it was better not to try it and maybe
 currupt my files

The pre-built versions of PyQt4 and PyQt5 don't use the same version
of SIP. If you don't have a build system (e.g. Visual Studio 2010, the
Windows 7 SDK, or MinGW), then using a virtual environment should work
around the problem.

http://docs.python.org/3/library/venv.html

Install PyQt4, and then copy the following files and directories to a
separate environment:

Python33\qt.conf
Python33\Lib\site-packages\sip.pyd
Python33\Lib\site-packages\PyQt4

Copy the qt.conf file to the environment's Scripts, and update the
absolute paths it contains to the new PyQt4 directory. Also edit
qt.conf and pyuic4.bat in the PyQt4 directory. Then uninstall PyQt4
and install PyQt5.

This would be simpler if PyQt used a bdist_wininst installer that
works with easy_install. Apparently PySide does.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Windows Install Issue

2014-01-11 Thread Matthew Ngaha
On Sun, Jan 12, 2014 at 1:13 AM, eryksun eryk...@gmail.com wrote:

 The pre-built versions of PyQt4 and PyQt5 don't use the same version
 of SIP. If you don't have a build system (e.g. Visual Studio 2010, the
 Windows 7 SDK, or MinGW), then using a virtual environment should work
 around the problem.

 http://docs.python.org/3/library/venv.html

 Install PyQt4, and then copy the following files and directories to a
 separate environment:

Problem solved. Thanks so much:)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] another better way to do this ?

2014-01-11 Thread Don Jennings

On Jan 11, 2014, at 4:24 PM, Roelof Wobben wrote:

 Hello, 
  
 I try to learn python by following the audicity page.
  
 Now I have the following problem.
  
 I have two strings a and b 
  
 Now I have to check if the characters of b are all in a.
 But they do have to be in the same order. 

Perhaps they are looking for something like:

 'abc' in 'someotherabcstring'
True

I suspect that you'll want to figure out how to do that same task with 
variables now :)

Take care,
Don

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 115, Issue 28

2014-01-11 Thread Keith Winston
On Sat, Jan 11, 2014 at 7:37 PM, Alan Gauld alan.ga...@btinternet.com wrote:
 In other words, think about the design of your code don't
 just type randomly.


I prefer the million monkeys at a million typewriters approach to
coding...  But then, it's all I've tried...


-- 
Keith
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor