[Tutor] Python help

2014-02-28 Thread Tone Lite
Hello,

I am having trouble coming up with a solution to this exercise and any help
would be appreciated, thanks! I have attached the code below.



'''exercise to complete and test this function'''

def joinStrings(stringList):
'''Join all the strings in stringList into one string,
and return the result, NOT printing it. For example:

 s = joinStrings(['very', 'hot', 'day']) # returns string
 print(s)
veryhotday
'''
# finish the code for this function



def main():
print(joinStrings(['very', 'hot', 'day']))
print(joinStrings(['this', 'is', 'it']))
print(joinStrings(['1', '2', '3', '4', '5']))

main()
'''exercise to complete and test this function'''

def joinStrings(stringList):
'''Join all the strings in stringList into one string,
and return the result, NOT printing it. For example:

 s = joinStrings(['very', 'hot', 'day']) # returns string
 print(s) 
veryhotday
'''
# finish the code for this function



def main():
print(joinStrings(['very', 'hot', 'day']))
print(joinStrings(['this', 'is', 'it']))
print(joinStrings(['1', '2', '3', '4', '5']))

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


Re: [Tutor] Python help

2014-02-28 Thread Ben Finney
Tone Lite tonelitebe...@gmail.com writes:

 I am having trouble coming up with a solution to this exercise and any
 help would be appreciated, thanks! I have attached the code below.

The code you present appears to be the exercise. Are you asking for
someone to write the solution for you? That isn't what we do here. We'll
help you, but that doesn't mean we'll do your work for you.

Please show us what you've tried, describe what it should be doing, and
what is happening instead. If there is an error, please also show the
complete error output.

-- 
 \  “He who allows oppression, shares the crime.” —Erasmus Darwin, |
  `\ grandfather of Charles Darwin |
_o__)  |
Ben Finney

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


Re: [Tutor] subprocess.call list vs. str argument

2014-02-28 Thread Albert-Jan Roskam




 From: Oscar Benjamin oscar.j.benja...@gmail.com
To: Albert-Jan Roskam fo...@yahoo.com 
Cc: Dave Angel da...@davea.name; eryksun eryk...@gmail.com; 
Tutor@python.org tutor@python.org 
Sent: Wednesday, February 26, 2014 3:38 PM
Subject: Re: [Tutor] subprocess.call list vs. str argument
 

On 26 February 2014 08:50, Albert-Jan Roskam fo...@yahoo.com wrote:


 Yesterday evening (it was *late* so forgive me if I wrong) I realized that 
 part of my confusion was also caused by the fact that I ran my code in Idle.
 If I called subprocess.call with a list argument, it  returned code 0 
 (success) but the generated sphinx code was not the same as when I ran the 
 program from the terminal. I concluded that this is some weird interaction 
 between Idle (which may also run in a subprocess??) and my own program. I 
 also had no problems when I ran (in the terminal): python -c import 
 subprocess; subprocess.call(['sphinx-apidoc'...(etc)])

 I was surprised that the list elements of the argument for subprocess.call 
 *have to be* separate tokens, e.g. (earlier in one of Danny's replies): a 
 token (list element) '-f -F' won't work, it has to be two separate 
 elements/tokens: '-f', '-F'. Apparently, subprocess.call is more than just a 
 convenience function that  .joins the list and escapes the resulting 
 string.

At the operating system level there is no command line as such on
posix (Linux, Mac etc.). The command to run a program is a string
giving the name of the program and you can also pass a list of strings
to the program as arguments. The command line is something that
happens in the shell (e.g. bash). Whereas Python would use quotes and
commas to separate strings in a list of strings the shell just assumes
that whitespace separates strings.

So in Python you would write
    ['qwe', 'asd', 'zxc zxc']
and it's clear that you have a list of three strings. In the shell
(e.g. bash) you would type
    qwe asd zxc zxc
and the shell understands that as three separate strings. The quotes
are needed to distinguish it from 4 strings because shell syntax
assumes that spaces separate strings.

So the idea of the command line as a single string that must be
split on whitespace is just something that happens in the shell. It is
supposed to be a convenient way of typing commands in the interactive
shell i.e. it would slow me down if I has to put in square brackets
quotes and commas every time I wanted to type a command in the shell
like ['ls', '-l', '~/mystuff']. But this convenience comes at a price
in that it becomes hard to handle strings that have spaces in them.
I've never really figured out how to write a non-trivial shell script
that can properly handle whitespace (it's easier to just avoid putting
spaces in filenames - or write the script in Python).

So really I think it's a good thing that Python lets you clearly
delineate each string in the argument list:
    subprocess.call(['ls', '-l', foldername])
without needing to worry about whether or not foldername contains spaces.


Thank you everybody for all your replies! I will use a list from now on. Also 
good to know that this works a little differently under Windows. 


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


[Tutor] running unittests on multiple OS, including non-Posix

2014-02-28 Thread Albert-Jan Roskam
Hi,

I would like to run my unittests (-- nose) on multiple platforms. I also would 
like to test different python versions and implementations on each platform 
(-- tox [2]). These platforms also include Windows, so Travis CI or Docker is 
not an option.
I was thinking about using Vagrant [3] to fire up VirtualBox [4] VMs for each 
platform-to-be-tested, then either (a) fire up nose or tox through SSH or (b) 
(the easy way) prepare each VM such that nose/tox is fire up right when the OS 
starts (ie., edit .bashrc, autoexit.bat or whatever it is called for the OS at 
hand. But this all feels like reinventing the wheel. Can you recommend a 
package or strategy to use?


[1] https://pypi.python.org/pypi/nose/

[2] https://pypi.python.org/pypi/tox
[3] http://www.vagrantbox.es/
[4] https://www.virtualbox.org/

 
Regards,

Albert-Jan




~~

All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a 

fresh water system, and public health, what have the Romans ever done for us?

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


Re: [Tutor] running unittests on multiple OS, including non-Posix

2014-02-28 Thread Ben Finney
Albert-Jan Roskam fo...@yahoo.com writes:

 I would like to run my unittests (-- nose) on multiple platforms. I
 also would like to test different python versions and implementations
 on each platform (-- tox [2]).

 […] But this all feels like reinventing the wheel. Can you recommend a
 package or strategy to use?

I'd recommend you describe your requirements in the “testing-in-python”
forum URL:http://lists.idyll.org/listinfo/testing-in-python/,
specifically for discussing tools and techniques for testing in Python.

-- 
 \   “Always do right. This will gratify some people, and astonish |
  `\the rest.” —Mark Twain |
_o__)  |
Ben Finney

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


Re: [Tutor] running unittests on multiple OS, including non-Posix

2014-02-28 Thread Albert-Jan Roskam


- Original Message -

 From: Ben Finney ben+pyt...@benfinney.id.au
 To: tutor@python.org
 Cc: 
 Sent: Friday, February 28, 2014 10:33 AM
 Subject: Re: [Tutor] running unittests on multiple OS, including non-Posix
 
 Albert-Jan Roskam fo...@yahoo.com writes:
 
  I would like to run my unittests (-- nose) on multiple platforms. I
  also would like to test different python versions and implementations
  on each platform (-- tox [2]).
 
  […] But this all feels like reinventing the wheel. Can you recommend a
  package or strategy to use?
 
 I'd recommend you describe your requirements in the “testing-in-python”
 forum URL:http://lists.idyll.org/listinfo/testing-in-python/,
 specifically for discussing tools and techniques for testing in Python.

Cool, thanks. I just subscribed to that list -- Your subscription request has 
been received, and will soon be acted upon.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] When to use multiprocessing Managers?

2014-02-28 Thread James Chapman
Thanks for the replies so far...

As per the subject line, yes I'm talking about managers and any object
a manager is capable of spawning. This is not version specific or code
specific, it's more a discussion on when to use a manager and when
it's not needed.

From the OReilly link sent by
Steven...(http://broadcast.oreilly.com/2009/04/pymotw-multiprocessing-part-2.html)
The Manager is responsible for coordinating shared information state
between all of its users. By creating the list through the manager,
the list is updated in all processes when anyone modifies it. In
addition to lists, dictionaries are also supported.

In my case I have multiple threaded processing sending log messages to
a Queue that was created by the parent process. The parent process
then has a read thread to take messages out of the queue and write
them to file. Whether I create the queue object like this:

log_Q = multiprocessing.Queue()

or whether I create it like this:

multimanager = multiprocessing.Manager()
log_Q = multimanager.Queue()

seems to make no difference. I always get all the messages from all
the threads in all the processes.

Perhaps the manager would be important if I was writing to a Queue and
expecting all threads to see that message? Although if I needed to
command a thread to do something I'd probably have a separate class
and separate thread for that purpose.

James
--
James


On 26 February 2014 14:19, David Palao dpalao.pyt...@gmail.com wrote:
 2014-02-25 11:52 GMT+01:00 James Chapman ja...@uplinkzero.com:
 Hello tutors

 I'm curious about managers and when to use them.
 For example, I see they offer a Queue() for sharing a Q between
 processes, but if I create a Q in the parent process and pass it down
 to child processes, then they can put messages into that Q just fine,
 and I presume the same thing for other objects available under the
 managers package.

 So unless the other process is on a different machine, is there a
 reason to use a manager?

 Does anyone have any use case examples or snippets I could look at even?

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

 Hello,
 I asked myself the same question when I started using multiprocessing
 time ago. So I was very happy when I saw the question by James.

 From my limited knowledge, I would say that a Manager can be useful
 when processes are distributed across different hosts, or if the
 exchange of information between processes is more complex than just a
 couple of synchronization primitives.

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


Re: [Tutor] Python help

2014-02-28 Thread James Chapman
The answer lies in this page:
http://docs.python.org/3.3/library/stdtypes.html#string-methods

--
James


On 28 February 2014 11:44, James Chapman ja...@uplinkzero.com wrote:
 The answer lies in this page:
 http://docs.python.org/3.3/library/stdtypes.html#string-methods


 --
 James


 On 28 February 2014 08:15, Ben Finney ben+pyt...@benfinney.id.au wrote:
 Tone Lite tonelitebe...@gmail.com writes:

 I am having trouble coming up with a solution to this exercise and any
 help would be appreciated, thanks! I have attached the code below.

 The code you present appears to be the exercise. Are you asking for
 someone to write the solution for you? That isn't what we do here. We'll
 help you, but that doesn't mean we'll do your work for you.

 Please show us what you've tried, describe what it should be doing, and
 what is happening instead. If there is an error, please also show the
 complete error output.

 --
  \  “He who allows oppression, shares the crime.” —Erasmus Darwin, |
   `\ grandfather of Charles Darwin |
 _o__)  |
 Ben Finney

 ___
 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] Reg: How to read string from a static text box from a GUI made in VC++

2014-02-28 Thread Shweta Kaushik

Hi,

I am writing a script to automate GUI which is designed in VC++. How to read 
strings from a static box using python(pywinauton).
Can you provide function details?

Thanks  Regards,
Shweta Kaushik
HCL Technologies Ltd.
Mob: +91 9500042351
Extn: 51904



::DISCLAIMER::


The contents of this e-mail and any attachment(s) are confidential and intended 
for the named recipient(s) only.
E-mail transmission is not guaranteed to be secure or error-free as information 
could be intercepted, corrupted,
lost, destroyed, arrive late or incomplete, or may contain viruses in 
transmission. The e mail and its contents
(with or without referred errors) shall therefore not attach any liability on 
the originator or HCL or its affiliates.
Views or opinions, if any, presented in this email are solely those of the 
author and may not necessarily reflect the
views or opinions of HCL or its affiliates. Any form of reproduction, 
dissemination, copying, disclosure, modification,
distribution and / or publication of this message without the prior written 
consent of authorized representative of
HCL is strictly prohibited. If you have received this email in error please 
delete it and notify the sender immediately.
Before opening any email and/or attachments, please check them for viruses and 
other defects.


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


Re: [Tutor] Reg: How to read string from a static text box from a GUI made in VC++

2014-02-28 Thread Alan Gauld

On 28/02/14 11:41, Shweta Kaushik wrote:

Hi,

I am writing a script to automate GUI which is designed in VC++. How to
read strings from a static box using python(pywinauton).


That's a bit off topic for this list, we focus on core Python
language and standard library issues.

You could try using the ctypes library module to access
the Win32API directly or even pythonwin if you have a
COM Object to access.

However, the Python Windows mailing list might be a more
pertinent list to ask.

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


Re: [Tutor] running unittests on multiple OS, including non-Posix

2014-02-28 Thread Mark Lawrence

On 28/02/2014 09:14, Albert-Jan Roskam wrote:

Hi,

I would like to run my unittests (-- nose) on multiple platforms. I also would 
like to test different python versions and implementations on each platform (-- 
tox [2]). These platforms also include Windows, so Travis CI or Docker is not an 
option.
I was thinking about using Vagrant [3] to fire up VirtualBox [4] VMs for each 
platform-to-be-tested, then either (a) fire up nose or tox through SSH or (b) 
(the easy way) prepare each VM such that nose/tox is fire up right when the OS 
starts (ie., edit .bashrc, autoexit.bat or whatever it is called for the OS at 
hand. But this all feels like reinventing the wheel. Can you recommend a 
package or strategy to use?


[1] https://pypi.python.org/pypi/nose/

[2] https://pypi.python.org/pypi/tox
[3] http://www.vagrantbox.es/
[4] https://www.virtualbox.org/




Do you really believe that this question is suited to a tutor mailing 
list?  Strangely enough I don't but I'm pleased to see that you've taken 
Ben Finney's advice and gone to the testing mailing list.


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


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


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


[Tutor] win32api win32gui help

2014-02-28 Thread Joe Bennett
Looking for a good simple remedial course on getting my python script
to talk to a Windows program. The author of the windows program has
documented the api here:

http://www.logger32.net/help/Logger32/Using%20the%20Logger32%20External%20Interface.htm


I'm struggling to understand how to implement the messages with
win32api/ gui... I've taken a stab at it here with my goal being that
I just want to 'register' with the program and receive the response
from it. So far I'm still scratching my head over this...

I get a response for 'hwnd' but have not been able to get any
confirmation that RegisterMessage, PostMessage and GetMessage are
working, configured properly or...what...

Running this all in WIN7 with ActivePython 2.6.6...


import win32api
import win32gui

hwnd = win32gui.FindWindowEx(0, 0, 0, Logger32)


print hwnd= , hwnd

message = win32api.RegisterWindowMessage(Logger32 3)


win32api.PostMessage(hwnd,message,1,9)

test = win32gui.GetMessage(hwnd,0,0)

print GetMessage: , test



Thanks


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


Re: [Tutor] win32api win32gui help

2014-02-28 Thread Alan Gauld

On 28/02/14 17:22, Joe Bennett wrote:

Looking for a good simple remedial course on getting my python script
to talk to a Windows program. The author of the windows program has
documented the api here:

http://www.logger32.net/help/Logger32/Using%20the%20Logger32%20External%20Interface.htm


This is really way beyond the scope of the tutor list which
focuses on the Python language and core modules.

You may find somebody here who can answer but you will be
much more likely to get a response on the Python Windows
mailing list.

The gmane newsfeed is here:

gmane.comp.python.windows

Mark Hammond, the author of Pythonwin, hangs out there along
with many other Windows folks.

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] Help with Guess the number script

2014-02-28 Thread Scott W Dunning
Hello, i am working on a project for learning python and I’m stuck.  The 
directions are confusing me.  Please keep in mind I’m very ne to this.  The 
directions are long so I’ll just add the paragraphs I’m confused about and my 
code if someone could help me out I’d greatly appreciate it!  Also, we haven’t 
learned loops yet so just conditional operators and for some reason we can’t 
use global variables.  


from random import randrange
randrange(1, 101)

from random import seed
seed(129)

def print_description():
print Welcome to Guess the Number.
I have seleted a secret number in the range 1 ... 100.
You must guess the number within 10 tries.
I will tell you if you ar high or low, and
I will tell you if you are hot or cold.\n
   
def get_guess(guess_number):
print (,guess_number,)Plese enter a guess:
current_guess = raw_input()
return int(guess_number)

def main():
print_description()
secret = 50
current_guess = 1
get_guess(1)
if current_guess != secret():
print Congratulations you win!!
   
main()


Here are the instructions I’m having a hard time with and just not sure I’m 
doing it correctly.  I’m not sure the get_guess function is correct and I’m a 
little lost with the secret and current_guess variable.

From within the body of the main function, immediately after the call to print 
description, create variable secret and assign it a random number between 1 and 
100, generated using the randrange function. You will need to pass two argument 
to randrange, what do you think they should be? You should be able to use the 
python help system or online python documentation to make sure you understand 
the arguments to randrange.

After the end of the body of the print description function, define a new 
global function named get guess that takes a single parameter. Name the 
parameter guess number, because it will hold the index (1, 2, 3, ..., 10) of 
current guess attempt. Make the function ask the user to enter guess using the 
raw input function. The function will return the number entered by the user, 
after it has been converted to an integer.

Return to the main function after the statement that assigned a value to the 
secret variable. In a new variable named current guess store the result of 
calling the get guess function with an argument of 1. Run your program to make 
sure it works correctly.

At the end of the main function, check if the current guess matches the secret. 
If it matches, print ‘Congratulations, you win!’. If it does not, print ‘Please 
play again!’ 





Thanks again!!!




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


Re: [Tutor] Help with Guess the number script

2014-02-28 Thread Ben Finney
Scott W Dunning swdunn...@cox.net writes:

 def get_guess(guess_number):
 print (,guess_number,)Plese enter a guess:
 current_guess = raw_input()
 return int(guess_number)

You've bound the name ‘current_guess’ to the user's input, but then do
nothing with it for the rest of the function; it will be discarded
without being used.

Then, you use the parameter ‘guess_number’, create a new integer from
it, and return that integer. I think you've used the wrong name for the
‘int()’ parameter.

-- 
 \  “The most merciful thing in the world… is the inability of the |
  `\human mind to correlate all its contents.” —Howard Philips |
_o__)Lovecraft |
Ben Finney

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