Re: Dummy Decoder Example (was Re: Parallel decoding lesson for you.)

2015-09-29 Thread Skybuck Flying

Hello,

(It is now 29 september 2015)

As promised here is Skybuck's Parallel Universal Code demonstration program.

This posting contains a Delphi and C/C++ version for you to learn from.

(I was kinda thinking of adding some kind of case statement/array and out of 
order execution/randomization to proof that the lines can be executed in any 
order, though I didn't come around to that (yet) been playing World of 
Warships =D at 1 fps to 30 fps lol)
(If anybody doubt that these lines can be executed out of order I may 
eventually add such a feature as welll.. maybe I will do it even for the fun 
of it ! ;))
(I was also maybe thinking of trying to through it all into a nice 
Tprocessor class with an actual thread to show it off as well... didn't come 
around to that yet either ;):))
(However if you clearly examine the indexes used you will discover that 
there is no overlap, all indexes are uniquely read and such... no 
write-read-write-read-sequential stuff going on... it can all be read in 
parallel... except for building rowoffset array).


// ** Begin of Delphi Program ***

program TestProgram;

{$APPTYPE CONSOLE}

{$R *.res}

uses
 System.SysUtils;

{

Skybuck's Parallel Universal Code, Demonstration program

version 0.01 created on 19 september 2015

This demonstration program will illustrate how to decode fields of data in 
parallel.


For this demonstration program bit fiddling will be avoided by allowing 1 
bit per array index to illustrate the general idea.


Also lengths may be stored by 1 integer per array index. In a real world 
scenerio it would be Skybuck Universally Encoded.


Skybuck's Parallel Universal Code, Design Document:

version 1 created on 16 september 2015 (after seeing another mentioning of 
IBM's processor MIL which makes me sick, as if decoding fields in parallel 
is hard ! LOL ;) :))


(I also wrote a little introductionary question for it see other file for it 
and I even learned something from it: Parallel decoding lesson for you.txt)


All bits of the fields are split up in such a way that the first bit of each 
field is right next to each other, the second bit of each field is also next 
to each other, and so forth.


Conceptually view:

First currently situation

Field A consists out of a1a2a3a4  (4 bits)
Field B consists out of b1b2b3  (3 bits)
Field C consists out of c1  (1 bit)
Field D consists out of d1d2d3d4d5d6  ( 6 bits)

These bits are stored as follows:

"First row":
a1b1c1d1

"Second row":
a2b2d2

"Third row":
a3b3d3

"Fourth row":
a4d4

"Fiveth row":
d5

"Sixth row":
d6

These rows will be stores sequentially as follows:
a1b1c1d1a2b2d2a3b3d4a4d4d5d6

Now the question is: How does a processor know where each row begins ? and 
how many bits of each field there is, the answers are given below:


The bit length of each row is stored preemptively/prefixed:

"First row": 4
"Second row": 3
"Third row": 3
"Fourth row": 2
"Fiveth row": 1
"Sixth row" : 1

Now for each row their offset can be computed:

First row starts at 0,
Second row starts at 0 + 4 = 4
Third row starts at 0 + 4 + 3 = 7
Fouth row starts at 0 + 4 + 3 + 3 = 10
Fiveth row starts at 0 + 4 + 3 + 3 + 2 = 12
Sixth row starts at 0 + 4+ 3 + 3+ 2 + 1 = 13

Let's check if this is true:

0   1   2   3   4   5   6   7   8   9   10 11 12 13
a1 b1 c1 d1 a2 b2 d2 a3 b3 d3 a4 d4 d5 d6

Bingo, all match.

The processor can compute the offsets of each row.

And thus the processor can reach each field in parallel as follows:

Read field A bit 0 at offset 0
Read field B bit 0 at offset 4
Read field C bit 0 at offset 7
Read field D bit 0 at offset 10

Now the question is how can the processor know when to stop reading ?

A marker/meta bit could be used like described in Skybuck's Universal Code 
version 1, which indicates if the field continues or stops.


These bits can be stored in the same way as the data bits above.

And thus for each data bit, a meta bit can be read as well.

This way the processor knows that C2 does not exist and can stop reading 
field C


For huffman codes that would not even be required, since the processor can 
see in the huffman tree when it reaches a leave/end node and then it will 
know the end of C was reached.


So marker/beta bits can be avoided by using Huffman codes ! Pretty neeto ! 
;) =D


However huffman has a drawback that some fields might get large, and may not 
be suited for rare information and modifications and so forth ! ;)


The last thing to do to make this usuable is to include another prefix field 
which indicates how many prefixes there are.


So final stream will look something like:

[Number of Fields][Set of Field Lengths][Set of Field Data Bits 
Intermixed/Parallel]


First field can be universally coded.
Second set of fields can be universally coded.
Third set of field contains data bits intermixed/in parallel.

Additional:

The problem can be solved by sorting the fields from largest to smallest 
field, so new stream looks like:
(sorting fr

Re: multiprocessing speedup

2015-09-29 Thread Peter Otten
Rita wrote:

> I am using the multiprocessing with apply_async to do some work. Each task
> takes a few seconds but I have several thousand tasks. I was wondering if
> there is a more efficient method and especially when I plan to operate on
> a
>  large memory arrays (numpy)
> 
> Here is what I have now
> 
> 
> import multiprocessing as mp
> import random
> 
> def f(x):
> count=0
> for i in range(x):
> x=random.random()
> y=random.random()
> if x*x + y*y<=1:
> count+=1
> 
> return count
> 
> def main():
> resultObj=[]
> n=1
> P=mp.Pool(2)
> for arg in xrange(n):
> resultObj.append(P.apply_async(f,(arg,)))
> P.close()
> P.join()
> result = [ i.get() for i in resultObj ]
> print sum(result)/(n)
> 
> if __name__=="__main__":
> main()

This is much too early to worry about speed. 
First write a working version. 
Then measure to identify the bottlenecks.
Then optimise the bottlenecks (if any) and only the bottlenecks.

> 1) Does multiprocessing do a fork for each task?

I don't think so. You can see the when you modify your script to return the 
process id (there will only be two).

But the data has to be passed around.

> 2) If so, I assume thats costly due to setup and teardown. Would this be
> the case?

I don't think so.

> 3) I plan to pass large arrays to function,f, therefore is there a more
> efficient method to achieve this?

Where do these arrays come from? If they are coming from a file could you 
use separate scripts to operate on part(s) of the file(s)? 

Of course such considerations are moot if most of time is spent to process 
an array rather than pass it around. Which brings us back to the first and 
foremost point:

This is much too early to worry about speed.

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


Create a .lua fle from Python

2015-09-29 Thread Ariel Argañaraz
Hi,
This is my first post, I would like to know if a library that can help me
with this.


I want to parse a XML fle with Python and save the data into a Lua table
called for example "newTable", then I want to create a "table.lua" fle with
the "newTable" write on it.


for example:

the XML fle: cities.xml


 
  BuenosAires
  30
  

  Seatle
  25




And  I want to create a cities_temp.lua file

cities_temps ={
["Buenos Aires"] = 30,
["Seatle"] = 25,
}


Is that posible to do with LUPA (https://pypi.python.org/pypi/lupa)?? In
the docs I read that you can create lua tables but I did not see if there
is a way to create a .lua file with that table.


I could do it with python writing to a file line per line but i want some
more elegant.

Can anyone give some help?

Thanks.

-- 
Ariel Argañaraz
-- 
https://mail.python.org/mailman/listinfo/python-list


Check if a given value is out of certain range

2015-09-29 Thread Laxmikant Chitare
Hi,

I know there is an elegant way to check if a given value is within certain
range.
Example - To check if x is between zero and ten, I can do 0 < x 10.

Is there any similar elegant way to check if a value is out of certain
range?
Example - To check if x is either less than zero or greater than ten?
Right now I am using x < 0 or x > 10.

Regards,
Laxmikant
-- 
https://mail.python.org/mailman/listinfo/python-list


PY3.5 and nnumpy and scipy installation problem

2015-09-29 Thread Ek Esawi
Hi All again—


Thanks to all who have provided excellent tips for installing Python,
Numpy, Scipy, etc. Paul suggested the use Anaconda which proved to be the
best and easiest way for me.


If I may add I stumbled on an academic site that spells out in great
details how to install Python, numpy, scipy and others which helped me
greatly. For any installation issue here is the link


http://www.southampton.ac.uk/~fangohr/blog/installation-of-python-spyder-numpy-sympy-scipy-pytest-matplotlib-via-anaconda.html


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


Re: Check if a given value is out of certain range

2015-09-29 Thread Chris Angelico
On Tue, Sep 29, 2015 at 2:46 PM, Laxmikant Chitare
 wrote:
> Hi,
>
> I know there is an elegant way to check if a given value is within certain
> range.
> Example - To check if x is between zero and ten, I can do 0 < x 10.
>
> Is there any similar elegant way to check if a value is out of certain
> range?
> Example - To check if x is either less than zero or greater than ten?
> Right now I am using x < 0 or x > 10.

You can simply negate the condition:

not 0 <= x <= 10

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


Issue: cannot successfully install Python 3 on Windows 7

2015-09-29 Thread Gilad Mayani
Dear Python staff,

I am trying to install the latest version of Python 3 on my machine, in
which I already have Python 2.7.3 installed.
I did this by downloading the installer from the 'Download Python 3.5.0'
button from https://www.python.org/downloads/.
BTW, the installer installs the 32-bit Python version.

The installation seems to run smoothly, but when I try to then open Python
(by running "py -3" from the command line or opening the Python 3 IDLE)
I always get this message:

> the program can't start because api-ms-win-crt-runtime-I1-1-0.dll is
> missing from your computer.


I have trying a few times via the installer to repair the installation,
uninstall & re-install and restart my computer between the installations.
I also ran Windows updates and tried installing with the Python 3.5.0
Windows x86-64 executable installer (
https://www.python.org/ftp/python/3.5.0/python-3.5.0-amd64.exe) instead,
with the same results.

My machine details are:
OS Name Microsoft Windows 7 Home Premium Version 6.1.7601 Service Pack 1
Build 7601 System Type x64-based PC Processor Intel(R) Core(TM) i7-2630QM
CPU @ 2.00GHz, 2001 Mhz, 4 Core(s), 8 Logical Processor(s) BIOS
Version/Date Dell
Inc. A02, 2/3/2011 SMBIOS Version 2.6

Do you know how this can be solved?
Thanks a lot for your help!
Gilad Mayani.
-- 
https://mail.python.org/mailman/listinfo/python-list


Question re class variable

2015-09-29 Thread plewto
I have a perplexing problem with Python 3 class variables. I wish to generate 
an unique ID each time an instance of GameClass is created. There are two 
versions of the __gen_id method with test run results for each listed below the 
code. 

Originally I used the version which is now commented out. When a new instance 
was created it created an ID by appending the value of __instance_counter to 
the class name, it then checked the contents of of __instatance_registrty to 
see if this ID was already in use. If so it incremented the counter until it 
found an unused ID. This version works exactly as I expected.

Later I decided to get rid of __instance_registry and rely solely on the 
restricted access to __instance_counter and the fact that it is monotonically 
increasing to generate IDs. I wrote the second, simpler version of __gen_id to 
that end, but it doesn't work!  No doubt I'm overlooking something very simple 
here but I'm not seeing it. 

Any help appreciated. 


class GameObject:

# __instance_registry = {"":None}
__instance_counter = 0

def __init__(self, name):
self.__name = str(name)
self.__id = self.__gen_id()

# def __gen_id(self):
# ty = self.__class__.__name__
# id = ''
# while id in self.__instance_registry:
# id = '%s_%d' % (ty, self.__instance_counter)
# self.__instance_counter += 1
# self.__instance_registry[id] = self
# return id

def __gen_id(self):
ty = self.__class__.__name__
id = '%s_%d' % (ty, self.__instance_counter)
self.__instance_counter += 1
return id

def __str__(self):
return "name = '%s'   id = '%s'" % (self.__name, self.__id)  


go1 = GameObject("GO1")
go2 = GameObject("GO2")
go3 = GameObject("GO3")
print(go1)
print(go2)
print(go3)


# Results with original __gen_id method
# name = 'GO1'   id = 'GameObject_0'
# name = 'GO2'   id = 'GameObject_1'
# name = 'GO3'   id = 'GameObject_2'


# Results with new simpler __gen_id method, __instance_counter not being 
incremented
# name = 'GO1'   id = 'GameObject_0'
# name = 'GO2'   id = 'GameObject_0'
# name = 'GO3'   id = 'GameObject_0'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question re class variable

2015-09-29 Thread alister
On Tue, 29 Sep 2015 02:27:23 -0700, plewto wrote:

> I have a perplexing problem with Python 3 class variables. I wish to
> generate an unique ID each time an instance of GameClass is created.
> There are two versions of the __gen_id method with test run results for
> each listed below the code.
> 
> Originally I used the version which is now commented out. When a new
> instance was created it created an ID by appending the value of
> __instance_counter to the class name, it then checked the contents of of
> __instatance_registrty to see if this ID was already in use. If so it
> incremented the counter until it found an unused ID. This version works
> exactly as I expected.
> 
> Later I decided to get rid of __instance_registry and rely solely on the
> restricted access to __instance_counter and the fact that it is
> monotonically increasing to generate IDs. I wrote the second, simpler
> version of __gen_id to that end, but it doesn't work!  No doubt I'm
> overlooking something very simple here but I'm not seeing it.
> 
> Any help appreciated.
> 
> 
> class GameObject:
> 
> # __instance_registry = {"":None}
> __instance_counter = 0
> 
> def __init__(self, name):
> self.__name = str(name)
> self.__id = self.__gen_id()
> 
> # def __gen_id(self):
> # ty = self.__class__.__name__
> # id = ''
> # while id in self.__instance_registry:
> # id = '%s_%d' % (ty, self.__instance_counter)
> # self.__instance_counter += 1 #
> self.__instance_registry[id] = self # return id
> 
> def __gen_id(self):
> ty = self.__class__.__name__
> id = '%s_%d' % (ty, self.__instance_counter)
> self.__instance_counter += 1 return id
> 
> def __str__(self):
> return "name = '%s'   id = '%s'" % (self.__name, self.__id)
> 
> 
> go1 = GameObject("GO1")
> go2 = GameObject("GO2")
> go3 = GameObject("GO3")
> print(go1)
> print(go2)
> print(go3)
> 
> 
> # Results with original __gen_id method # name = 'GO1'   id =
> 'GameObject_0'
> # name = 'GO2'   id = 'GameObject_1'
> # name = 'GO3'   id = 'GameObject_2'
> 
> 
> # Results with new simpler __gen_id method, __instance_counter not being
> incremented # name = 'GO1'   id = 'GameObject_0'
> # name = 'GO2'   id = 'GameObject_0'
> # name = 'GO3'   id = 'GameObject_0'

why reinvent the wheel?
why not simply use pythons builtin id function?
each new instance of an object is automatically assigned a unique ID


-- 
I'm a soldier, not a diplomat.  I can only tell the truth.
-- Kirk, "Errand of Mercy", stardate 3198.9
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question re class variable

2015-09-29 Thread Antoon Pardon
Op 29-09-15 om 11:27 schreef [email protected]:
> I have a perplexing problem with Python 3 class variables. I wish to generate 
> an unique ID each time an instance of GameClass is created. There are two 
> versions of the __gen_id method with test run results for each listed below 
> the code.

The problem is that in python you can't change a class variable through an 
instance. The moment you
try, you create an instance attribute.

> class GameObject:
>
> # __instance_registry = {"":None}
> __instance_counter = 0
> 
> def __init__(self, name):
> self.__name = str(name)
> self.__id = self.__gen_id()
>
> def __gen_id(self):
> ty = self.__class__.__name__
> id = '%s_%d' % (ty, self.__instance_counter)
> self.__instance_counter += 1

This last line doesn't work as expected. What happens is equivallent to
the following.

  self.__instance_counter = self.__instance_counter + 1

But the self.__instance_counter are two different things here. On the right hand
python finds that self has no __instance_counter attribute so it will fetch the
value from the class.

However on the left hand, python will create an attribute for self and assign 
the
value to it. Python will not rebind the class variable.

-- 
Antoon Pardon 

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


Re: Question re class variable

2015-09-29 Thread jmp

On 09/29/2015 11:27 AM, [email protected] wrote:

I have a perplexing problem with Python 3 class variables.


Your problem is that when assigning values to your class attribute, you 
are actually creating a instance attribute.



class Foo:
  bar = "I'm a class attribute"
  def __init__(self):
self.bar = "I'm an instance attribute"

  def foo(self):
print self.bar
print Foo.bar
# this is how you set a class attribute from an instance
Foo.bar = "I am still a class attribute"
print Foo.bar

Foo.foo()

I'm an instance attribute
I'm a class attribute
I am still a class attribute


What can be confusing is that assuming you never use the same name for a 
class an instance attribute (that would be bad code), you can access

your class attribute from the instance:

class Foo:
  bar = "I'm a class attribute"
  def foo(self):
# python will look into the class scope if not found in the instance
print self.bar # this is not an assignment so we're fine

Foo.foo()
I'm an class attribute

As side note and unrelated topic, your are using name mangling 
(attribute starting with __), are you sure you need it ? You need a 
strong motive to use this feature otherwise you're making things 
difficult for yourself without any benefit.


Finally here's how I'd code your id, to give some idea on alternative ways:

class GameObject:

  @property
  def id(self):
return id(self) #use the builtin id function

print GameObject().id

Cheers,

JM

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


Re: Question re class variable

2015-09-29 Thread jmp

On 09/29/2015 01:02 PM, jmp wrote:

class GameObject:

   @property
   def id(self):
 return id(self) #use the builtin id function

print GameObject().id

Cheers,

JM


I should add that until you don't serialize your object you're fine.

If you need to serialize it, you may want to look at 
https://docs.python.org/3/library/uuid.html


import uuid

class GameObject:

  def __init__(self):
self._id = None

  @property
  def id(self):
if self._id is None:
  # make a UUID based on the host ID and current time
  self._id = uuid.uuid1()
return self._id

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


Re: Question re class variable

2015-09-29 Thread Anssi Saari
Antoon Pardon  writes:

> Op 29-09-15 om 11:27 schreef [email protected]:
>> I have a perplexing problem with Python 3 class variables. I wish to
>> generate an unique ID each time an instance of GameClass is
>> created. There are two versions of the __gen_id method with test run
>> results for each listed below the code.
>
> The problem is that in python you can't change a class variable through an 
> instance. The moment you
> try, you create an instance attribute.

That much is clear but why does his other version of __gen_id() work
(after a fashion)? It doesn't increment the class variable but the
instances get an incremental id.

The function was like this:

def __gen_id(self):
ty = self.__class__.__name__
id = ''
while id in self.__instance_registry:
id = '%s_%d' % (ty, self.__instance_counter)
self.__instance_counter += 1
self.__instance_registry[id] = self
return id

Also, is there any problem with incrementing
GameObject.__instance_counter from __gen_id()? I guess not?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Create a .lua fle from Python

2015-09-29 Thread Laura Creighton
In a message of Mon, 28 Sep 2015 18:41:09 -0300, Ariel Argañaraz writes:
>Hi,
>This is my first post, I would like to know if a library that can help me
>with this.
>
>
>I want to parse a XML fle with Python and save the data into a Lua table
>called for example "newTable", then I want to create a "table.lua" fle with
>the "newTable" write on it.
>
>
>for example:
>
>the XML fle: cities.xml
>
>
> 
>  BuenosAires
>  30
>  
>
>  Seatle
>  25
>
>
>
>
>And  I want to create a cities_temp.lua file
>
>cities_temps ={
>["Buenos Aires"] = 30,
>["Seatle"] = 25,
>}
>
>
>Is that posible to do with LUPA (https://pypi.python.org/pypi/lupa)?? In
>the docs I read that you can create lua tables but I did not see if there
>is a way to create a .lua file with that table.
>
>
>I could do it with python writing to a file line per line but i want some
>more elegant.
>
>Can anyone give some help?
>
>Thanks.
>
>-- 
>Ariel Argañaraz

Lupa is a partial re-write of lunatic python.
https://pypi.python.org/pypi/lunatic-python
with docs here:
http://labix.org/lunatic-python

and maybe that can do what you want.

But I don't know why you need to involve python at all.  Lua has
perfectly good xml parsers, indeed like python -- perhaps too many
of them.  Can't you just use lua?

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


Re: Question re class variable

2015-09-29 Thread Antoon Pardon
Op 29-09-15 om 13:17 schreef Anssi Saari:
> Antoon Pardon  writes:
>
>> Op 29-09-15 om 11:27 schreef [email protected]:
>>> I have a perplexing problem with Python 3 class variables. I wish to
>>> generate an unique ID each time an instance of GameClass is
>>> created. There are two versions of the __gen_id method with test run
>>> results for each listed below the code.
>> The problem is that in python you can't change a class variable through an 
>> instance. The moment you
>> try, you create an instance attribute.
> That much is clear but why does his other version of __gen_id() work
> (after a fashion)? It doesn't increment the class variable but the
> instances get an incremental id.
>
> The function was like this:
>
> def __gen_id(self):
> ty = self.__class__.__name__
> id = ''
> while id in self.__instance_registry:
> id = '%s_%d' % (ty, self.__instance_counter)
> self.__instance_counter += 1
> self.__instance_registry[id] = self
> return id

Because you check against the class variable __instance_registry. That variable
isn't rebound, it is mutated, so it remains a class variable and can thus be 
used
to check which id's are already in use. So you increment your counter until the
corresponding id is not in the __instance_registry.

-- 
Antoon Pardon. 

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


Re: Question re class variable

2015-09-29 Thread Steven D'Aprano
On Tue, 29 Sep 2015 09:17 pm, Anssi Saari wrote:

[...]
>> The problem is that in python you can't change a class variable through
>> an instance. The moment you try, you create an instance attribute.
> 
> That much is clear but why does his other version of __gen_id() work
> (after a fashion)? It doesn't increment the class variable but the
> instances get an incremental id.
> 
> The function was like this:
> 
> def __gen_id(self):
> ty = self.__class__.__name__
> id = ''
> while id in self.__instance_registry:
> id = '%s_%d' % (ty, self.__instance_counter)
> self.__instance_counter += 1
> self.__instance_registry[id] = self
> return id


This works because it doesn't assign to self.__instance_registry itself, it
assigns to an item within the existing self.__instance_registry. So the
registry object (a dict?) gets modified in place, not re-bound or shadowed
by an instance attribute of the same name.



-- 
Steven

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


Re: Issue: cannot successfully install Python 3 on Windows 7

2015-09-29 Thread Gisle Vanem

Gilad Mayani wrote:


I always get this message:

the program can't start because api-ms-win-crt-runtime-I1-1-0.dll is 
missing from your computer.


Is that really an 'I' in there? The .dll should really
be named:
  %SystemRoot%\system32\api-ms-win-crt-runtime-l1-1-0.dll

with an lower-case 'l'. (This .dll is itself a forwarder .dll to
ucrtbase.dll).

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


[ANN] pythenv

2015-09-29 Thread casa
Pythenv runs a Python script creating a virtualenv on the fly. Requirements may 
be passed as a requirements file or embedded in the Python script in a 
dedicated comment:

# requirements: foo==1.2.3, bar

This project is on Github:

https://github.com/c4s4/pythenv

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


Re: multiprocessing speedup

2015-09-29 Thread Oscar Benjamin
On Tue, 29 Sep 2015 at 02:22 Rita  wrote:

> I am using the multiprocessing with apply_async to do some work. Each task
> takes a few seconds but I have several thousand tasks. I was wondering if
> there is a more efficient method and especially when I plan to operate on a
>  large memory arrays (numpy)
>

> Here is what I have now
>
import multiprocessing as mp
> import random
>
> def f(x):
> count=0
> for i in range(x):
> x=random.random()
> y=random.random()
> if x*x + y*y<=1:
> count+=1
>
> return count
>

I assume you're using the code shown as a toy example of playing with the
multiprocessing module? If not then the function f can be made much more
efficient.

The problem is that while it's good that you have distilled your problem
into a simple program for testing it's not really possible to find a more
efficient way without finding the bottleneck which means looking at the
full problem.

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


Re: Issue: cannot successfully install Python 3 on Windows 7

2015-09-29 Thread Oscar Benjamin
On Tue, 29 Sep 2015 at 10:22 Gilad Mayani  wrote:

> Dear Python staff,
>
> I am trying to install the latest version of Python 3 on my machine, in
> which I already have Python 2.7.3 installed.
> I did this by downloading the installer from the 'Download Python 3.5.0'
> button from https://www.python.org/downloads/.
> BTW, the installer installs the 32-bit Python version.
>
> The installation seems to run smoothly, but when I try to then open Python
> (by running "py -3" from the command line or opening the Python 3 IDLE)
> I always get this message:
>
>> the program can't start because api-ms-win-crt-runtime-I1-1-0.dll is
>> missing from your computer.
>
> Do you know how this can be solved?
>

It seems there are some teething problems with Python 3.5 on Windows.
What's happening here is probably a bug in Python 3.5. It would be great if
you could report it to the issue tracker:

bugs.python.org 

In the meantime I suspect that you will have better luck installing Python
3.4.

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


Re: Question re class variable

2015-09-29 Thread John Gordon
In  alister 
 writes:

> why not simply use pythons builtin id function?
> each new instance of an object is automatically assigned a unique ID

It's only guaranteed to be unique for objects that exist at the same time.

If an object is created and destroyed and then another new object is
created, the ID of those two objects can be the same.

-- 
John Gordon   A is for Amy, who fell down the stairs
[email protected]  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Create a .lua fle from Python

2015-09-29 Thread jmp

On 09/28/2015 11:41 PM, Ariel Argañaraz wrote:

Hi,
This is my first post, I would like to know if a library that can help
me with this.


I want to parse a XML fle with Python and save the data into a Lua table
called for example "newTable", then I want to create a "table.lua" fle
with the "newTable" write on it.



And  I want to create a cities_temp.lua file

cities_temps ={
["Buenos Aires"] = 30,
["Seatle"] = 25,
}
Can anyone give some help?

Thanks.

--
Ariel Argañaraz


Use an xml parser to fetch the data from the xml file and use a template 
engine to generate the lua code.


for instance, using bs4 (beautifulsoup) for xml and jinja2 for the 
template engine:


import bs4
import jinja2

xml = """
 
  BuenosAires
  30
  

  Seatle
  25

"""

lua_template = """
cities_temps ={
{%- for city, temp in cities.iteritems() %}
["{{city}}"] = {{temp}},
{%- endfor %}
}"""

xmlp = bs4.BeautifulSoup(xml, 'xml')
# from xml to python dictionary
data = {city.find('name').string:city.find('temperature').string for 
city in xmlp.findAll('city')}

# from python dictionary to lua
print jinja2.Template(lua_template).render(cities=data)


will yield (python 2.7):

cities_temps ={
["BuenosAires"] = 30,
["Seatle"] = 25,
}

Cheers,

jm



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


Re: Check if a given value is out of certain range

2015-09-29 Thread Rob Gaddi
On Tue, 29 Sep 2015 10:16:04 +0530, Laxmikant Chitare wrote:

> Hi,
> 
> I know there is an elegant way to check if a given value is within
> certain range.
> Example - To check if x is between zero and ten, I can do 0 < x 10.
> 
> Is there any similar elegant way to check if a value is out of certain
> range?
> Example - To check if x is either less than zero or greater than ten?
> Right now I am using x < 0 or x > 10.
> 
> Regards,
> Laxmikant

not (0 <= x <= 10)



-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Create a .lua fle from Python

2015-09-29 Thread Peter Otten
jmp wrote:

> On 09/28/2015 11:41 PM, Ariel Argañaraz wrote:
>> Hi,
>> This is my first post, I would like to know if a library that can help
>> me with this.
>>
>>
>> I want to parse a XML fle with Python and save the data into a Lua table
>> called for example "newTable", then I want to create a "table.lua" fle
>> with the "newTable" write on it.
> 
>> And  I want to create a cities_temp.lua file
>>
>> cities_temps ={
>> ["Buenos Aires"] = 30,
>> ["Seatle"] = 25,
>> }
>> Can anyone give some help?
>>
>> Thanks.
>>
>> --
>> Ariel Argañaraz
> 
> Use an xml parser to fetch the data from the xml file and use a template
> engine to generate the lua code.
> 
> for instance, using bs4 (beautifulsoup) for xml and jinja2 for the
> template engine:
> 
> import bs4
> import jinja2
> 
> xml = """
>   
>BuenosAires
>30
>
> 
>Seatle
>25
> 
> """
> 
> lua_template = """
> cities_temps ={
> {%- for city, temp in cities.iteritems() %}
> ["{{city}}"] = {{temp}},
> {%- endfor %}
> }"""
> 
> xmlp = bs4.BeautifulSoup(xml, 'xml')
> # from xml to python dictionary
> data = {city.find('name').string:city.find('temperature').string for
> city in xmlp.findAll('city')}
> # from python dictionary to lua
> print jinja2.Template(lua_template).render(cities=data)
> 
> 
> will yield (python 2.7):
> 
> cities_temps ={
> ["BuenosAires"] = 30,
> ["Seatle"] = 25,
> }

Is Ariel's xml file user-supplied? If so, how does your suggestion prevent 
the resulting lua script from executing arbitrary code?

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


Re: [ANN] pythenv

2015-09-29 Thread Facundo Batista
On Tue, Sep 29, 2015 at 10:14 AM,   wrote:

> Pythenv runs a Python script creating a virtualenv on the fly. Requirements 
> may be passed as a requirements file or embedded in the Python script in a 
> dedicated comment:
>
> # requirements: foo==1.2.3, bar
>
> This project is on Github:
>
> https://github.com/c4s4/pythenv

Hi Michel!

You may be interested in fades:

 https://pypi.python.org/pypi/fades

fades does something similar, but also support receivng the parameters
one by one in comand line, or through a requirements.txt file, or in a
comment in the script, or in the scripts docstring.

It also supports running any installed python version, even ipython.

And you're not forced to run a python script! you can open an
interactive interpreter inside the virtualenv, or directly execute
anything inside the virtualenv.

Regards,

-- 
.Facundo

Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/
Twitter: @facundobatista
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Check if a given value is out of certain range

2015-09-29 Thread Mark Lawrence

On 29/09/2015 17:48, Rob Gaddi wrote:

On Tue, 29 Sep 2015 10:16:04 +0530, Laxmikant Chitare wrote:


Hi,

I know there is an elegant way to check if a given value is within
certain range.
Example - To check if x is between zero and ten, I can do 0 < x 10.

Is there any similar elegant way to check if a value is out of certain
range?
Example - To check if x is either less than zero or greater than ten?
Right now I am using x < 0 or x > 10.

Regards,
Laxmikant


not (0 <= x <= 10)



Yuck.

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

Mark Lawrence

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


Re: Check if a given value is out of certain range

2015-09-29 Thread Random832
On Tue, Sep 29, 2015, at 16:32, Mark Lawrence wrote:
> On 29/09/2015 17:48, Rob Gaddi wrote:
> > On Tue, 29 Sep 2015 10:16:04 +0530, Laxmikant Chitare wrote:
> >
> >> Hi,
> >>
> >> I know there is an elegant way to check if a given value is within
> >> certain range.
> >> Example - To check if x is between zero and ten, I can do 0 < x 10.
> >>
> >> Is there any similar elegant way to check if a value is out of certain
> >> range?
> >> Example - To check if x is either less than zero or greater than ten?
> >> Right now I am using x < 0 or x > 10.
> >>
> >> Regards,
> >> Laxmikant
> >
> > not (0 <= x <= 10)
> >
> 
> Yuck.

How about x not in range(11)?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Check if a given value is out of certain range

2015-09-29 Thread Ian Kelly
On Tue, Sep 29, 2015 at 3:04 PM, Random832  wrote:
> How about x not in range(11)?

That's fine as long as x is known to only take integral values.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Check if a given value is out of certain range

2015-09-29 Thread Emile van Sebille

On 9/29/2015 2:04 PM, Random832 wrote:

On Tue, Sep 29, 2015, at 16:32, Mark Lawrence wrote:




not (0 <= x <= 10)



Yuck.


How about x not in range(11)?



x = 5.5

Emile



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


Re: Check if a given value is out of certain range

2015-09-29 Thread Denis McMahon
On Tue, 29 Sep 2015 10:16:04 +0530, Laxmikant Chitare wrote:

> Is there any similar elegant way to check if a value is out of certain
> range?

What about:

if not (0 < x < 10):

-- 
Denis McMahon, [email protected]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: multiprocessing speedup

2015-09-29 Thread Rita
Thanks for the responses.

I will create another thread to supply a more realistic example.


On Tue, Sep 29, 2015 at 10:12 AM, Oscar Benjamin  wrote:

> On Tue, 29 Sep 2015 at 02:22 Rita  wrote:
>
>> I am using the multiprocessing with apply_async to do some work. Each
>> task takes a few seconds but I have several thousand tasks. I was wondering
>> if there is a more efficient method and especially when I plan to operate
>> on a  large memory arrays (numpy)
>>
>
>> Here is what I have now
>>
> import multiprocessing as mp
>> import random
>>
>> def f(x):
>> count=0
>> for i in range(x):
>> x=random.random()
>> y=random.random()
>> if x*x + y*y<=1:
>> count+=1
>>
>> return count
>>
>
> I assume you're using the code shown as a toy example of playing with the
> multiprocessing module? If not then the function f can be made much more
> efficient.
>
> The problem is that while it's good that you have distilled your problem
> into a simple program for testing it's not really possible to find a more
> efficient way without finding the bottleneck which means looking at the
> full problem.
>
> --
> Oscar
>



-- 
--- Get your facts first, then you can distort them as you please.--
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Check if a given value is out of certain range

2015-09-29 Thread Steven D'Aprano
On Wed, 30 Sep 2015 07:07 am, Ian Kelly wrote:

> On Tue, Sep 29, 2015 at 3:04 PM, Random832  wrote:
>> How about x not in range(11)?
> 
> That's fine as long as x is known to only take integral values.

It's not fine. In Python 2, it's painfully slow and inefficient, both
memory-wise and algorithmically:

-1 in range(1)  # test 0 <= -1 <= 1

This first creates a list of 1 integers, then compares each and
every one of them against -1 before returning False.

Using xrange instead at least avoids building the list first, but it still
compares -1 against each value.

Testing a numeric value within a certain range of values should be constant
time and constant memory. It should be *fast*. Using range in Python 2 is
none of those things.



-- 
Steven

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


pypy - Gurobi solver library

2015-09-29 Thread LJ
Hi All,

I use gurobipy to model a large scale optimization problem. Is there a way to 
use pypy with the gurobipy library? Has anyone done this?

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


Re: Check if a given value is out of certain range

2015-09-29 Thread Tim Chase
On 2015-09-29 21:32, Mark Lawrence wrote:
> On 29/09/2015 17:48, Rob Gaddi wrote:
> >> Is there any similar elegant way to check if a value is out of
> >> certain range?
> >> Example - To check if x is either less than zero or greater than
> >> ten? Right now I am using x < 0 or x > 10.
> >
> > not (0 <= x <= 10)
> 
> Yuck.

Not sure there's much "yuck" to be had there.  It's succinct, easy to
read, and correct.  The only improvement might be if you have things
to do in both cases, in which case remove the "not" and set the
clauses accordingly:

  if 0 <= x <= 10:
success_within_range(x)
  else:
fail_out_of_bounds(x)

-tkc



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


Linux Mint installation of Python 3.5

2015-09-29 Thread Mario Figueiredo
Hello everyone,

Under Linux Mint it is not a good idea to just go ahead and replace the
system installed Python versions and their packages. And yet I wish to
both update the 3.4 modules and install Python 3.5. I understand that
for the first I just need to use virtualenv.

But how can I safely install Python 3.5 from sources into a Linux Mint
box without damaging the OS?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Linux Mint installation of Python 3.5

2015-09-29 Thread Chris Angelico
On Wed, Sep 30, 2015 at 12:37 PM, Mario Figueiredo  wrote:
> Under Linux Mint it is not a good idea to just go ahead and replace the
> system installed Python versions and their packages. And yet I wish to
> both update the 3.4 modules and install Python 3.5. I understand that
> for the first I just need to use virtualenv.
>
> But how can I safely install Python 3.5 from sources into a Linux Mint
> box without damaging the OS?

The easiest way to install something from source is to use 'make
altinstall' for the final step. That should install you a 'python3.5'
binary without touching the 'python3' binary. That said, though, it's
entirely possible that upgrading 'python3' from 3.4 to 3.5 won't
actually break anything; it won't break any script that explicitly
looks for python3.4, and there's not a huge amount of breakage. But to
be on the safe side, use altinstall and explicitly ask for python3.5
any time you want it.

Personally, I use the regular 'make install', but that's because I'm
on Debian - the system Python is 2.7.

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


Re: Linux Mint installation of Python 3.5

2015-09-29 Thread Mario Figueiredo
On 09/30/2015 03:44 AM, Chris Angelico wrote:
> 
> The easiest way to install something from source is to use 'make
> altinstall' for the final step. That should install you a 'python3.5'
> binary without touching the 'python3' binary. That said, though, it's
> entirely possible that upgrading 'python3' from 3.4 to 3.5 won't
> actually break anything; it won't break any script that explicitly
> looks for python3.4, and there's not a huge amount of breakage. But to
> be on the safe side, use altinstall and explicitly ask for python3.5
> any time you want it.
> 

Thank you Chris. That will set me on my path.

> Personally, I use the regular 'make install', but that's because I'm
> on Debian - the system Python is 2.7.

Unfortunately Ubuntu based distros are going through a 2.x to 3.x
transition period. Both Pythons are installed and are system dependencies.

And their finicky dependency on Python really make these distros not
very friendly for Python development. If I do end up successfully
upgrading from 3.4 to 3.5, I will most likely forfeit my ability to
upgrade the Mint version in the future without a full system
installation. So the solution is to just maintain 3 different versions
of python my machine. Ridiculous.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Check if a given value is out of certain range

2015-09-29 Thread Random832
Steven D'Aprano  writes:
> It's not fine. In Python 2,
>...
> Testing a numeric value within a certain range of values should be constant
> time and constant memory. It should be *fast*. Using range in Python 2 is
> none of those things.

I wasn't aware we were discussing Python 2.

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


Re: Linux Mint installation of Python 3.5

2015-09-29 Thread Zachary Ware
On Tue, Sep 29, 2015 at 10:00 PM, Mario Figueiredo  wrote:
> On 09/30/2015 03:44 AM, Chris Angelico wrote:
>>
>> The easiest way to install something from source is to use 'make
>> altinstall' for the final step. That should install you a 'python3.5'
>> binary without touching the 'python3' binary. That said, though, it's
>> entirely possible that upgrading 'python3' from 3.4 to 3.5 won't
>> actually break anything; it won't break any script that explicitly
>> looks for python3.4, and there's not a huge amount of breakage. But to
>> be on the safe side, use altinstall and explicitly ask for python3.5
>> any time you want it.
>>
>
> Thank you Chris. That will set me on my path.
>
>> Personally, I use the regular 'make install', but that's because I'm
>> on Debian - the system Python is 2.7.
>
> Unfortunately Ubuntu based distros are going through a 2.x to 3.x
> transition period. Both Pythons are installed and are system dependencies.
>
> And their finicky dependency on Python really make these distros not
> very friendly for Python development. If I do end up successfully
> upgrading from 3.4 to 3.5, I will most likely forfeit my ability to
> upgrade the Mint version in the future without a full system
> installation. So the solution is to just maintain 3 different versions
> of python my machine. Ridiculous.

It should be no problem to just do `./configure && make profile_opt &&
make install`.  The default prefix is /usr/local/; the system python's
prefix is /usr/.  Assuming /usr/local/bin is on your PATH before
/usr/bin, 'python3' from your shell will be python3.5, but all system
scripts should be using /usr/bin/python3 explicitly (if not, it's a
bug; report it to Mint).  Let the system take care of its own 3.4, you
can ignore it and use 3.5.  You won't be able to use apt-get to
install packages for 3.5, but since you're using 3.5.0 less than a
month after release, I assume you want more up-to-date packages anyway
:).  Just use pip for any global packages you want for 3.5, and both
venv and pip for any packages you don't want to be global.

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


Re: Check if a given value is out of certain range

2015-09-29 Thread Steven D'Aprano
On Wed, 30 Sep 2015 01:08 pm, Random832 wrote:

> Steven D'Aprano  writes:
>> It's not fine. In Python 2,
>>...
>> Testing a numeric value within a certain range of values should be
>> constant time and constant memory. It should be *fast*. Using range in
>> Python 2 is none of those things.
> 
> I wasn't aware we were discussing Python 2.

Was there something in the OP's question that suggested to you that we were
only discussing Python 3?

Python 2.7 is still the main version used by most people.


-- 
Steven

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


Re: Linux Mint installation of Python 3.5

2015-09-29 Thread Chris Angelico
On Wed, Sep 30, 2015 at 1:00 PM, Mario Figueiredo  wrote:
>> Personally, I use the regular 'make install', but that's because I'm
>> on Debian - the system Python is 2.7.
>
> Unfortunately Ubuntu based distros are going through a 2.x to 3.x
> transition period. Both Pythons are installed and are system dependencies.
>
> And their finicky dependency on Python really make these distros not
> very friendly for Python development. If I do end up successfully
> upgrading from 3.4 to 3.5, I will most likely forfeit my ability to
> upgrade the Mint version in the future without a full system
> installation. So the solution is to just maintain 3 different versions
> of python my machine. Ridiculous.

Three different Python versions? Ehh, no big deal.

rosuav@sikorsky:~$ python2 --version
Python 2.7.9
rosuav@sikorsky:~$ python3.4 --version
Python 3.4.2
rosuav@sikorsky:~$ python3.5 --version
Python 3.5.0b1+
rosuav@sikorsky:~$ python3.6 --version
Python 3.6.0a0
rosuav@sikorsky:~$ pypy --version
Python 2.7.8 (2.4.0+dfsg-3, Dec 20 2014, 13:30:46)
[PyPy 2.4.0 with GCC 4.9.2]
rosuav@sikorsky:~$ jython --version
"my" variable $jythonHome masks earlier declaration in same scope at
/usr/bin/jython line 15.
Jython 2.5.3

And Steven D'Aprano probably can beat that by an order of magnitude.

Keep your multiple interpreters around; it doesn't hurt. Unless you're
seriously bothered by disk space issues, the biggest cost is keeping
track of which one you've installed some third-party package into.

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


Re: Linux Mint installation of Python 3.5

2015-09-29 Thread Steven D'Aprano
On Wed, 30 Sep 2015 01:00 pm, Mario Figueiredo wrote:

> So the solution is to just maintain 3 different versions
> of python my machine. Ridiculous.

Not at all. It's not like a Python install is that big -- Python 3.3 is only
about 150MB.

It's a little sad that Ubuntu isn't able to transition between 2 and 3 in
one release, but that's their problem, not yours. You shouldn't be touching
the system Python(s), you should leave that for Ubuntu to upgrade.

I think that it is generally a good idea to keep your development Python
separate from the system Python, even if they use the same version. That
way, even if you accidentally break your development Python, the system
Python will continue to work.



-- 
Steven

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


Re: Linux Mint installation of Python 3.5

2015-09-29 Thread Chris Angelico
On Wed, Sep 30, 2015 at 1:23 PM, Steven D'Aprano  wrote:
> I think that it is generally a good idea to keep your development Python
> separate from the system Python, even if they use the same version. That
> way, even if you accidentally break your development Python, the system
> Python will continue to work.

What, you don't enjoy fixing a broken Python using no tool that itself
requires Python? Where's the fun in a boring life?!?

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


Re: Check if a given value is out of certain range

2015-09-29 Thread Ian Kelly
On Tue, Sep 29, 2015 at 9:14 PM, Steven D'Aprano  wrote:
> On Wed, 30 Sep 2015 01:08 pm, Random832 wrote:
>
>> Steven D'Aprano  writes:
>>> It's not fine. In Python 2,
>>>...
>>> Testing a numeric value within a certain range of values should be
>>> constant time and constant memory. It should be *fast*. Using range in
>>> Python 2 is none of those things.
>>
>> I wasn't aware we were discussing Python 2.
>
> Was there something in the OP's question that suggested to you that we were
> only discussing Python 3?
>
> Python 2.7 is still the main version used by most people.

As far as I'm concerned, Python is Python 3. I'm aware that the check
is inefficient in Python 2, but I tire of constantly pointing out
Python 2 as the exception to everything.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Check if a given value is out of certain range

2015-09-29 Thread Luca Menegotto

Il 29/09/2015 23:04, Random832 ha scritto:


How about x not in range(11)?



Remember: simpler is better.

--
Ciao!
Luca

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


Re: pypy - Gurobi solver library

2015-09-29 Thread Laura Creighton
In a message of Tue, 29 Sep 2015 18:58:19 -0700, LJ writes:
>Hi All,
>
>I use gurobipy to model a large scale optimization problem. Is there a way to 
>use pypy with the gurobipy library? Has anyone done this?
>
>Thanks.

I don't think so.  I think that gurobipy depends on having all of
numpy working, and pypy isn't there yet.  But you can ask this one
on [email protected] in case there is somebody there who has
done such a thing.

Laura

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


Re: ConnectionError handling problem

2015-09-29 Thread shiva upreti
On Friday, September 25, 2015 at 12:55:01 PM UTC+5:30, Cameron Simpson wrote:
> On 24Sep2015 22:46, shiva upreti  wrote:
> >On Friday, September 25, 2015 at 10:55:45 AM UTC+5:30, Cameron Simpson wrote:
> >> On 24Sep2015 20:57, shiva upreti  wrote:
> >> >Thank you Cameron.
> >> >I think the problem with my code is that it just hangs without raising 
> >> >any 
> >> >exceptions. And as mentioned by Laura above that when I press CTRL+C, it 
> >> >just catches that exception and prints ConnectionError which is 
> >> >definitely 
> >> >a lie in this case as you mentioned.
> 
> Ok. You original code says:
> 
>   try:
> r=requests.post(url, data=query_args)
>   except:
> print "Connection error"
> 
> and presumably we think your code is hanging inside the requests.post call? 
> You 
> should probably try to verify that, because if it is elsewhere you need to 
> figure out where (lots of print statements is a first start on that).
> 
> I would open two terminals. Run your program until it hangs in one.
> 
> While it is hung, examine the network status. I'll presume you're on a UNIX 
> system of some kind, probably Linux? If not it may be harder (or just require 
> someone other than me).
> 
> If it is hung in the .post call, quite possibly it has an established 
> connecion 
> to the target server - maybe that server is hanging.
> 
> The shell command:
> 
>   netstat -rn | fgrep 172.16.68.6 | fgrep 8090
> 
> will show every connection to your server hosting the URL 
> "http://172.16.68.6:8090/login.xml";. That will tell you if you have a 
> connection (if you are the only person doing the connecting from your 
> machine).
> 
> If you have the "lsof" program (possibly in /usr/sbin, so "/usr/sbin/lsof") 
> you 
> can also examine the state of your hung Python program. This:
> 
>   lsof -p 12345
> 
> will report on the open files and network connections of the process with pid 
> 12345. Adjust to suit: you can find your program's pid ("process id") with 
> the 
> "ps" command, or by backgrounding your program an issuing the "jobs" command, 
> which should show the process id more directly.
> 
> Cheers,
> Cameron Simpson 

Hi Cameron.
Yes I use ubuntu 14.04. I will try what you suggested. But I cant understand 
one thing, for whatever reason the script is hanging, why does it resumes 
almost instantaneously when I press CTRL+C.
Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list