Method not found: 'ServiceSettingSave' in Suds package

2013-09-27 Thread Anup Kandalkar
I am trying to create service for the url:

   wsdl_url = https://avatax.avalara.net/Account/Accountsvc.wsdl

But some error is coming:

 svc = suds.client.Client(url=wsdl_url)
  File "/usr/lib/python2.7/dist-packages/suds/client.py", line 114, in __init__
self.wsdl = reader.open(url)
  File "/usr/lib/python2.7/dist-packages/suds/reader.py", line 152, in open
d = self.fn(url, self.options)
  File "/usr/lib/python2.7/dist-packages/suds/wsdl.py", line 158, in __init__
self.resolve()
  File "/usr/lib/python2.7/dist-packages/suds/wsdl.py", line 207, in resolve
c.resolve(self)
  File "/usr/lib/python2.7/dist-packages/suds/wsdl.py", line 660, in resolve
self.resolvesoapbody(definitions, op)
  File "/usr/lib/python2.7/dist-packages/suds/wsdl.py", line 686, in 
resolvesoapbody
ptop = self.type.operation(op.name)
  File "/usr/lib/python2.7/dist-packages/suds/wsdl.py", line 525, in operation
raise MethodNotFound(name)
MethodNotFound: Method not found: 'ServiceSettingSave'

please help me to solve this issues, for this need to update python packages or 
any other way.

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


Re: Download all youtube favorites with youtube-dl script

2013-09-27 Thread Thomas Kandler
On 26.09.2013 17:13, Bill wrote:
> I have been using the script youtube-dl http://rg3.github.io/youtube-dl/
> 
> And I was wondering if there is a way to download all of a user's
> favorites or uploads.
> 
> The script has a functionality to download all videos in a txt file. So
> if there is a way using the youtube API or JSON (none of which I am
> familiar with) to bring up a list of all these videos then it'd be a
> simple case putting these urls into a file.
> 
> The problem is youtube displays favorites or user uploads in pages or
> infinite scroll. So it is difficult to access them by the BeautifulSoup
> module.
> 
> 
> What do you suggest?

Regarding the uploads: most profiles do have something called 'Popular
Uploads' or 'Recent Uploads'. Hover with the mouse over the link, a
'play'-Button appears, click it, copy the URL (should have a &list
parameter), paste the URL in youtube-dl (or a txt-file) and it will
fetch all videos.

I am not sure if this works for favorites, too, but that's the way I do it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Handling 3 operands in an expression without raising an exception

2013-09-27 Thread Νίκος

Στις 27/9/2013 1:55 πμ, ο/η Dave Angel έγραψε:

On 26/9/2013 18:14, Νίκος wrote:


Στις 26/9/2013 11:16 μμ, ο/η Denis McMahon έγραψε:

On Thu, 26 Sep 2013 19:58:02 +0300, Νίκος wrote:


except socket.gaierror as e:
city = host = "UnKnown Origin"

But then what if in case of an error i needed different string set to be
assigned on city and host respectively?


Oh FFS

Are you serious when you ask this?

Simply change:

except socket.gaierror as e:
  city = host = "UnKnown Origin"

To:

except socket.gaierror as e:
  city = "Unknown City"
  host = "Unknown Host"


Yes indeed that was an idiotic question made by me, but i was somehow
feeling again that i should handle it in one-liner, avoid wanting to use
2 statements.


newlines are still cheap.  And they can really help readability.


I wonder if there is a way to assign the string "Unknown Origin" to the
variable that failed in the try block to get a value.

Can i describe that somehow inside the except block?

I mean like:

except socket.gaierror as e:
what_ever_var_failed = "Unknown Origin"


Simply assign the default values BEFORE the try block, and use pass as
the except block.

That still doesn't get around the inadvisability of putting those 3
lines in the try block.

You still haven't dealt with the gt assignment and its possible
exception.

Yes gi must be removed form within the try block because iam tesign it 
for failure.


I'am not sure what you mean though when you say:


Simply assign the default values BEFORE the try block, and use pass as
the except block.


Can you please make it more clear for me?

This is my code as i have it at the moment:

ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or 
os.environ.get('REMOTE_ADDR', "Cannot Resolve") )

try:
gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat')
city = gi.time_zone_by_addr( ipval )
host = socket.gethostbyaddr( ipval ) [0]
except socket.gaierror as e:
city = "Άγνωστη Πόλη"
host = "Άγνωστη Προέλευση"

Or even better since i actually use 3 vars inside the try block it would 
be really neat to be able to detect which far failed and assign a 
specific value variable failed depended.


IF it can also be written in one-line afteer the excpect would be even 
better. Call me persistent but when i can write somethign in 1-line i 
wou;d prefer it over 3-lines.

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


Re: Handling 3 operands in an expression without raising an exception

2013-09-27 Thread Steven D'Aprano
On Fri, 27 Sep 2013 12:19:53 +0300, Νίκος wrote:

> I'am not sure what you mean though when you say:
> 
>> Simply assign the default values BEFORE the try block, and use pass as
>> the except block.
> 
> Can you please make it more clear for me?


variable = "default value"
try:
variable = something_that_might_fail()
except SomeException:
pass




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


Re: What's the best way to extract 2 values from a CSV file from each row systematically?

2013-09-27 Thread Roland Mueller
Hello,

2013/9/24 Alex Lee 

> Thanks for the help guys! I'll definitely read up on the csv module
> documentation.
>
> Tim, that's incredibly helpful, thanks a lot! :) My CSV file doesn't have
> headers, but I'm sure I can just as easily add it in manually.
>

a better way to provide column headers is to use the fieldname parameter
when creating the CSV reader. fieldnames is a string array that should
match the number of columns in the csv file:

*class *csv.DictReader(*csvfile*, *fieldnames=None*, *restkey=None*, *
restval=None*, *dialect='excel'*, **args*, ***kwds*)

BR,
Roland

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


Re: Handling 3 operands in an expression without raising an exception

2013-09-27 Thread Νίκος

Στις 27/9/2013 12:26 μμ, ο/η Steven D'Aprano έγραψε:

On Fri, 27 Sep 2013 12:19:53 +0300, Νίκος wrote:


I'am not sure what you mean though when you say:


Simply assign the default values BEFORE the try block, and use pass as
the except block.


Can you please make it more clear for me?



variable = "default value"
try:
 variable = something_that_might_fail()
except SomeException:
 pass


Thanks Steven but this way i still have to declare the default string 
sfor the variables:


Its no different than:

except socket.gaierror as e:
city = "Άγνωστη Πόλη"
host = "Άγνωστη Προέλευση"

Your way set the vars on top, the other way set the vars inside the 
except block.


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


card dealer

2013-09-27 Thread markotaht
from random import *
from math import floor


kaarte_alles = 52
kaart_tõmmatud = [False for i in range(52)]


mast = ["ärtu", "ruutu", "poti", "risti"]
aste = ["äss", "kaks", "kolm", "neli","viis", "kuus", \
"seitse", "kaheksa", "üheksa", "kümme", "soldat",\
"emand", "kuningas"]

def tõmba_kaart():
global kaarte_alles
if kaarte_alles == 0:
print("Segan pakki")
kaarte_alles = 52
for i in range(52):
kaart_tõmmatud[i] = False
kaarte_alles -= 1
n = random(kaarte_alles)
kaart = vali_järgmine_vaba(n)
m = kaart % 13
a = kaart / 13
print(mast[int(a)] + " " + aste[int(m)])

def vali_järgmine_vaba(n):
i = -1

while(n  > 0):
n -= 1
i = i + 1
while kaart_tõmmatud[i]:
i = i + 1
kaart_tõmmatud[i] = True
return i

def random(n):
return randint(0, n)

while True:
n = int(input("Mitu kaarti tõmmata(0 et väljuda): "))
if(n==0):
break

for i in range(n):
tõmba_kaart()


HI im trying to make a card dealer, but this code doesent work correctly. It 
deasl cards, but the cards to repeat. when i type in 52 ten i might get 3 the 
same cards. This is a translation from my c++ code. In c++ it works correctly.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Handling 3 operands in an expression without raising an exception

2013-09-27 Thread Dave Angel
On 27/9/2013 05:19, Νίκος wrote:

> Στις 27/9/2013 1:55 πμ, ο/η Dave Angel έγραψε:

>>
>> Simply assign the default values BEFORE the try block, and use pass as
>> the except block.
>>
>> That still doesn't get around the inadvisability of putting those 3
>> lines in the try block.
>>
>> You still haven't dealt with the gt assignment and its possible
>> exception.
>>
> Yes gi must be removed form within the try block because iam tesign it 
> for failure.

Then why don't you do it below?

>
> I'am not sure what you mean though when you say:
>
>> Simply assign the default values BEFORE the try block, and use pass as
>> the except block.
>
> Can you please make it more clear for me?
>
> This is my code as i have it at the moment:
>
> ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or 
> os.environ.get('REMOTE_ADDR', "Cannot Resolve") )
> try:
>   gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat')
>   city = gi.time_zone_by_addr( ipval )
>   host = socket.gethostbyaddr( ipval ) [0]
> except socket.gaierror as e:
>   city = "Άγνωστη Πόλη"
>   host = "Άγνωστη Προέλευση"

ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or 
os.environ.get('REMOTE_ADDR', "Cannot Resolve") )
city = "Άγνωστη Πόλη"
host = "Άγνωστη Προέλευση"
try:
city = gi.time_zone_by_addr( ipval )
host = socket.gethostbyaddr( ipval ) [0]
except socket.gaierror as e:
pass

>
> Or even better since i actually use 3 vars inside the try block it would 
> be really neat to be able to detect which far failed and assign a 
> specific value variable failed depended.

ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or 
os.environ.get('REMOTE_ADDR', "Cannot Resolve") )
city = None
host = None
try:
city = gi.time_zone_by_addr( ipval )
host = socket.gethostbyaddr( ipval ) [0]
except socket.gaierror as e:
if not city:
city = "Άγνωστη Πόλη"
if not host:
host = "Άγνωστη Προέλευση"

or:

ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or 
os.environ.get('REMOTE_ADDR', "Cannot Resolve") )
city = None
host = None
try:
city = gi.time_zone_by_addr( ipval )
host = socket.gethostbyaddr( ipval ) [0]
except socket.gaierror as e:
if not host:
host = "Άγνωστη Προέλευση"
if not city:
city = "Άγνωστη Πόλη"

Note that in that last case, I tested the variables in the reverse
order.  Note also on both of these that I assumed that None is not a
reasonable value for either of those.  In fact, I also assume that an
empty string is not a reasonable value.  If I didn't like the latter
assumption, I'd have used tests like  if host is None:

>
> IF it can also be written in one-line afteer the excpect would be even 
> better. Call me persistent but when i can write somethign in 1-line i 
> wou;d prefer it over 3-lines.

Ridiculous.  But if you like code golf, you can always do:

city, host = "Άγνωστη Πόλη", "Άγνωστη Προέλευση"

You should study APL.  Many functions were written in one line, with
twenty lines of explanation.  The function itself was considered
unreadable nonsense. And if a function stopped working, general wisdom
was to throw it out, and re-implement the explanation. I studied it
briefly in class in 1970, and have no idea if there are current
implementations.


-- 
DaveA


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


Re: Handling 3 operands in an expression without raising an exception

2013-09-27 Thread Νίκος

Στις 27/9/2013 1:43 μμ, ο/η Dave Angel έγραψε:

Στις 27/9/2013 1:55 πμ, ο/η Dave Angel έγραψε:

Simply assign the default values BEFORE the try block, and use pass as
the except block.

That still doesn't get around the inadvisability of putting those 3
lines in the try block.

You still haven't dealt with the gt assignment and its possible
exception.

Yes gi must be removed form within the try block because iam tesign it
for failure.

Then why don't you do it below?

I'am not sure what you mean though when you say:

Simply assign the default values BEFORE the try block, and use pass as
the except block.

Can you please make it more clear for me?

This is my code as i have it at the moment:

ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or
os.environ.get('REMOTE_ADDR', "Cannot Resolve") )
try:
gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat')
city = gi.time_zone_by_addr( ipval )
host = socket.gethostbyaddr( ipval ) [0]
except socket.gaierror as e:
city = "Άγνωστη Πόλη"
host = "Άγνωστη Προέλευση"



ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or
os.environ.get('REMOTE_ADDR', "Cannot Resolve") )
city = "Άγνωστη Πόλη"
host = "Άγνωστη Προέλευση"
try:
city = gi.time_zone_by_addr( ipval )
host = socket.gethostbyaddr( ipval ) [0]
except socket.gaierror as e:
pass


Thanks for taking the time to expain this:

In the exact above solution of yours opposed to the top of mines is that 
you code has the benefit of actually identifying the variable that 
failed to have been assigned a value while in my code no matter what 
variable failes in the try block i assign string to both 'city' and 
'host' hence i dont really know which one of them is failing?


Di i understood it correctly?
--
https://mail.python.org/mailman/listinfo/python-list


Re: card dealer

2013-09-27 Thread Dave Angel
On 27/9/2013 06:24, markot...@gmail.com wrote:

> from random import *
> from math import floor
>

>
> kaarte_alles = 52
> kaart_tõmmatud = [False for i in range(52)]
>
>
> mast = ["ärtu", "ruutu", "poti", "risti"]
> aste = ["äss", "kaks", "kolm", "neli","viis", "kuus", \
> "seitse", "kaheksa", "üheksa", "kümme", "soldat",\
> "emand", "kuningas"]
>
> def tõmba_kaart():
> global kaarte_alles
> if kaarte_alles == 0:
> print("Segan pakki")
> kaarte_alles = 52
> for i in range(52):
> kaart_tõmmatud[i] = False
> kaarte_alles -= 1
> n = random(kaarte_alles)
> kaart = vali_järgmine_vaba(n)
> m = kaart % 13
> a = kaart / 13
> print(mast[int(a)] + " " + aste[int(m)])
>
> def vali_järgmine_vaba(n):
> i = -1
>
> while(n  > 0):
> n -= 1
> i = i + 1
> while kaart_tõmmatud[i]:
> i = i + 1
> kaart_tõmmatud[i] = True
> return i
>
> def random(n):
> return randint(0, n)
>
> while True:
> n = int(input("Mitu kaarti tõmmata(0 et väljuda): "))
> if(n==0):
> break
>
> for i in range(n):
> tõmba_kaart()
>
>
> HI im trying to make a card dealer, but this code doesent work correctly. It 
> deasl cards, but the cards to repeat. when i type in 52 ten i might get 3 the 
> same cards. This is a translation from my c++ code. In c++ it works correctly.

If you had created your global list containing list(range(52)), then you
could do nearly your entire program with one call to random.sample.

http://docs.python.org/3.3/library/random.html#random.sample

-- 
DaveA


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


Re: card dealer

2013-09-27 Thread MRAB

On 27/09/2013 11:24, markot...@gmail.com wrote:

from random import *
from math import floor


kaarte_alles = 52
kaart_tõmmatud = [False for i in range(52)]


mast = ["ärtu", "ruutu", "poti", "risti"]
aste = ["äss", "kaks", "kolm", "neli","viis", "kuus", \
 "seitse", "kaheksa", "üheksa", "kümme", "soldat",\
 "emand", "kuningas"]

def tõmba_kaart():
 global kaarte_alles
 if kaarte_alles == 0:
 print("Segan pakki")
 kaarte_alles = 52
 for i in range(52):
 kaart_tõmmatud[i] = False
 kaarte_alles -= 1
 n = random(kaarte_alles)
 kaart = vali_järgmine_vaba(n)
 m = kaart % 13
 a = kaart / 13
 print(mast[int(a)] + " " + aste[int(m)])

def vali_järgmine_vaba(n):
 i = -1

 while(n  > 0):
 n -= 1
 i = i + 1
 while kaart_tõmmatud[i]:
 i = i + 1
 kaart_tõmmatud[i] = True
 return i

def random(n):
 return randint(0, n)

while True:
 n = int(input("Mitu kaarti tõmmata(0 et väljuda): "))
 if(n==0):
 break

 for i in range(n):
 tõmba_kaart()


HI im trying to make a card dealer, but this code doesent work correctly. It 
deasl cards, but the cards to repeat. when i type in 52 ten i might get 3 the 
same cards. This is a translation from my c++ code. In c++ it works correctly.


Suppose random(...) returns 0.

In 'vali_järgmine_vaba', n == 0, so it won't run anything in the
'while' loop, therefore i == -1, therefore:

kaart_tõmmatud[-1] = True

(which sets the last item in the list).

If random(...) returns 0 again (which is possible),
'vali_järgmine_vaba' will do exactly the same thing.

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


nozama-cloudsearch-service 1.1.2: a local Amazon CloudSearch using ElasticSearch as its backend.

2013-09-27 Thread Oisin Mulvihill
Hello,

Have you ever wanted to test your app against a dev version of your
production CloudSearch? Is management saying budget constraints won't allow
this? Then Nozama CloudSearch is for you.

It is a light weight implementation of Amazon's CloudSearch service you can
run locally. Its has additional REST API features which allow inspection of
data in a way not available via Amazon CloudSearch.

Nozama is also a way to migrate from Amazon CloudSearch to ElasticSearch.

Version 1.1.2

This now supports text searching and uses ElasticSearch as it backend.
Facets are not yet supported. I use MongoDB to store the results of batch
upload runs. This will change in future as I believe I can use
ElasticSearch for this too.

It is BSD licensed and available now from pypi https://pypi.python.org/pypi/
nozama-cloudsearch-service:

  easy_install nozama-cloudsearch-service

Contributions are always welcome. Just fork me on github:

 * https://github.com/oisinmulvihill/nozama-cloudsearch

It also has documentation which it self hosts or can be seen on readthedocs:

 * https://nozama-cloudsearch.readthedocs.org/en/latest/index.html


All the best,

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


Re: card dealer

2013-09-27 Thread Alister
On Fri, 27 Sep 2013 03:24:28 -0700, markotaht wrote:

> from random import *
> from math import floor
> 
> 
> kaarte_alles = 52 kaart_tõmmatud = [False for i in range(52)]
> 
> 
> mast = ["ärtu", "ruutu", "poti", "risti"]
> aste = ["äss", "kaks", "kolm", "neli","viis", "kuus", \
> "seitse", "kaheksa", "üheksa", "kümme", "soldat",\
> "emand", "kuningas"]
> 
> def tõmba_kaart():
> global kaarte_alles if kaarte_alles == 0:
> print("Segan pakki")
> kaarte_alles = 52 for i in range(52):
> kaart_tõmmatud[i] = False
> kaarte_alles -= 1 n = random(kaarte_alles)
> kaart = vali_järgmine_vaba(n)
> m = kaart % 13 a = kaart / 13 print(mast[int(a)] + " " +
> aste[int(m)])
> 
> def vali_järgmine_vaba(n):
> i = -1
> 
> while(n  > 0):
> n -= 1 i = i + 1 while kaart_tõmmatud[i]:
> i = i + 1
> kaart_tõmmatud[i] = True return i
> 
> def random(n):
> return randint(0, n)
> 
> while True:
> n = int(input("Mitu kaarti tõmmata(0 et väljuda): "))
> if(n==0):
> break
> 
> for i in range(n):
> tõmba_kaart()
> 
> 
> HI im trying to make a card dealer, but this code doesent work
> correctly. It deasl cards, but the cards to repeat. when i type in 52
> ten i might get 3 the same cards. This is a translation from my c++
> code. In c++ it works correctly.


It looks like you a simply selecting a random entry in the deck 
i would suggest you try the following

1) build the deck as a list (i think you are already doing this)
2) shuffle the list (random.shuffle would be good here)
3) pop the cards of the list as required

this resemble the real world & should be easy to break down into various 
classes & expand for multiple decks if req.


-- 
Passionate hatred can give meaning and purpose to an empty life.
-- Eric Hoffer
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: card dealer

2013-09-27 Thread Dave Angel
On 27/9/2013 07:26, Dave Angel wrote:

> On 27/9/2013 06:24, markot...@gmail.com wrote:
>
I sent the previous message long before I had finished.
>
> If you had created your global list containing list(range(52)), then you
> could do nearly your entire program with one call to random.sample.
>
> http://docs.python.org/3.3/library/random.html#random.sample
>

What is your goal?  Are you trying to make the logic match your C++
code?  Are you just trying to solve the problem, or are you trying to
figure out where the bug is in your present code.

If it were my problem, I'd build a deck as a list, shuffle it with
random.shuffle(), then deal the cards out in order.  I might also use
list.pop() to take items off, so I wouldn't need any separate counter.

If i were trying to figure out why the existing code fails, I'd start
with an assert right before setting the flags.

assert(not kaart_tõmmatud[i])
kaart_tõmmatud[i] = True

Once you do that, and it fires, you know explicitly that you have a bug.

i believe the code may be fixed by changing the function 
vali_järgmine_vaba()  to begin as follows:

def vali_järgmine_vaba(n):
i = 0
while kaart_tõmmatud[i]:
i = i + 1

while(n  > 0):

But I would point out that this is a horribly unreadable way to do it. 
It's possibly appropriate for C, which is mostly unreadable anyway.  But
even there, there are much better approaches.  For example, i recall
writing a shuffle function in C decades ago, which took an array of (52)
unique items and put them in random order.  For an array of size 52, it
did it with exactly 51 swaps, without any searching like you're doing in
the above function.


-- 
daveA


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


Re: Handling 3 operands in an expression without raising an exception

2013-09-27 Thread Dave Angel
On 27/9/2013 07:15, Νίκος wrote:

> Στις 27/9/2013 1:43 μμ, ο/η Dave Angel έγραψε:

   
>
>> ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or
>> os.environ.get('REMOTE_ADDR', "Cannot Resolve") )
>> city = "Άγνωστη Πόλη"
>> host = "Άγνωστη Προέλευση"
>> try:
>>  city = gi.time_zone_by_addr( ipval )
>>  host = socket.gethostbyaddr( ipval ) [0]
>> except socket.gaierror as e:
>>  pass
>
> Thanks for taking the time to expain this:
>
> In the exact above solution of yours opposed to the top of mines is that 

No idea what you mean here.  I'll assume you're talking about the
version you DON'T quote here, the one with the if statements in the
except clause.

> you code has the benefit of actually identifying the variable that 
> failed to have been assigned a value while in my code no matter what 
> variable failes in the try block i assign string to both 'city' and 
> 'host' hence i dont really know which one of them is failing?

Yes, it has that advantage. Of course it doesn't USE that advantage for
anything so I'd go back to the pass version quoted immediately above. 
Or I'd have two separate try/except clauses, one for each function call.
 After all, the implication of the failure is different for each.


>
> Di i understood it correctly?

I think so.

-- 
DaveA


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


How to write in to already opened excel file by using openpyxl

2013-09-27 Thread someshg2
Hi..there,

I have opened a excel file by using the following code
from openpyxl import load_workbook

 wb = load_workbook('path of the file')
DriverTableSheet = wb.get_sheet_by_name(name = 'name of the sheet')


after that i have to append some values in that excel file..

for that i used the following code

DriverTableSheet.cell(row=1, column=2).value="value"


but it is not responsive..can u guys please guide how to write / append a data 
in that excel file and save that excel file

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


Re: Handling 3 operands in an expression without raising an exception

2013-09-27 Thread Νίκος

Στις 27/9/2013 3:17 μμ, ο/η Dave Angel έγραψε:

On 27/9/2013 07:15, Νίκος wrote:


Στις 27/9/2013 1:43 μμ, ο/η Dave Angel έγραψε:






ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or
os.environ.get('REMOTE_ADDR', "Cannot Resolve") )
city = "Άγνωστη Πόλη"
host = "Άγνωστη Προέλευση"
try:
city = gi.time_zone_by_addr( ipval )
host = socket.gethostbyaddr( ipval ) [0]
except socket.gaierror as e:
pass


Thanks for taking the time to expain this:

In the exact above solution of yours opposed to the top of mines is that


No idea what you mean here.  I'll assume you're talking about the
version you DON'T quote here, the one with the if statements in the
except clause.


you code has the benefit of actually identifying the variable that
failed to have been assigned a value while in my code no matter what
variable failes in the try block i assign string to both 'city' and
'host' hence i dont really know which one of them is failing?


Yes, it has that advantage. Of course it doesn't USE that advantage for
anything so I'd go back to the pass version quoted immediately above.
Or I'd have two separate try/except clauses, one for each function call.
  After all, the implication of the failure is different for each.




Di i understood it correctly?


I think so.



Thank you for everything, i appreciate your time and effort to help me 
understand.

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


Re: How to write in to already opened excel file by using openpyxl

2013-09-27 Thread Neil Cerutti
On 2013-09-27, somes...@gmail.com  wrote:
> Hi..there,
>
> I have opened a excel file by using the following code
> from openpyxl import load_workbook
>
>  wb = load_workbook('path of the file')
> DriverTableSheet = wb.get_sheet_by_name(name = 'name of the sheet')
> after that i have to append some values in that excel file..
>
> for that i used the following code
>
> DriverTableSheet.cell(row=1, column=2).value="value"
>
> but it is not responsive..can u guys please guide how to write
> / append a data in that excel file and save that excel file

Show more code, please. And please describe the error more fully.

What did you hope to happen, and what happened instead? What have
you tried so far?

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


Re: How to write in to already opened excel file by using openpyxl

2013-09-27 Thread Joel Goldstick
On Fri, Sep 27, 2013 at 9:37 AM, Neil Cerutti  wrote:

> On 2013-09-27, somes...@gmail.com  wrote:
> > Hi..there,
> >
> > I have opened a excel file by using the following code
> > from openpyxl import load_workbook
> >
> >  wb = load_workbook('path of the file')
> > DriverTableSheet = wb.get_sheet_by_name(name = 'name of the sheet')
> > after that i have to append some values in that excel file..
> >
> > for that i used the following code
> >
> > DriverTableSheet.cell(row=1, column=2).value="value"
> >
> > but it is not responsive..can u guys please guide how to write
> > / append a data in that excel file and save that excel 
> > file
>


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

You need to read the documentation:
http://openpyxl.readthedocs.org/en/latest/tutorial.html#saving-to-a-file

The code you show doesn't have any save method being called.


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


Re: How to write in to already opened excel file by using openpyxl

2013-09-27 Thread somesh g
Hi..joel

what is said is correct i dint added save to that after adding its working 
perfect

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


Re: How to write in to already opened excel file by using openpyxl

2013-09-27 Thread somesh g
hi..Neil 

yes i dint saved that time and i added the save option and it saved 

Thanks for the response
-- 
https://mail.python.org/mailman/listinfo/python-list


unable to read combo boxes in excel by xlrd package in python

2013-09-27 Thread somesh g
Hi..there

I want to read the combo box in excel by using "xlrd" but in the output it is 
showing empty message, its not reading the combo box can u guys help me how to 
read the combo box in excel by "xlrd"

code written like this

workbook = xlrd.open_workbook('path of the file')
worksheet = workbook.sheet_by_name('sheetname')
TargetSystem = worksheet.cell_value(4, 2)
-- 
https://mail.python.org/mailman/listinfo/python-list


Free Proxy site 2014

2013-09-27 Thread 23alagmy
Free Proxy site 2014
search is the first proxy supports proxy access blocked sites, browsing, and 
downloads without restrictions and also conceal your identity Pencah by 100% 
from the sites you visit

http://natigaas7ab.net/wp/?p=14556
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unable to read combo boxes in excel by xlrd package in python

2013-09-27 Thread Neil Cerutti
On 2013-09-27, somesh g  wrote:
> Hi..there
>
> I want to read the combo box in excel by using "xlrd" but in
> the output it is showing empty message, its not reading the
> combo box can u guys help me how to read the combo box in excel
> by "xlrd"
>
> code written like this
>
> workbook = xlrd.open_workbook('path of the file')
> worksheet = workbook.sheet_by_name('sheetname')
> TargetSystem = worksheet.cell_value(4, 2)

It depends on what kind of combo-box it is. The Excel-native
combo-box sucks (no auto-completion, no multi-select, etc.), and
so it's possible a Visual Basic widget was used instead. That
would leave the cell contents blank when read, as above.

You will need to retrieve the value from the combo-box object
directly somehow.

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


Re: Handling 3 operands in an expression without raising an exception

2013-09-27 Thread Denis McMahon
On Fri, 27 Sep 2013 12:19:53 +0300, Νίκος wrote:

> This is my code as i have it at the moment:
> 
> ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or
> os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) try:
>   gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat')
>   city = gi.time_zone_by_addr( ipval )
>   host = socket.gethostbyaddr( ipval ) [0]
> except socket.gaierror as e:
>   city = "Άγνωστη Πόλη"
>   host = "Άγνωστη Προέλευση"

Here is the basic problem: You're trying to do too many things at once in 
a language you don't understand and without any understanding of the 
fundamental underlying concepts of the systems that you're interfacing 
with.

Break the task down into simpler steps and do the steps one at a time:

Calculate ipval

Calculate gi

If ipval is valid, calculate city, else give city a default value

If ipval is valid, calculate host, else give host a default value

Then consider which of the above needs to be contained within a try / 
catch.

Finally, code them as 4 separate units of code, eg:

# instantiate geolocation by ip
gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat')

# calculate ipval
try:
ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or 
  os.environ.get('REMOTE_ADDR', "Cannot Resolve") )
except ( KeyError, TypeError ):
ipval = some_default

# try and obtain time zone from ip
try:
city = gi.time_zone_by_addr( ipval )
except (error type[s]):
city = "Unknown City"

# try and obtain hostname from ip
try:
host = socket.gethostbyaddr( ipval ) [0]
except ( socket.gaierror ):
host = "Unknown Host"

Note that there is nothing special about writing it in as few lines as 
code as possible. Writing it out in a way that is easy to understand and 
follow helps make sure it actually works, and makes it a lot easier to 
maintain in future.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unable to read combo boxes in excel by xlrd package in python

2013-09-27 Thread Neil Cerutti
On 2013-09-27, Neil Cerutti  wrote:
> On 2013-09-27, somesh g  wrote:
>> Hi..there
>>
>> I want to read the combo box in excel by using "xlrd" but in
>> the output it is showing empty message, its not reading the
>> combo box can u guys help me how to read the combo box in excel
>> by "xlrd"
>>
>> code written like this
>>
>> workbook = xlrd.open_workbook('path of the file')
>> worksheet = workbook.sheet_by_name('sheetname')
>> TargetSystem = worksheet.cell_value(4, 2)
>
> It depends on what kind of combo-box it is. The Excel-native
> combo-box sucks (no auto-completion, no multi-select, etc.), and
> so it's possible a Visual Basic widget was used instead. That
> would leave the cell contents blank when read, as above.
>
> You will need to retrieve the value from the combo-box object
> directly somehow.

If it's an Active-X ListBox or ComboBox, there's probably be a
CellLink defined. This will be the cell you need to read with
xlrd to get the value.

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


Re: Handling 3 operands in an expression without raising an exception

2013-09-27 Thread Grant Edwards
On 2013-09-27, Denis McMahon  wrote:

> Note that there is nothing special about writing it in as few lines as 
> code as possible.

Hah! That's what they _want_ you to think.  First they get you hooked
on newlines, then the newline mine owners form a cartel and start
jacking up the prices.  Then you'll wish you'd spent more time
learning to write Perl one-liners...

-- 
Grant Edwards   grant.b.edwardsYow! What GOOD is a
  at   CARDBOARD suitcase ANYWAY?
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: card dealer

2013-09-27 Thread Denis McMahon
On Fri, 27 Sep 2013 12:08:33 +, Dave Angel wrote:

> i recall
> writing a shuffle function in C decades ago, which took an array of (52)
> unique items and put them in random order.

Whenever I tried to write shuffles I came up against a fairly fundamental 
limit:

52! > prng states

Granted prngs seem to be better on the importing entropy from elsewhere 
front these days.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: what is wrong in my code?? (python 3.3)

2013-09-27 Thread Denis McMahon
On Fri, 27 Sep 2013 06:54:48 -0700, dream4soul wrote:

> #!c:/Python33/python.exe -u
> import os, sys 
> print("Content-type: text/html; charset=utf-8\n\n")
> print ('Hello, world!')
> print('ранее предусматривалась смертная казнь.')

> I see only first print, second it just question marks in my browser(code
> edited in notepad++ with UTF-8 encode). what is wrong??

Sounds like your browser is ignoring the charset. Can you force the 
browser to utf-8?

What happens if you create a plain html file with the same content and 
send it to your browser?

eg: test.html:
-
Hello, world!
ранее предусматривалась смертная казнь.
-

This really doesn't look like a python issue (again).

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Hostrange expansion

2013-09-27 Thread Sam Giraffe
Hi,

I need some help in expanding a hostrange as in: h[1-100].domain.com should
get expanded into a list containing h1.domain.com to h100.domain.com. Is
there a library that can do this for me? I also need to valid the range
before I expand it, i.e., h[1*100].domain.com should not be accept, or
other formats should not be accepted.

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


Re: Handling 3 operands in an expression without raising an exception

2013-09-27 Thread Νίκος

Στις 27/9/2013 6:16 μμ, ο/η Denis McMahon έγραψε:

On Fri, 27 Sep 2013 12:19:53 +0300, Νίκος wrote:


This is my code as i have it at the moment:

ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or
os.environ.get('REMOTE_ADDR', "Cannot Resolve") ) try:
gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat')
city = gi.time_zone_by_addr( ipval )
host = socket.gethostbyaddr( ipval ) [0]
except socket.gaierror as e:
city = "Άγνωστη Πόλη"
host = "Άγνωστη Προέλευση"


Here is the basic problem: You're trying to do too many things at once in
a language you don't understand and without any understanding of the
fundamental underlying concepts of the systems that you're interfacing
with.

Break the task down into simpler steps and do the steps one at a time:

Calculate ipval

Calculate gi

If ipval is valid, calculate city, else give city a default value

If ipval is valid, calculate host, else give host a default value

Then consider which of the above needs to be contained within a try /
catch.

Finally, code them as 4 separate units of code, eg:

# instantiate geolocation by ip
gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat')

# calculate ipval
try:
 ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or
   os.environ.get('REMOTE_ADDR', "Cannot Resolve") )
except ( KeyError, TypeError ):
 ipval = some_default

# try and obtain time zone from ip
try:
 city = gi.time_zone_by_addr( ipval )
except (error type[s]):
 city = "Unknown City"

# try and obtain hostname from ip
try:
 host = socket.gethostbyaddr( ipval ) [0]
except ( socket.gaierror ):
 host = "Unknown Host"

Note that there is nothing special about writing it in as few lines as
code as possible. Writing it out in a way that is easy to understand and
follow helps make sure it actually works, and makes it a lot easier to
maintain in future.



Sure your method follows the the logic in a straighforward way 
step-by-step but i just dont want to spent almost 20 lines of code just 
to calculate 2 variables(city and host).


ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or 
os.environ.get('REMOTE_ADDR', "Cannot Resolve") )

city = "Άγνωστη Πόλη"
host = "Άγνωστη Προέλευση"
try:
gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat')
city = gi.time_zone_by_addr( ipval )
host = socket.gethostbyaddr( ipval ) [0]
except socket.gaierror as e:
	print( "metrites.py => (%s): " % lastvisit, repr( sys.exc_info() ), 
file=open('/tmp/err.out', 'w') )


The above code works in less lines of codes and because the assignment 
of the vars happen before the try:/except: block, if something fails 
during try: we can tell by looking at the values of city or host.


Also its being logged at the err.out too.
Only problem is that iam handlign address related issues and not the 
case of when gi fails.


But i dont know how to do that.

except (error type[s]): i saw in your code but iam not sure what exactly 
this is supposed to handle.

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


Re: Handling 3 operands in an expression without raising an exception

2013-09-27 Thread Neil Cerutti
On 2013-09-27, ??  wrote:
> Sure your method follows the the logic in a straighforward way
> step-by-step but i just dont want to spent almost 20 lines of
> code just to calculate 2 variables(city and host).

Sure, eating with my mouth is straightforward and step-by-step,
but I just want to shove the food directly into my stomach.

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


Re: Handling 3 operands in an expression without raising an exception

2013-09-27 Thread Grant Edwards
On 2013-09-27, ??  wrote:

> Sure your method follows the the logic in a straighforward way 
> step-by-step but i just dont want to spent almost 20 lines of code just 
> to calculate 2 variables(city and host).

Does your provider charge you per line of code?

If all that matters is the number of lines of code then use this:

  city,host = 0,0

Only _1_ nice short line of code.

Happy?

-- 
Grant Edwards   grant.b.edwardsYow! If Robert Di Niro
  at   assassinates Walter Slezak,
  gmail.comwill Jodie Foster marry
   Bonzo??
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Handling 3 operands in an expression without raising an exception

2013-09-27 Thread Joel Goldstick
On Fri, Sep 27, 2013 at 1:00 PM, Grant Edwards wrote:

> On 2013-09-27, ??  wrote:
>
> > Sure your method follows the the logic in a straighforward way
> > step-by-step but i just dont want to spent almost 20 lines of code just
> > to calculate 2 variables(city and host).
>
> Does your provider charge you per line of code?
>
> If all that matters is the number of lines of code then use this:
>
>   city,host = 0,0
>
> Only _1_ nice short line of code.
>
> Happy?
>
> --
> Grant Edwards   grant.b.edwardsYow! If Robert Di Niro
>   at   assassinates Walter
> Slezak,
>   gmail.comwill Jodie Foster marry
>Bonzo??
> --
> https://mail.python.org/mailman/listinfo/python-list
>


Better yet, don't write the program.  Zero lines of code, and every line
works perfectly.  It runs extremely fast too!

... or Nikos the annoyance, write it in apl


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


Re: Hostrange expansion

2013-09-27 Thread Joel Goldstick
On Fri, Sep 27, 2013 at 11:32 AM, Sam Giraffe  wrote:

> Hi,
>
> I need some help in expanding a hostrange as in: h[1-100].domain.comshould 
> get expanded into a list containing
> h1.domain.com to h100.domain.com. Is there a library that can do this for
> me? I also need to valid the range before I expand it, i.e., h[1*100].
> domain.com should not be accept, or other formats should not be accepted.
>

You can loop on the range and create the list by appending strings created
with the range using string substitution.  No library involved, just basic
python language features.  As to the validation problem, I don't think you
have defined it well enough to advise you on coding.

Why don't you specify exaction what is legal or not legal for your range,
write the code, show us what you  have, and someone can help you further.
My guess is the code can all be written in maybe 20 lines or so.

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


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


Re: Handling 3 operands in an expression without raising an exception

2013-09-27 Thread Mark Lawrence

On 27/09/2013 18:00, Grant Edwards wrote:

On 2013-09-27, ??  wrote:


Sure your method follows the the logic in a straighforward way
step-by-step but i just dont want to spent almost 20 lines of code just
to calculate 2 variables(city and host).


Does your provider charge you per line of code?

If all that matters is the number of lines of code then use this:

   city,host = 0,0

Only _1_ nice short line of code.

Happy?



Classic overengineering, fancy wasting two whole spaces and having such 
long names.  Surely c,h=0,0 is vastly superior?


--
Cheers.

Mark Lawrence

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


Re: Hostrange expansion

2013-09-27 Thread Peter Otten
Sam Giraffe wrote:

> I need some help in expanding a hostrange as in: h[1-100].domain.com
> should get expanded into a list containing h1.domain.com to
> h100.domain.com. Is there a library that can do this for me? I also need
> to valid the range before I expand it, i.e., h[1*100].domain.com should
> not be accept, or other formats should not be accepted.

To get you started:

import re
import itertools

def to_range(s, sep="-"):
"""
>>> to_range("9-11")
['9', '10', '11']
"""
lo, hi = s.split(sep)
return [str(i) for i in range(int(lo), int(hi)+1)]

def explode(s):
"""
>>> list(explode("h[3-5].com"))
['h3.com', 'h4.com', 'h5.com']
"""
parts = re.compile(r"(\[\d+-\d+\])").split(s)
parts[0::2] = [[p] for p in parts[0::2]]
parts[1::2] = [to_range(p[1:-1]) for p in parts[1::2]]
return ("".join(p) for p in itertools.product(*parts))

if __name__ == "__main__":
dom = "h[1-3]x[9-11].com"
print(dom)
for name in explode(dom):
print("{}".format(name))


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


Re: Handling 3 operands in an expression without raising an exception

2013-09-27 Thread Denis McMahon
On Fri, 27 Sep 2013 18:32:23 +0100, Mark Lawrence wrote:

> On 27/09/2013 18:00, Grant Edwards wrote:
>> On 2013-09-27, ??  wrote:
>>
>>> Sure your method follows the the logic in a straighforward way
>>> step-by-step but i just dont want to spent almost 20 lines of code
>>> just to calculate 2 variables(city and host).
>>
>> Does your provider charge you per line of code?
>>
>> If all that matters is the number of lines of code then use this:
>>
>>city,host = 0,0
>>
>> Only _1_ nice short line of code.
>>
>> Happy?
>>
>>
> Classic overengineering, fancy wasting two whole spaces and having such
> long names.  Surely c,h=0,0 is vastly superior?

Why not c=h=0

2 characters (28%) shorter!

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Handling 3 operands in an expression without raising an exception

2013-09-27 Thread Grant Edwards
On 2013-09-27, Denis McMahon  wrote:
> On Fri, 27 Sep 2013 18:32:23 +0100, Mark Lawrence wrote:
>
>> On 27/09/2013 18:00, Grant Edwards wrote:
>>> On 2013-09-27, ??  wrote:
>>>
 Sure your method follows the the logic in a straighforward way
 step-by-step but i just dont want to spent almost 20 lines of code
 just to calculate 2 variables(city and host).
>>>
>>> Does your provider charge you per line of code?
>>>
>>> If all that matters is the number of lines of code then use this:
>>>
>>>city,host = 0,0
>>>
>>> Only _1_ nice short line of code.
>>>
>>> Happy?
>>>
>>>
>> Classic overengineering, fancy wasting two whole spaces and having such
>> long names.  Surely c,h=0,0 is vastly superior?
>
> Why not c=h=0
>
> 2 characters (28%) shorter!

And 47% more opaque!

-- 
Grant Edwards   grant.b.edwardsYow! ... he dominates the
  at   DECADENT SUBWAY SCENE.
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Handling 3 operands in an expression without raising an exception

2013-09-27 Thread Joel Goldstick
On Fri, Sep 27, 2013 at 2:54 PM, Grant Edwards wrote:

> On 2013-09-27, Denis McMahon  wrote:
> > On Fri, 27 Sep 2013 18:32:23 +0100, Mark Lawrence wrote:
> >
> >> On 27/09/2013 18:00, Grant Edwards wrote:
> >>> On 2013-09-27, ??  wrote:
> >>>
>  Sure your method follows the the logic in a straighforward way
>  step-by-step but i just dont want to spent almost 20 lines of code
>  just to calculate 2 variables(city and host).
> >>>
> >>> Does your provider charge you per line of code?
> >>>
> >>> If all that matters is the number of lines of code then use this:
> >>>
> >>>city,host = 0,0
> >>>
> >>> Only _1_ nice short line of code.
> >>>
> >>> Happy?
> >>>
> >>>
> >> Classic overengineering, fancy wasting two whole spaces and having such
> >> long names.  Surely c,h=0,0 is vastly superior?
> >
> > Why not c=h=0
> >
> > 2 characters (28%) shorter!
>
> And 47% more opaque!
>
> --
> Grant Edwards   grant.b.edwardsYow! ... he dominates
> the
>   at   DECADENT SUBWAY SCENE.
>   gmail.com
> --
> https://mail.python.org/mailman/listinfo/python-list
>


better yet:  i=l=0

The names have even less meaning, and they are thin -- less space
-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Aide pour bien démarrer en Python

2013-09-27 Thread jonathan . corriveau
Je sais qu'il y a plein d'information à lire un peu partout, mais j'ai vraiment 
du mal à voir pourquoi Python est si fantastique...

Je m'explique

Pour moi python c'est un langage de script très cryptique avec des noms de 
méthodes courts, pas claire, dans une identation pas toujours facile à lire et 
qui me rappel (mauvais souvenir) le positionnement obligatoire des instructions 
en COBOL... Je viens d'un monde .Net où les noms de méthodes disent exactement, 
très précisemment ce que fait le code (quite à avoir un nom de 30 caractères)...

Dans les standards PEP-8, il y a beaucoup de standards qui vont de soit, c'est 
facile de comprendre pourquoi c'est comme ça. Mais, il y a plein de cas où, 
personnelement et pour probablement plusieurs développeurs qui viennent du 
monde JAVA ou .Net, c'est très illisible et même contre-intuitif... 

Outre l'aspect visuel, je trouve des codes d'exemples, prit dans un pain et 
dans un seul fichier, très mal découpés et ça devient très difficile de se 
retrouver pour savoir qui fait quoi... 

On voit partout Python est orienté objet, tout le tralala, mais dans ma tête, 
j'ai bien du mal à voir du code Python qui suit certaine règle à la Clean Code 
avec des patterns bien établient (IoC, DI, Repository, UnitOfWork)...

J'ai plus souvent l'impression de voir des SmartUI (anti-pattern) qui dépendent 
de la terre entière avec aucune réél separation of concern...

Ceci dit, j'essaie vraiment d'apprendre le python et j'aimerais bien le faire...
Pourriez-vous m'indiquer des bonnes ressources, documentation qui pourrait 
répondre à mes intérogations ?

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


Re: Download all youtube favorites with youtube-dl script

2013-09-27 Thread Bill

Thomas Kandler wrote:

On 26.09.2013 17:13, Bill wrote:

I have been using the script youtube-dl http://rg3.github.io/youtube-dl/

And I was wondering if there is a way to download all of a user's
favorites or uploads.

The script has a functionality to download all videos in a txt file. So
if there is a way using the youtube API or JSON (none of which I am
familiar with) to bring up a list of all these videos then it'd be a
simple case putting these urls into a file.

The problem is youtube displays favorites or user uploads in pages or
infinite scroll. So it is difficult to access them by the BeautifulSoup
module.


What do you suggest?


Regarding the uploads: most profiles do have something called 'Popular
Uploads' or 'Recent Uploads'. Hover with the mouse over the link, a
'play'-Button appears, click it, copy the URL (should have a &list
parameter), paste the URL in youtube-dl (or a txt-file) and it will
fetch all videos.

I am not sure if this works for favorites, too, but that's the way I do it.



Hi.

A screenshot would help me locate it.

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


Re: Aide pour bien démarrer en Python

2013-09-27 Thread Joel Goldstick
2013/9/27 

> Je sais qu'il y a plein d'information à lire un peu partout, mais j'ai
> vraiment du mal à voir pourquoi Python est si fantastique...
>
> Je m'explique
>
> Pour moi python c'est un langage de script très cryptique avec des noms de
> méthodes courts, pas claire, dans une identation pas toujours facile à lire
> et qui me rappel (mauvais souvenir) le positionnement obligatoire des
> instructions en COBOL... Je viens d'un monde .Net où les noms de méthodes
> disent exactement, très précisemment ce que fait le code (quite à avoir un
> nom de 30 caractères)...
>
> Dans les standards PEP-8, il y a beaucoup de standards qui vont de soit,
> c'est facile de comprendre pourquoi c'est comme ça. Mais, il y a plein de
> cas où, personnelement et pour probablement plusieurs développeurs qui
> viennent du monde JAVA ou .Net, c'est très illisible et même
> contre-intuitif...
>
> Outre l'aspect visuel, je trouve des codes d'exemples, prit dans un pain
> et dans un seul fichier, très mal découpés et ça devient très difficile de
> se retrouver pour savoir qui fait quoi...
>
> On voit partout Python est orienté objet, tout le tralala, mais dans ma
> tête, j'ai bien du mal à voir du code Python qui suit certaine règle à la
> Clean Code avec des patterns bien établient (IoC, DI, Repository,
> UnitOfWork)...
>
> J'ai plus souvent l'impression de voir des SmartUI (anti-pattern) qui
> dépendent de la terre entière avec aucune réél separation of concern...
>
> Ceci dit, j'essaie vraiment d'apprendre le python et j'aimerais bien le
> faire...
> Pourriez-vous m'indiquer des bonnes ressources, documentation qui pourrait
> répondre à mes intérogations ?
>
> Merci!
> --
> https://mail.python.org/mailman/listinfo/python-list
>

It seems that people in the .NET world don't seem to like python.  Maybe
the reverse is true.  All the things that .net or java people hate about
python, python people view as the best parts of the language.  But, if you
need to use python you can start with python.org.  There are many links to
documentation suitable for different skill levels.  Some of it is available
in French: https://wiki.python.org/moin/FrenchLanguage

good luck to you

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


Re: Download all youtube favorites with youtube-dl script

2013-09-27 Thread Thomas Kandler
On 27.09.2013 21:50, Bill wrote:
> Hi.
> 
> A screenshot would help me locate it.
> 
> Cheers

Sure. http://i.imgur.com/LvrNZYO.png

I don't thing *every* profile has this, but as I said, I use youtube-dl
quite often this way.

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


Re: Aide pour bien démarrer en Python

2013-09-27 Thread Vincent Vande Vyvre

Le 27/09/2013 21:57, Joel Goldstick a écrit :




2013/9/27 >


Je sais qu'il y a plein d'information à lire un peu partout, mais
j'ai vraiment du mal à voir pourquoi Python est si fantastique...

Je m'explique

Pour moi python c'est un langage de script très cryptique avec des
noms de méthodes courts, pas claire, dans une identation pas
toujours facile à lire et qui me rappel (mauvais souvenir) le
positionnement obligatoire des instructions en COBOL... Je viens
d'un monde .Net où les noms de méthodes disent exactement, très
précisemment ce que fait le code (quite à avoir un nom de 30
caractères)...

Dans les standards PEP-8, il y a beaucoup de standards qui vont de
soit, c'est facile de comprendre pourquoi c'est comme ça. Mais, il
y a plein de cas où, personnelement et pour probablement plusieurs
développeurs qui viennent du monde JAVA ou .Net, c'est très
illisible et même contre-intuitif...

Outre l'aspect visuel, je trouve des codes d'exemples, prit dans
un pain et dans un seul fichier, très mal découpés et ça devient
très difficile de se retrouver pour savoir qui fait quoi...

On voit partout Python est orienté objet, tout le tralala, mais
dans ma tête, j'ai bien du mal à voir du code Python qui suit
certaine règle à la Clean Code avec des patterns bien établient
(IoC, DI, Repository, UnitOfWork)...

J'ai plus souvent l'impression de voir des SmartUI (anti-pattern)
qui dépendent de la terre entière avec aucune réél separation of
concern...

Ceci dit, j'essaie vraiment d'apprendre le python et j'aimerais
bien le faire...
Pourriez-vous m'indiquer des bonnes ressources, documentation qui
pourrait répondre à mes intérogations ?

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


It seems that people in the .NET world don't seem to like python.  
Maybe the reverse is true.  All the things that .net or java people 
hate about python, python people view as the best parts of the 
language.  But, if you need to use python you can start with 
python.org . There are many links to documentation 
suitable for different skill levels.  Some of it is available in 
French: https://wiki.python.org/moin/FrenchLanguage


good luck to you

--
Joel Goldstick
http://joelgoldstick.com




Je te recommande : http://python.developpez.com/cours/apprendre-python3/

--
Vincent V.V.
Oqapy  . Qarte 
 . PaQager 

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


Re: card dealer

2013-09-27 Thread Dave Angel
On 27/9/2013 12:10, Denis McMahon wrote:

> On Fri, 27 Sep 2013 12:08:33 +, Dave Angel wrote:
>
>> i recall
>> writing a shuffle function in C decades ago, which took an array of (52)
>> unique items and put them in random order.
>
> Whenever I tried to write shuffles I came up against a fairly fundamental 
> limit:
>
> 52! > prng states
>
> Granted prngs seem to be better on the importing entropy from elsewhere 
> front these days.
>

in 1978, I implemented a random number generator that the OS sequenced
through between scheduling processes, so that any individual process
would be relatively safe from that phenomenon. Of course I was limited
to the precision of the math package - 10**13

-- 
DaveA


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


Re: Free Proxy site 2014

2013-09-27 Thread Dave Angel
On 27/9/2013 10:44, 23alagmy wrote:

> Free Proxy site 2014
> search is the first proxy supports proxy access blocked sites, browsing, and 
> downloads without restrictions and also conceal your identity Pencah by 100% 
> from the sites you visit
>
>

Sure, I'm going to trust going to a site recommended by a spammer who
doesn't know the language he's posting in.  Right.

-- 
DaveA


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


Re: card dealer

2013-09-27 Thread Ned Batchelder

On 9/27/13 12:10 PM, Denis McMahon wrote:

On Fri, 27 Sep 2013 12:08:33 +, Dave Angel wrote:


i recall
writing a shuffle function in C decades ago, which took an array of (52)
unique items and put them in random order.

Whenever I tried to write shuffles I came up against a fairly fundamental
limit:

52! > prng states

Granted prngs seem to be better on the importing entropy from elsewhere
front these days.



Python's PRNG holds plenty of state to handle card shuffling. Python's 
random number generator has a period of 2**19337-1, so it has that many 
states.  That is much larger than 52!, about 10**5933 times larger.  
(Unless I've botched the math...)


The other variable is how many states the initial seed can have.  If 
os.urandom is available, then it seeds with 16 bytes of OS-supplied 
randomness.  But 52! is about 2**226, so the 128 bits of seed isn't 
enough to make all shuffles possible.


You could seed a Random yourself with more bits if you really wanted to.

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


Re: Handling 3 operands in an expression without raising an exception

2013-09-27 Thread Νίκος

Στις 27/9/2013 8:00 μμ, ο/η Grant Edwards έγραψε:

On 2013-09-27, ??  wrote:


Sure your method follows the the logic in a straighforward way
step-by-step but i just dont want to spent almost 20 lines of code just
to calculate 2 variables(city and host).


Does your provider charge you per line of code?

If all that matters is the number of lines of code then use this:

   city,host = 0,0

Only _1_ nice short line of code.

Happy?



Well to tell the truth no matter what you say to me if something can be 
written in less lines than another implementation but still retain its 
simplicity and straightforward logic behind it i would prefer it!
I don't know why you think otherwise, especially people who are used to 
write Perl code(me being one of them) would agree with me!


But in this case i cant use your examples even if i wanted too and thats 
because the strings needed to be assigned to the 2 vars respectively are 
different.


city = "Άγνωστη Πόλη"
host = "Άγνωστη Προέλευση"

If they were to have the same string assigned to them it should be okey 
but they do not.


Or perhaps you can even still think of writing the above into 1-liner 
whatsoever!


I wouldn't be surprised if you can! :-)
--
https://mail.python.org/mailman/listinfo/python-list


walking a heapq nondestructively without duplicating?

2013-09-27 Thread Tim Chase
I've got a large heapq'ified list and want to walk it in-order
without altering it.  I get the "unsorted" heap'ish results if I just
do

  from heapq import heappush, heappop, nlargest, nsmallest
  my_heap = []
  for thing in lots_of_items():
heappush(thing)
  for item in my_heap:
...

To get them in-order, I can do something like

  while my_heap:
item = heappop(my_heap)
do_something(item)

to iterate over the items in order, but that destroys the original
heap. I can also do

  for item in nlargest(len(my_heap), my_heap): # or nsmallest()
do_something(item)

but this duplicates a potentially large list according to my
reading of the description for nlargest/nsmallest[1].  Is there a
handy way to non-destructively walk the heap (either in-order or
reversed) without duplicating its contents?

-tkc

[1] http://docs.python.org/2/library/heapq.html#heapq.nlargest







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


Re: Handling 3 operands in an expression without raising an exception

2013-09-27 Thread Dave Angel
On 27/9/2013 18:06, Νίκος wrote:


>
> city = "Άγνωστη Πόλη"
> host = "Άγνωστη Προέλευση"
>
> If they were to have the same string assigned to them it should be okey 
> but they do not.
>
> Or perhaps you can even still think of writing the above into 1-liner 
> whatsoever!

I already did earlier in this thread.  And you must have read the
message, because you replied to other parts of it.  it's the one where I
referred to code golf, and to APL.  About 12 hours ago, at 6:43 my time.

city, host = "Άγνωστη Πόλη", "Άγνωστη Προέλευση"

I still think it's foolish, but be my guest.

-- 
DaveA


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


Re: walking a heapq nondestructively without duplicating?

2013-09-27 Thread Ned Batchelder

On 9/27/13 6:22 PM, Tim Chase wrote:

I've got a large heapq'ified list and want to walk it in-order
without altering it.  I get the "unsorted" heap'ish results if I just
do

   from heapq import heappush, heappop, nlargest, nsmallest
   my_heap = []
   for thing in lots_of_items():
 heappush(thing)
   for item in my_heap:
 ...

To get them in-order, I can do something like

   while my_heap:
 item = heappop(my_heap)
 do_something(item)

to iterate over the items in order, but that destroys the original
heap. I can also do

   for item in nlargest(len(my_heap), my_heap): # or nsmallest()
 do_something(item)

but this duplicates a potentially large list according to my
reading of the description for nlargest/nsmallest[1].  Is there a
handy way to non-destructively walk the heap (either in-order or
reversed) without duplicating its contents?


If you add all your items at once, and then you want to walk over all 
the items, then don't use a heap.  Just put all your items in a list, 
and then sort it.  The advantage of a heap is that you can add items to 
it with little effort, delaying some of the work until when you need to 
get the items out.  It maintains a partially-sorted list that's good for 
insertion and popping.  You have different needs. Use a sorted list.


--Ned.


-tkc

[1] http://docs.python.org/2/library/heapq.html#heapq.nlargest









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


Help me with Python please (picture)

2013-09-27 Thread jae655
http://imgur.com/E6vrNs4


Can't seem to be getting an output.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with Python please (picture)

2013-09-27 Thread Gary Herron

On 09/27/2013 05:43 PM, jae...@gmail.com wrote:

http://imgur.com/E6vrNs4


Can't seem to be getting an output.


Please find a way to include the code in the email.   Also what evidence 
do you provide that it does not work?  What happened when you ran it?  
What did you expect to happen?  What were you trying to achieve?


Since you are asking volunteers to help, it would be polite to take the 
time to explain things carefully.



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


Re: Help me with Python please (picture)

2013-09-27 Thread Dave Angel
On 27/9/2013 20:43, jae...@gmail.com wrote:

> http://imgur.com/E6vrNs4
>
>
> Can't seem to be getting an output.

Please compose a text message containing a description of the
environment, the (small) code, and the expected results. This is a text
mailing list, and posting transient images on untrusted websites is
not likely to get you much help.

And when copying the code and the output, please use cut and paste; 
don't paraphrase or retype anything.

if you don't know how to capture the text, describe your environment,
and somebody will probably be able to help you.

-- 
DaveA


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


Re: Handling 3 operands in an expression without raising an exception

2013-09-27 Thread Chris Angelico
On Sat, Sep 28, 2013 at 8:06 AM, Νίκος  wrote:
> Well to tell the truth no matter what you say to me if something can be
> written in less lines than another implementation but still retain its
> simplicity and straightforward logic behind it i would prefer it!
> I don't know why you think otherwise, especially people who are used to
> write Perl code(me being one of them) would agree with me!

It's high time you stopped trying to write Perl code that runs under
the Python interpreter, and started writing Python code that runs
under the Python interpreter.

There are rules. You first learn the rules and learn to code within
them; then later, once you actually achieve some measure of
competence, you begin learning when to break the rules.

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


Re: Help me with Python please (picture)

2013-09-27 Thread Denis McMahon
On Fri, 27 Sep 2013 17:43:42 -0700, jae655 wrote:

> http://imgur.com/E6vrNs4

> Can't seem to be getting an output.

I can't see where your output statements are.

With no output statements, there is no output.

perhaps you want to assign the result of the function call to a variable, 
and then print the variable? Or perhaps not, perhaps you were going to do 
the output some other way?

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with Python please (picture)

2013-09-27 Thread John Ladasky
On Friday, September 27, 2013 5:43:42 PM UTC-7, jae...@gmail.com wrote:
> http://imgur.com/E6vrNs4
> 
> Can't seem to be getting an output.

Because you aren't printing anything!

One possible way to fix that is to change the line which reads...

random_characters(8)

to read...

print(random_characters(8))

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


Python Unit Tests

2013-09-27 Thread melwin9
Hey,

How do i go about coming up/coding tests for this program below. Not sure how 
to even approach writing about 5 tests for it.

Initially I had this for the test but its not working well.

Test was name test_guess.py (Code Below)

[code]
from unittest import TestCase 
import pexpect as pe 

import guess as g 
import random 

random_number = random.randrange(1, 10) 
correct = False 

class GuessTest(TestCase): 
def setUp(self): 
self.intro = 'I have chosen a number from 1-10' 
self.request = 'Guess a number: ' 
self.responseHigh = "That's too high." 
self.responseLow  = "That's too low." 
self.responseCorrect = "That's right!" 
self.goodbye = 'Goodbye and thanks for playing!' 

def test_main(self): 
#cannot execute main now because it will 
#require user input 
from guess import main 

def test_guessing_hi_low_4(self): 
# Conversation assuming number is 4 
child = pe.spawn('python guess.py') 
child.expect(self.intro,timeout=5) 
child.expect(self.request,timeout=5) 
child.sendline('5') 
child.expect(self.responseHigh,timeout=5) 
child.sendline('3') 
child.expect(self.responseLow,timeout=5) 
child.sendline('4') 
child.expect(self.responseCorrect,timeout=5) 
child.expect(self.goodbye,timeout=5) 


def __init__(self): 
self.number = random.randint(0,10) 
HIGH = 1 
LOW = 2 
OK = 3 

def guess(self, number): 
if number > self.number: 
 return self.HIGH 
if number < self.number: 
 return self.LOW 
return self.OK 

def test_guesstoolow(self): 
while not correct: 
guess = input("What could it be?") 
if guess == random_number: 
print "Congrats You Got It" 
correct = True 
elif guess > random_number: 
print "To High" 
elif guess < random_number: 
print "To Low" 
else: 
print "Try Again"  [/code]

Python code for game below

[code]
import random

intro = 'I have chosen a number from 1-10'
request = 'Guess a number: '
responseHigh = "That's too high."
responseLow  = "That's too low."
responseCorrect = "That's right!"
goodbye = 'Goodbye and thanks for playing!'

print(intro)

def main():
guessesTaken = 0
number = random.randint(1, 10)
while guessesTaken < 5:
print(request)
guess = input()
guess = int(guess)

guessesTaken = guessesTaken + 1

if guess < number:
print(responseLow) 

if guess > number:
print(responseHigh)

if guess == number:
break

if guess == number:
guessesTaken = str(guessesTaken)
print(responseCorrect + '! You guessed my number in ' + 
guessesTaken + ' guesses!')

if guess != number:
number = str(number)
print(goodbye + ' The number I was thinking of was ' + number)

##def main():
#print(intro)
 #   user_input = raw_input(request)
  #  print(responseHigh)
  #  print(request)
  #  user_input = raw_input(request)
  #  print(responseLow)
  #  user_input = raw_input(request)
  #  print(responseCorrect)
  #  print(goodbye)

if __name__ == '__main__':
main()[/code]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help me with Python please (picture)

2013-09-27 Thread Steven D'Aprano
On Fri, 27 Sep 2013 17:43:42 -0700, jae655 wrote:

> http://imgur.com/E6vrNs4
> 
> 
> Can't seem to be getting an output.

The problem with your code has to do with the code between pixel 
coordinates (29, 234) and (175, 249) approximately. If you open your 
image in a pixel editor, copy and paste that part out, run it through 
some OCR software, and then add "print " (including the space) before it, 
you will probably get the result you are after.

By the way, posting a picture of your code is thoughtless and rude to 
those contributors and programmers who are blind or partially sighted. If 
you post text, they can contribute using a screen-reader. If you post a 
picture, they're screwed. Even if you don't give two hoots for the blind, 
at least consider that maybe they can answer your question when nobody 
else can.

Why would we want to follow a link to look at your code, when we could 
read it right here in your message? We might not have access to imgur 
(many places block it). We cannot copy and paste your code to run it to 
see what it does, or make edits to it. If we want to describe parts of 
your code we have to re-type it, possibly introducing our own typos.

I really don't understand why you would take program code, which is text, 
and take a screenshot of it, then spend time blanking out parts of the 
screenshot. Text is *much* more useful for a programmer. It astonishes me 
that there is an entire subreddit on imgur dedicated to people who take 
screenshots of their code. What's wrong with them?

Could be worse -- at least you didn't take a photo of the screen with 
your phone, them email the picture to yourself, then take a screenshot of 
the photo in your mail client, then upload that screenshot to imgur, then 
take a screenshot of the picture on imgur, then post that screenshot here.


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


Re: Help me with Python please (picture)

2013-09-27 Thread Chris Angelico
On Sat, Sep 28, 2013 at 3:18 PM, Steven D'Aprano
 wrote:
> Could be worse -- at least you didn't take a photo of the screen with
> your phone, them email the picture to yourself, then take a screenshot of
> the photo in your mail client, then upload that screenshot to imgur, then
> take a screenshot of the picture on imgur, then post that screenshot here.

http://xkcd.com/763/

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


Re: Method not found: 'ServiceSettingSave' in Suds package

2013-09-27 Thread dieter
Anup Kandalkar  writes:

> I am trying to create service for the url:
>
>wsdl_url = https://avatax.avalara.net/Account/Accountsvc.wsdl
>
> But some error is coming:
>
>  svc = suds.client.Client(url=wsdl_url)
>   File "/usr/lib/python2.7/dist-packages/suds/client.py", line 114, in 
> __init__
> self.wsdl = reader.open(url)
>   File "/usr/lib/python2.7/dist-packages/suds/reader.py", line 152, in open
> d = self.fn(url, self.options)
>   File "/usr/lib/python2.7/dist-packages/suds/wsdl.py", line 158, in __init__
> self.resolve()
>   File "/usr/lib/python2.7/dist-packages/suds/wsdl.py", line 207, in resolve
> c.resolve(self)
>   File "/usr/lib/python2.7/dist-packages/suds/wsdl.py", line 660, in resolve
> self.resolvesoapbody(definitions, op)
>   File "/usr/lib/python2.7/dist-packages/suds/wsdl.py", line 686, in 
> resolvesoapbody
> ptop = self.type.operation(op.name)
>   File "/usr/lib/python2.7/dist-packages/suds/wsdl.py", line 525, in operation
> raise MethodNotFound(name)
> MethodNotFound: Method not found: 'ServiceSettingSave'

This looks to be a bug in the "wsdl". Somewhere, it refers to
"ServiceSettingSave" but there is no definition for it.

To analyse,
I would download the WSDL description (recursively, if
necessary to get the full description) and search there for
"ServiceSettingSave".

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


Re: card dealer

2013-09-27 Thread Steven D'Aprano
On Fri, 27 Sep 2013 17:40:46 -0400, Ned Batchelder wrote:

> On 9/27/13 12:10 PM, Denis McMahon wrote:
>> On Fri, 27 Sep 2013 12:08:33 +, Dave Angel wrote:
>>
>>> i recall
>>> writing a shuffle function in C decades ago, which took an array of
>>> (52) unique items and put them in random order.
>> Whenever I tried to write shuffles I came up against a fairly
>> fundamental limit:
>>
>> 52! > prng states
>>
>> Granted prngs seem to be better on the importing entropy from elsewhere
>> front these days.
>>
>>
> Python's PRNG holds plenty of state to handle card shuffling. Python's
> random number generator has a period of 2**19337-1, so it has that many
> states.  That is much larger than 52!, about 10**5933 times larger.
> (Unless I've botched the math...)

There's a warning about that in the docs:

http://docs.python.org/3/library/random.html#random.shuffle

[quote]
Note that for even rather small len(x), the total number of permutations 
of x is larger than the period of most random number generators; this 
implies that most permutations of a long sequence can never be generated.
[end quote]

If I've done that maths right, it turns out that 2025 is the largest 
number of items that a list can have for Python's default PRNG to 
generate every possible shuffle. But does it really matter? For most 
purposes, I'd say No. Even if you generated one trillion shuffles per 
second, you would have to keep shuffling for more than a trillion years 
before repeating yourself.

To be pedantic: a *lot* more than a trillion years. Approximately 
10**5789 trillion years. That's about a:

trillion trillion trillion trillion trillion trillion trillion trillion 
trillion trillion trillion trillion trillion trillion trillion trillion 
trillion trillion trillion trillion trillion trillion trillion trillion 
... and so on for 57 more lines ... years. 


So in practice it's not really relevant that some shuffles won't be 
generated. They'll be randomly distributed throughout the space of all 
possible shuffles, which is so large that you really won't notice the 
missing ones.


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


Re: Python Unit Tests

2013-09-27 Thread Dave Angel
On 28/9/2013 00:52, melw...@gmail.com wrote:

> Hey,
>

What version of Python are you using?  I'll assume 2.7, but you really
should specify it (and any other meaningful environment dependencies) in
your original query, the beginning of your thread.

For 2.7, the docs for unittest are at:

http://docs.python.org/2/library/unittest.html

> How do i go about coming up/coding tests for this program below. Not sure how 
> to even approach writing about 5 tests for it.
>
> Initially I had this for the test but its not working well.
>
> Test was name test_guess.py (Code Below)
>
> [code]
> from unittest import TestCase 
> import pexpect as pe 
>
> import guess as g 
> import random 
>
> random_number = random.randrange(1, 10) 
> correct = False 
>
> class GuessTest(TestCase): 
> def setUp(self): 
> self.intro = 'I have chosen a number from 1-10' 
> self.request = 'Guess a number: ' 
> self.responseHigh = "That's too high." 
> self.responseLow  = "That's too low." 
> self.responseCorrect = "That's right!" 
> self.goodbye = 'Goodbye and thanks for playing!' 

These strings don't change from one test to another.  Thus they could be
set in the __init__() method, and indeed could just be globals.  Or even
(horrors) imported from the guess module.  So in your tests, you might
refer to  g.intro, rather than self.intro   Or you might decide that the
content of the strings is not what you're testing, but rather the flow
of the logic.


> 
> def test_main(self): 
> #cannot execute main now because it will 
> #require user input 
> from guess import main 

No need for an import here.  Assuming you will be adding a call to
main(), you can just call it as  g.main(), since you imported g already
as a global.

> 
> def test_guessing_hi_low_4(self): 
> # Conversation assuming number is 4 
> child = pe.spawn('python guess.py') 
> child.expect(self.intro,timeout=5) 
> child.expect(self.request,timeout=5) 
> child.sendline('5') 
> child.expect(self.responseHigh,timeout=5) 
> child.sendline('3') 
> child.expect(self.responseLow,timeout=5) 
> child.sendline('4') 
> child.expect(self.responseCorrect,timeout=5) 
> child.expect(self.goodbye,timeout=5) 
>
>
> def __init__(self): 
> self.number = random.randint(0,10) 
> HIGH = 1 
> LOW = 2 
> OK = 3 

Those 3 statements do nothing useful.  They set 3 local variables which
are then immediately forgotten.  Presumably you meant:

   self.HIGH = 1
   self.LOW = 2
   self.OK = 3

>
> def guess(self, number): 
> if number > self.number: 
>  return self.HIGH 
> if number < self.number: 
>  return self.LOW 
> return self.OK 
>
> def test_guesstoolow(self): 

Nothing in this method tests any of the actual program

> while not correct: 
> guess = input("What could it be?") 
> if guess == random_number: 
> print "Congrats You Got It" 
> correct = True 
> elif guess > random_number: 
> print "To High" 
> elif guess < random_number: 
> print "To Low" 
> else: 
> print "Try Again"  [/code]
>
> Python code for game below
>
> [code]
> import random
>
> intro = 'I have chosen a number from 1-10'
> request = 'Guess a number: '
> responseHigh = "That's too high."
> responseLow  = "That's too low."
> responseCorrect = "That's right!"
> goodbye = 'Goodbye and thanks for playing!'
>
> print(intro)
>
> def main():
> guessesTaken = 0
> number = random.randint(1, 10)
> while guessesTaken < 5:
> print(request)
> guess = input()
> guess = int(guess)
>
> guessesTaken = guessesTaken + 1
>
> if guess < number:
> print(responseLow) 
>
> if guess > number:
> print(responseHigh)
>
> if guess == number:
> break
>
> if guess == number:
> guessesTaken = str(guessesTaken)
> print(responseCorrect + '! You guessed my number in ' + 
> guessesTaken + ' guesses!')
>
> if guess != number:
> number = str(number)
> print(goodbye + ' The number I was thinking of was ' + number)
>
> ##def main():
> #print(intro)
>  #   user_input = raw_input(request)
>   #  print(responseHigh)
>   #  print(request)
>   #  user_input = raw_input(request)
>   #  print(responseLow)
>   #  user_input = raw_input(request)
>   #  print(responseCorrect)
>   #  print(goodbye)
>
> if __name__ == '__main__':
> main()[/code]

According to https://en.wikipedia.org/wiki/Unit_testing:
"...one can view a unit as the smallest testable part of an application"

This is frequently a function, but certainly nothing smaller.  So  your
program is too monolithic to write multiple unit tests 

Weird bahaviour from shlex - line no

2013-09-27 Thread Daniel Stojanov
Can somebody explain this. The line number reported by shlex depends
on the previous token. I want to be able to tell if I have just popped
the last token on a line.




import shlex

first = shlex.shlex("word1 word2\nword3")
print first.get_token()
print first.get_token()
print "line no", first.lineno, "\n"

second = shlex.shlex("word1 word2,\nword3")
print second.get_token()
print second.get_token()
print second.get_token()
print "line no", second.lineno, "\n"


OUTPUT:
word1
word2
line no 2

word1
word2
,
line no 1
-- 
https://mail.python.org/mailman/listinfo/python-list