Re: [Tutor] Dictionaries and multiple keys/values

2013-03-26 Thread Dave Angel

On 03/26/2013 12:36 AM, Robert Sjoblom wrote:

Hi again, Tutor List.

I am trying to figure out a problem I've run into. Let me first say
that this is an assignment, so please don't give me any answers, but
just nudge me in the general direction. So the task is this: from a
text file, populate three different dictionaries with various
information. The text file is structured like so:
Georgie Porgie
87%
$$$
Canadian, Pub Food

So name, rating, price range, and food offered. After food offered
follows a blank line before the next restaurant is listed.



There are a number of things about the input file that you haven't 
specified, and it's useful to create a running description of the 
assumptions you're making about it.  That way, if one of those 
assumptions turns out to not always be true, you at least have a clue as 
to what might be wrong.


And in real-life problems, you might want to add code to test every one 
of those assumptions, and exit with a clean message when the data 
doesn't meet them.


Examples of such assumptions:

1) the "name" line is unique;  no two records have the same name
2) the rating is always exactly two digits followed by a percent sign, 
even if it's less than 10%.
3) white space may occur before and after the dollarsigns on the 
price-range field, but never on the rating or name lines
4) there will be exactly 5 lines for every record, including the last 
one in the file.



The three dictionaries are:
name_to_rating = {}
price_to_names = {'$': [], '$$': [], '$$$': [], '': []}
cuisine_to_names = {}

Now I've poked at this for a while now, and one idea I had, which I
worked on for quite a while, was that since the restaurants all start
at index 0, 5, 10 and so on, I could structure a while loop like this:
with open('textfile.txt') as mdf:
   file_length = len(mdf.readlines())-1
   mdf.seek(0)
   data = mdf.readlines()

   i = 0
   while file_length > 0:
 name_to_rating[data[i]] = int(data[i+1][:2])
 price_to_names[data[i+2].strip()].append(data[i].strip())
 # here's the cuisine_to_names part
 i += 5
 file_length -= 5

And while this works, for the two first dictionaries,  it seems really
cumbersome -- especially that second expression -- and very, very
brittle. However, even if I was happy with that, I can't figure out
what to do in the situation where:
data[i+3] = 'Canadian, Pub Food' #should be two items, is currently a string.
My problem is that I'm... stupid. I can split the entry into a list
with two items, but even so I don't know how to add the key: value
pair to the dictionary so that the value is a list, which I then later
can append things to.



Nothing stupid about that.  Your only shortcoming is assuming it should 
be a single line doing the assignment.  Once you use 
cuisines.split(something) to make a list of cuisines, you then need to 
loop over them.  And if the cuisine doesn't already exist, you need to 
create the item, while if it does, you need to append to the item.



I'm sorry, this sounds terribly confused, I know. I had another idea
to feed each line to a function, because no restaurant name has a
comma in it, and food offered always has a comma in it if the
restaurant offers more than one kind. But again, this seems really
brittle.

I guess we can't use objects (for some reason), but that doesn't
really matter because if I can't extract the data into dictionaries I
wouldn't have much use of an object either way. So yeah, my two
questions are these:
is there a better way to move through the text file other than a
really convoluted expression? And how do I add more than one value to
a key in a dictionary, if the values are added at different times and
there's no list created in the dictionary to begin with?

(I briefly though about initializing empty lists for each food type in
the dictionary and go with my horrible expressions, but that seems
like a cheap way out of a problem I'd rather tackle in a good way to
begin with)

Much thanks in advance.



First thing I'd do to make those lines clearer is to assign temp names 
to each of those fields.  For example, if you say

name =

then the other places that use name can be much more readable. 
Likewise, if a particular name needs to be stripped or split before 
being assigned, it's in one common place.


So the loop would start with four assignments, capturing usable versions 
of those four lines.  Then you'd have 3 assignments, updating the three 
dictionaries from those four names.  And one of those assignments would 
update multiple dictionary items, it would actually be a loop.


You mention objects, which is one way to make things easier.  But you 
didn't mention functions.  I think it'd be an improvement if each 
dictionary had a function created to do its updating.  Then the loop 
that you're writing here would be four assignments, followed by 3 
function calls.


Finally, you ask if there's a better way than readlines().  I don't 
think there's any harm in doing it th

Re: [Tutor] Dictionaries and multiple keys/values

2013-03-26 Thread Alan Gauld

On 26/03/13 04:36, Robert Sjoblom wrote:


Georgie Porgie
87%
$$$
Canadian, Pub Food



So a 5 line pattern with 4 data fields. The last one containing multiple 
comma separated values, potentially.




The three dictionaries are:
name_to_rating = {}
price_to_names = {'$': [], '$$': [], '$$$': [], '': []}
cuisine_to_names = {}


And the keys are all basic single data values


So far so good.


Now I've poked at this for a while now, and one idea I had, which I
worked on for quite a while, was that since the restaurants all start
at index 0, 5, 10 and so on, I could structure a while loop like this:


Sounds way too complicated.

I'd just read the file in groups of 5 lines and process them as I went.
I'd also write a helper function to process each record.

In pseudo code

def storeRestaurant(mdr):
   name = mdr.readline()
   rating = mdr.readline()
   price = mdr.readline()
   cuisines= mdr.readline().split(',')
   # now assign values to dictionaries.

with openas mdr
   while True:
  try: storeRestaurant(mdr)
  except end of file: pass



I'm sorry, this sounds terribly confused, I know. I had another idea
to feed each line to a function, because no restaurant name has a
comma in it, and food offered always has a comma in it if the
restaurant offers more than one kind. But again, this seems really
brittle.


I'm not sure why you think its brittle?
You need to code in error checking somewhere,
it might as well be hidden in a function.


I guess we can't use objects (for some reason),


Technically you can but maybe assignment wise you can't...


really convoluted expression? And how do I add more than one value to
a key in a dictionary, if the values are added at different times and
there's no list created in the dictionary to begin with?


You can create a list to begin with if you suspect you may need multiple 
values ie each time you add a new key create a list.

The get() method should help here.


(I briefly though about initializing empty lists for each food type in
the dictionary and go with my horrible expressions,


You can do the empty lists without the horrible expressions!
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


[Tutor] PyDtls

2013-03-26 Thread Mousumi Basu
I have installed PyDtls from the link:-"
https://pypi.python.org/pypi/Dtls/0.1.0";.
While creating the server and client objects in
"sslconnection.py", it is referring to "x509.py" for certificates.
Following error is occurring :-

File
"C:\dtls\Dtls-0.1.0.sdist_with_openssl.win32\Dtls-0.1.0\dtls\"x509.py",line
34 , in 
from openssl import *
File"C:\dtls\Dtls-0.1.0.sdist_with_openssl.win32\Dtls-0.1.0\dtls\"openssl.py",
line 74 in 

   libcrypto=CDLL(release_cryptodll_path)

File"C:\Python27\lib\ctypes\"_init_.py", line 365,in _init_
  self_.handle=_dlopen(self._name,mode)

WindowsError: [Error 126] The specified module could not be found.


Please help me out to sort that error.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PyDtls

2013-03-26 Thread Dave Angel

On 03/26/2013 08:16 AM, Mousumi Basu wrote:

 I have installed PyDtls from the link:-"
https://pypi.python.org/pypi/Dtls/0.1.0";.
 While creating the server and client objects in
"sslconnection.py", it is referring to "x509.py" for certificates.
Following error is occurring :-

File
"C:\dtls\Dtls-0.1.0.sdist_with_openssl.win32\Dtls-0.1.0\dtls\"x509.py",line
34 , in 
from openssl import *
File"C:\dtls\Dtls-0.1.0.sdist_with_openssl.win32\Dtls-0.1.0\dtls\"openssl.py",
line 74 in 

libcrypto=CDLL(release_cryptodll_path)

File"C:\Python27\lib\ctypes\"_init_.py", line 365,in _init_
   self_.handle=_dlopen(self._name,mode)

WindowsError: [Error 126] The specified module could not be found.


 Please help me out to sort that error.




Sounds to me like the DLL that implements the crypto is missing, in the 
wrong place, or has unmet dependencies.  You can find out the name (and 
presumably the path) of the dll by looking at release_cryptodll_path.


If it's indeed there, then I'd use the dependency walker (from the 
appropriate Windows ddk) to find whether there are any unmet 
dependencies.  That assumes you haven't done anything obscure with the 
path, as the dependency walker needs to run with the same environment 
variables.



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


[Tutor] Udp socket questio

2013-03-26 Thread Phil

Thank you for reading this.

I'm a bit out of my depth here. I'm attempting to set up a simple udp 
client.


The example that follows results in an error message and I'm wondering 
if I should be importing a different module. A Google search doesn't 
support that idea.


''
udp socket client
Silver Moon
'''

import socket   #for sockets
import sys  #for exit

# create dgram udp socket
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
except socket.error:
print 'Failed to create socket'
sys.exit()

host = 'localhost';
port = ;

while(1) :
msg = raw_input('Enter message to send : ')

try :
#Set the whole string
s.sendto(msg, (host, port))

# receive data from client (data, addr)
d = s.recvfrom(1024)
reply = d[0]
addr = d[1]

print 'Server reply : ' + reply

except socket.error, msg:
print 'Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
sys.exit()


Traceback (most recent call last):
  File "socket2.py", line 6, in 
import socket   #for sockets
  File "/home/phil/Python/socket.py", line 7, in 
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
AttributeError: 'module' object has no attribute 'AF_INET'

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


Re: [Tutor] Udp socket questio

2013-03-26 Thread Dave Angel

On 03/26/2013 07:30 AM, Phil wrote:

Thank you for reading this.

I'm a bit out of my depth here. I'm attempting to set up a simple udp
client.

The example that follows results in an error message and I'm wondering
if I should be importing a different module. A Google search doesn't
support that idea.

''
 udp socket client
 Silver Moon
'''

import socket#for sockets
import sys#for exit

# create dgram udp socket
try:
 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
except socket.error:
 print 'Failed to create socket'
 sys.exit()

host = 'localhost';
port = ;

while(1) :
 msg = raw_input('Enter message to send : ')

 try :
 #Set the whole string
 s.sendto(msg, (host, port))

 # receive data from client (data, addr)
 d = s.recvfrom(1024)
 reply = d[0]
 addr = d[1]

 print 'Server reply : ' + reply

 except socket.error, msg:
 print 'Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
 sys.exit()


Traceback (most recent call last):
   File "socket2.py", line 6, in 
 import socket   #for sockets
   File "/home/phil/Python/socket.py", line 7, in 
 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
AttributeError: 'module' object has no attribute 'AF_INET'



Looks to me like you have your own file socket.py  in /home/phil/Python

and that it has the line that's causing the exception.

That file hides the one in the system library, so please rename it to 
something else.



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


Re: [Tutor] PyDtls

2013-03-26 Thread Alan Gauld

On 26/03/13 12:16, Mousumi Basu wrote:


 I have installed PyDtls from the
link:-"https://pypi.python.org/pypi/Dtls/0.1.0";.


This list is for learning the python language and standard library.
Anything beyond that you are taking pot luck whether anyone here knows 
about it.


You would be better off asking on a specific Dtls forum or possibly on 
the general Python mailing list/newsgroup.


comp.lang.python


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

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


Re: [Tutor] PyDtls

2013-03-26 Thread eryksun
On Tue, Mar 26, 2013 at 8:16 AM, Mousumi Basu  wrote:
> File"C:\dtls\Dtls-0.1.0.sdist_with_openssl.win32\Dtls-0.1.0\dtls\"openssl.py",
> line 74 in 

You didn't install the package. Run "python setup.py install". This
will install it to Lib\site-packages\Dtls and copy the pre-built DLLs
into the package directory.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Building Python 2.7.3 on RHEL 5.8 x86_64 -- Syntax Error

2013-03-26 Thread Sean Carolan
I'm attempting to use setup.py to build an RPM, but ran into this error:

[scarolan@cobbler:~/rpmbuild/BUILD/Python-2.7.3]$ python27 setup.py
bdist_rpm

  File "setup.py", line 361
with open(tmpfile) as fp:
^
SyntaxError: invalid syntax
error: Bad exit status from /var/tmp/rpm-tmp.8897 (%build)

It appears the syntax error is striggered when "python setup.py build" is
run from that temporary bash script (/var/tmp/rpm-tmp.8897):

+ cd
/home/scarolan/rpmbuild/BUILD/Python-2.7.3/build/bdist.linux-x86_64/rpm/BUILD
+ cd Python-2.7.3
+ env 'CFLAGS=-O2 -g -m64 -mtune=generic' python setup.py build
  File "setup.py", line 361
with open(tmpfile) as fp:
^
SyntaxError: invalid syntax

Any ideas how to fix this?  The documentation on this topic is quite scarce.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Building Python 2.7.3 on RHEL 5.8 x86_64 -- Syntax Error

2013-03-26 Thread Amit Saha
On Wed, Mar 27, 2013 at 12:55 AM, Sean Carolan  wrote:
> I'm attempting to use setup.py to build an RPM, but ran into this error:
>
> [scarolan@cobbler:~/rpmbuild/BUILD/Python-2.7.3]$ python27 setup.py
> bdist_rpm
>
>   File "setup.py", line 361
> with open(tmpfile) as fp:
> ^
> SyntaxError: invalid syntax
> error: Bad exit status from /var/tmp/rpm-tmp.8897 (%build)
>
> It appears the syntax error is striggered when "python setup.py build" is
> run from that temporary bash script (/var/tmp/rpm-tmp.8897):

Could it be that it is taking the system python executable which is
probably 2.4?

-Amit.


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


Re: [Tutor] Building Python 2.7.3 on RHEL 5.8 x86_64 -- Syntax Error

2013-03-26 Thread Sean Carolan
> Could it be that it is taking the system python executable which is
> probably 2.4?
>
> -Amit.


I've tried it with python24, python25 and python27 and all of them give the
same error.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Building Python 2.7.3 on RHEL 5.8 x86_64 -- Syntax Error

2013-03-26 Thread Sean Carolan
Ok, so I'm now attempting a "clean room" installation using Python 2.7.3 to
build the RPM.  Here's my installation command:

./configure --with-zlib=/usr/include; make; sudo make install

But the bdist_rpm setup command fails:

[scarolan@titania:~/Python-2.7.3]$ python2.7 setup.py bdist_rpm

error: pyconfig.h: No such file or directory
error: Bad exit status from /var/tmp/rpm-tmp.67699 (%build)

RPM build errors:
Bad exit status from /var/tmp/rpm-tmp.67699 (%build)
error: command 'rpmbuild' failed with exit status 1

Where is it looking for pyconfig.h?




On Tue, Mar 26, 2013 at 10:18 AM, Sean Carolan  wrote:

>
> Could it be that it is taking the system python executable which is
>> probably 2.4?
>>
>> -Amit.
>
>
> I've tried it with python24, python25 and python27 and all of them give
> the same error.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Building Python 2.7.3 on RHEL 5.8 x86_64 -- Syntax Error

2013-03-26 Thread Hugo Arts
On Tue, Mar 26, 2013 at 3:18 PM, Sean Carolan  wrote:

>
>  Could it be that it is taking the system python executable which is
>> probably 2.4?
>>
>> -Amit.
>
>
> I've tried it with python24, python25 and python27 and all of them give
> the same error.
>
>
What it looks like to me is that while you run (using python 2.7):

>  python27 setup.py bdist_rpm

doing that generates a temporary bash script, which in turn runs:

> python setup.py build

which is linked to the system default python, which I'm guessing is 2.4. No
matter which version you execute the first one with, the bash script
generated will always try to use the system-default python. This is
essentially a bug in the setup script; it should generate a script that
uses the same python version it was executed with, ideally.

The easiest workaround I can think of is a temporary alias, i.e.:

$ alias python="python27" && python setup.by bdist_rpm && unalias python

Or some variation of such. The more permanent fix is to change the bash
script that setup.py generates so it's less naive about having the right
system python installed, *or* upgrading the system python version.

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


Re: [Tutor] Building Python 2.7.3 on RHEL 5.8 x86_64 -- Syntax Error

2013-03-26 Thread Sean Carolan
> What it looks like to me is that while you run (using python 2.7):
>
> >  python27 setup.py bdist_rpm
>
> doing that generates a temporary bash script, which in turn runs:
>
> > python setup.py build
>

Yea, I checked this, and /usr/local/bin/python is just a symlink pointing
at /usr/local/bin/python2.7.

Unfortunately Red Hat is slow to update their package versions; even the
most recent RHEL6 comes with Python 2.6.

I think if I can figure out where it wants that pyconfig.h file, it should
work.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Building Python 2.7.3 on RHEL 5.8 x86_64 -- Syntax Error

2013-03-26 Thread Walter Prins
Hi,


On 26 March 2013 16:54, Hugo Arts  wrote:

> On Tue, Mar 26, 2013 at 3:18 PM, Sean Carolan  wrote:
>
>>
>>  Could it be that it is taking the system python executable which is
>>> probably 2.4?
>>>
>>> -Amit.
>>
>>
>> I've tried it with python24, python25 and python27 and all of them give
>> the same error.
>>
>
> The easiest workaround I can think of is a temporary alias, i.e.:
>
> $ alias python="python27" && python setup.by bdist_rpm && unalias python
>
> Or some variation of such. The more permanent fix is to change the bash
> script that setup.py generates so it's less naive about having the right
> system python installed, *or* upgrading the system python version.
>

Sean you might also look into virtualenv.  I suspect a suitably setup
virtualenv will also avoid your problem, but is obviously more work than
what Hugo's suggested.  See for example this question on stackoverflow:
http://stackoverflow.com/questions/1534210/use-different-python-version-with-virtualenv


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


Re: [Tutor] Building Python 2.7.3 on RHEL 5.8 x86_64 -- Syntax Error

2013-03-26 Thread eryksun
On Tue, Mar 26, 2013 at 11:18 AM, Sean Carolan  wrote:
> I've tried it with python24, python25 and python27 and all of them give the
> same error.

After looking at the source, I think the option python=python2.7 may
solve the problem.

http://hg.python.org/cpython/file/d321885ff8f3/Lib/distutils/command/bdist_rpm.py#l23
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PyDtls

2013-03-26 Thread eryksun
On Tue, Mar 26, 2013 at 12:59 PM, Mousumi Basu  wrote:
>
> I have run the following command previously in the command prompt:-
>
> C:\dtls\Dtls-0.1.0.sdist_with_openssl.win32\Dtls-0.1.0\dtls>
> python setup.py install
>
> Was that incorrect?Please help me out as i am eager to learn about pydtls.

That's fine, but the error messages you posted showed 'File "C:\dtls\
', which is not correct. I see from the ctypes error that Python
is installed in C:\Python27. Then the package (and the DLLs) should be
located here:

C:\Python27\Lib\site-packages\dtls

You don't run it from there as a script, however. Python will find it
along sys.path when you "import dtls".
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PyDtls

2013-03-26 Thread eryksun
On Tue, Mar 26, 2013 at 1:35 PM, eryksun  wrote:
>> C:\dtls\Dtls-0.1.0.sdist_with_openssl.win32\Dtls-0.1.0\dtls>
>> python setup.py install
>>
>> Was that incorrect?Please help me out as i am eager to learn about pydtls.
>
> That's fine,

On 2nd thought, that's not fine. setup.py is located in the parent directory.

Make sure you're in the right directory:

> C:
> cd C:\dtls\Dtls-0.1.0.sdist_with_openssl.win32\Dtls-0.1.0

Run the setup script:

> python setup.py install

Run python and import dtls to test it:

>>> import dtls
>>> import ssl
>>> hasattr(ssl, 'DTLS_OPENSSL_VERSION')
False

Now patch ssl:

>>> dtls.do_patch()
>>> ssl.DTLS_OPENSSL_VERSION
'OpenSSL 1.0.1c 10 May 2012'
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Dictionaries and multiple keys/values

2013-03-26 Thread David Rock
* Robert Sjoblom  [2013-03-26 05:36]:
> 
> brittle. However, even if I was happy with that, I can't figure out
> what to do in the situation where:
> data[i+3] = 'Canadian, Pub Food' #should be two items, is currently a string.
> My problem is that I'm... stupid. I can split the entry into a list
> with two items, but even so I don't know how to add the key: value
> pair to the dictionary so that the value is a list, which I then later
> can append things to.

If your data is a list, then it will be a list in the dict.  You could
just make it so that particular key always contains a list of
characteristics, even if it's a list of only one.

>>> data = 'Canadian, Pub Food'.split(',')
>>> data
['Canadian', ' Pub Food']
>>> data = 'French'.split(',')
>>> data
['French']

Then just put the list as the value.

d['characteristics'] = data
>>> data = 'Canadian, Pub Food'.split(',')
>>> d['characteristics'] = data
>>> d['characteristics']
['Canadian', ' Pub Food']

-- 
David Rock
da...@graniteweb.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Building Python 2.7.3 on RHEL 5.8 x86_64 -- Syntax Error

2013-03-26 Thread Sean Carolan
>
> http://hg.python.org/cpython/file/d321885ff8f3/Lib/distutils/command/bdist_rpm.py#l23
>

No dice.

[scarolan@titania:~/Python-2.7.3]$ alias | grep python
alias python='/usr/local/bin/python2.7'

[scarolan@titania:~/Python-2.7.3]$ /usr/local/bin/python2.7 setup.py
bdist_rpm
error: pyconfig.h: No such file or directory
error: Bad exit status from /var/tmp/rpm-tmp.14555 (%build)
RPM build errors:
Bad exit status from /var/tmp/rpm-tmp.14555 (%build)
error: command 'rpmbuild' failed with exit status 1

Has anyone on this list successfully built a python 2.7 RPM using this
command?
python2.7 setup.py bdist_rpm

If so, what was your secret?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Building Python 2.7.3 on RHEL 5.8 x86_64 -- Syntax Error

2013-03-26 Thread Sean Carolan
> If so, what was your secret?
>
>
I tried running this again with strace, and it looks like it's finding the
pyconfig.h file:

open("/usr/local/include/python2.7/pyconfig.h", O_RDONLY) = 4
read(4, "/* pyconfig.h.  Generated from p"..., 4096) = 4096
stat("pyconfig.h", {st_mode=S_IFREG|0664, st_size=36037, ...}) = 0
stat("pyconfig.h.in", {st_mode=S_IFREG|0644, st_size=34336, ...}) = 0
stat("PC/pyconfig.h", {st_mode=S_IFREG|0644, st_size=20770, ...}) = 0
stat("PC/os2vacpp/pyconfig.h", {st_mode=S_IFREG|0644, st_size=10113, ...})
= 0
stat("PC/os2emx/pyconfig.h", {st_mode=S_IFREG|0644, st_size=8096, ...}) = 0
stat("Include/pyconfig.h", {st_mode=S_IFREG|0664, st_size=36037, ...}) = 0
stat("build/bdist.linux-x86_64/rpm/BUILD/Python-2.7.3/pyconfig.h",
{st_mode=S_IFREG|0664, st_size=36037, ...}) = 0
stat("build/bdist.linux-x86_64/rpm/BUILD/Python-2.7.3/Include/pyconfig.h",
{st_mode=S_IFREG|0664, st_size=36037, ...}) = 0
stat("RISCOS/pyconfig.h", {st_mode=S_IFREG|0644, st_size=18510, ...}) = 0
open("/usr/local/include/python2.7/pyconfig.h", O_RDONLY) = 3
read(3, "/* pyconfig.h.  Generated from p"..., 4096) = 4096
error: pyconfig.h: No such file or directory

/usr/local/include/python2.7/pyconfig.h exists:

[scarolan@titania:~/Python-2.7.3]$ ls
/usr/local/include/python2.7/pyconfig.h -l
-rw-r--r-- 1 root root 36037 Mar 26 11:45
/usr/local/include/python2.7/pyconfig.h

I'm not sure exactly what the installer is expecting here...
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Building Python 2.7.3 on RHEL 5.8 x86_64 -- Syntax Error

2013-03-26 Thread Alan Gauld

On 26/03/13 19:04, Sean Carolan wrote:


Has anyone on this list successfully built a python 2.7 RPM using this
command?
python2.7 setup.py bdist_rpm


Given that most folks on this list are only learning Python its pretty 
unlikely that they are building bespoke RPMs...


You might find more experience of RPM building on the general Python 
mailing list/newsgroup.


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

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


Re: [Tutor] Building Python 2.7.3 on RHEL 5.8 x86_64 -- Syntax Error

2013-03-26 Thread Sean Carolan
> Given that most folks on this list are only learning Python its pretty
> unlikely that they are building bespoke RPMs...
>
> You might find more experience of RPM building on the general Python
> mailing list/newsgroup.


Sorry 'bout that.  I'll follow up with the bug report and possibly the
general list as well.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Building Python 2.7.3 on RHEL 5.8 x86_64 -- Syntax Error

2013-03-26 Thread Prasad, Ramit
Sean Carolan wrote:
> [Alan Gauld wrote:]
> > Given that most folks on this list are only learning Python its pretty 
> > unlikely that they are building
> > bespoke RPMs...
> > 
> > You might find more experience of RPM building on the general Python 
> > mailing list/newsgroup.
> 
> Sorry 'bout that.  I'll follow up with the bug report and possibly the 
> general list as well.

Please post your solution back (if you find one), for archive completeness. 
And my curiosity. :)


~Ramit


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Building Python 2.7.3 on RHEL 5.8 x86_64 -- Syntax Error

2013-03-26 Thread Amit Saha
On Wed, Mar 27, 2013 at 7:32 AM, Sean Carolan  wrote:
>
>> Given that most folks on this list are only learning Python its pretty
>> unlikely that they are building bespoke RPMs...
>>
>> You might find more experience of RPM building on the general Python
>> mailing list/newsgroup.
>
>
> Sorry 'bout that.  I'll follow up with the bug report and possibly the
> general list as well.

I am going to try doing this sometime today. I shall let you know if I
find a solution or my observations.


Best,
Amit.

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


Re: [Tutor] Building Python 2.7.3 on RHEL 5.8 x86_64 -- Syntax Error

2013-03-26 Thread Amit Saha
On Wed, Mar 27, 2013 at 7:32 AM, Sean Carolan  wrote:
>
>> Given that most folks on this list are only learning Python its pretty
>> unlikely that they are building bespoke RPMs...
>>
>> You might find more experience of RPM building on the general Python
>> mailing list/newsgroup.
>
>
> Sorry 'bout that.  I'll follow up with the bug report and possibly the
> general list as well.


FWIW, I tried the same thing with Python 3 sources on Fedora 18, and
got the same error as you.

But, where did you get the idea that you could build Python RPMs using
$python setup.py bdist_rpm ? I thought that was only limited to
building RPMs for python packages (including extensions), but not the
Python interpreter itself. Please correct me if i am wrong.

Okay, here is something for you to try in the meantime. Download the
Python 2.7 SRPM (source RPM) from
http://koji.fedoraproject.org/koji/packageinfo?packageID=130. May be
the F17 version.
Extract it to get the source files, patches and the SPEC file.

If you are familiar with building RPM packages by hand, please try
building it like any other package. That is, by copying the .spec file
to SPECS and the .patch, .xz and other files in SOURCES and then doing
rpmbuild -ba python.spec from the SPECS directory. Oh yes, please
install the dependencies for building the package first by doing,
yum-builddep  before doing the build.

It seems like it built the RPMs alright on my laptop. See if that helps.

Best,
Amit.



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


Re: [Tutor] Udp socket questio

2013-03-26 Thread Phil

On 26/03/13 23:15, Dave Angel wrote:



Traceback (most recent call last):
   File "socket2.py", line 6, in 
 import socket   #for sockets
   File "/home/phil/Python/socket.py", line 7, in 
 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
AttributeError: 'module' object has no attribute 'AF_INET'



Looks to me like you have your own file socket.py  in /home/phil/Python


Thanks Dave,

I woke up during the early hours of the morning and realised what was 
going on. The name of my python file was not the same as the module but 
it was prefixed "socket" and than seems to be enough to cause a problem.


The udp client still doesn't do what I want but at least the example 
runs without an error.


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


[Tutor] HELP: Creating animation from multiple plots

2013-03-26 Thread Sayan Chatterjee
Dear All,

I am a newbie to Python but have a fair know how of other languages i.e C
etc.

I want to run an astrophysical simulation in Python. All I have to do it to
generate a set of 'plots' depending on a varying parameter and then stitch
them up.

1) Is it possible to automatically generate different data files( say in
the orders of 1000) with different names depending on a parameter?

2) Is it possible to plot the data sets right from Python itself and save
the plots in different jpeg files to stitched upon later on.

Awaiting your reply.

Thank you in advance.

Sincerely,
Sayan

-- 


--
*Sayan  Chatterjee*
Dept. of Physics and Meteorology
IIT Kharagpur
Lal Bahadur Shastry Hall of Residence
Room AB 205
Mob: +91 9874513565
blog: www.blissprofound.blogspot.com

Volunteer , Padakshep
www.padakshep.org
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] HELP: Creating animation from multiple plots

2013-03-26 Thread Amit Saha
Hi Sayan,

On Wed, Mar 27, 2013 at 4:14 PM, Sayan Chatterjee
 wrote:
> Dear All,
>
> I am a newbie to Python but have a fair know how of other languages i.e C
> etc.
>
> I want to run an astrophysical simulation in Python. All I have to do it to
> generate a set of 'plots' depending on a varying parameter and then stitch
> them up.
>
> 1) Is it possible to automatically generate different data files( say in the
> orders of 1000) with different names depending on a parameter?

It certainly is. Are you talking about the file names being
file_1001.txt, file_1002.txt and so on? If yes, let's say  your
parameter values are stored in param. Then something like this would
do the trick:

param_values = [1000,1001, 1005, 2001]

for param in param_values:
fname = 'file_' + str(param)


   # write to file fname
   #
   #


Sorry if its different from what you are looking for. But yes, its
certainly possible.


>
> 2) Is it possible to plot the data sets right from Python itself and save
> the plots in different jpeg files to stitched upon later on.

It is possible to generate plots and save each as JPEGs. [1].

What do you mean by stitching together?

[1] http://stackoverflow.com/questions/8827016/matplotlib-savefig-in-jpeg-format


Best,
Amit
-- 
http://amitsaha.github.com/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] HELP: Creating animation from multiple plots

2013-03-26 Thread Amit Saha
On Wed, Mar 27, 2013 at 4:23 PM, Amit Saha  wrote:
> Hi Sayan,
>
> On Wed, Mar 27, 2013 at 4:14 PM, Sayan Chatterjee
>  wrote:
>> Dear All,
>>
>> I am a newbie to Python but have a fair know how of other languages i.e C
>> etc.
>>
>> I want to run an astrophysical simulation in Python. All I have to do it to
>> generate a set of 'plots' depending on a varying parameter and then stitch
>> them up.
>>
>> 1) Is it possible to automatically generate different data files( say in the
>> orders of 1000) with different names depending on a parameter?
>
> It certainly is. Are you talking about the file names being
> file_1001.txt, file_1002.txt and so on? If yes, let's say  your
> parameter values are stored in param. Then something like this would
> do the trick:
>
> param_values = [1000,1001, 1005, 2001]
>
> for param in param_values:
> fname = 'file_' + str(param)
>
>
># write to file fname
>#
>#
>
>
> Sorry if its different from what you are looking for. But yes, its
> certainly possible.
>
>
>>
>> 2) Is it possible to plot the data sets right from Python itself and save
>> the plots in different jpeg files to stitched upon later on.
>
> It is possible to generate plots and save each as JPEGs. [1].
>
> What do you mean by stitching together?

You probably meant creating an animation from them. Yes,  it is
certainly possible. I will try to find a link which makes it really
easy to create an animation out of a bunch of images. Which operating
system are you on?

-Amit.



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


Re: [Tutor] HELP: Creating animation from multiple plots

2013-03-26 Thread Sayan Chatterjee
Thanks a lot for your prompt reply.

1. Yes. This is exactly what I wanted. Creating a bunch of data sets and
then writing script to plot them using gnuplot, but if something can
produce directly 'plots' it will certainly be helpful.

2. Yes. By stitching them up I meant an animation.Sorry for the
ambiguity. Exactly how we can do it Octave.

Pls see this link:
http://www.krizka.net/2009/11/06/creating-animations-with-octave/

I think Python is THE language, which may come to an immediate rescue.

My OS is Linux Mint (Gnome 3)

Sayan


On 27 March 2013 11:57, Amit Saha  wrote:

> On Wed, Mar 27, 2013 at 4:23 PM, Amit Saha  wrote:
> > Hi Sayan,
> >
> > On Wed, Mar 27, 2013 at 4:14 PM, Sayan Chatterjee
> >  wrote:
> >> Dear All,
> >>
> >> I am a newbie to Python but have a fair know how of other languages i.e
> C
> >> etc.
> >>
> >> I want to run an astrophysical simulation in Python. All I have to do
> it to
> >> generate a set of 'plots' depending on a varying parameter and then
> stitch
> >> them up.
> >>
> >> 1) Is it possible to automatically generate different data files( say
> in the
> >> orders of 1000) with different names depending on a parameter?
> >
> > It certainly is. Are you talking about the file names being
> > file_1001.txt, file_1002.txt and so on? If yes, let's say  your
> > parameter values are stored in param. Then something like this would
> > do the trick:
> >
> > param_values = [1000,1001, 1005, 2001]
> >
> > for param in param_values:
> > fname = 'file_' + str(param)
> >
> >
> ># write to file fname
> >#
> >#
> >
> >
> > Sorry if its different from what you are looking for. But yes, its
> > certainly possible.
> >
> >
> >>
> >> 2) Is it possible to plot the data sets right from Python itself and
> save
> >> the plots in different jpeg files to stitched upon later on.
> >
> > It is possible to generate plots and save each as JPEGs. [1].
> >
> > What do you mean by stitching together?
>
> You probably meant creating an animation from them. Yes,  it is
> certainly possible. I will try to find a link which makes it really
> easy to create an animation out of a bunch of images. Which operating
> system are you on?
>
> -Amit.
>
>
>
> --
> http://amitsaha.github.com/
>



-- 


--
*Sayan  Chatterjee*
Dept. of Physics and Meteorology
IIT Kharagpur
Lal Bahadur Shastry Hall of Residence
Room AB 205
Mob: +91 9874513565
blog: www.blissprofound.blogspot.com

Volunteer , Padakshep
www.padakshep.org
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] HELP: Creating animation from multiple plots

2013-03-26 Thread Amit Saha
On Wed, Mar 27, 2013 at 4:36 PM, Sayan Chatterjee
 wrote:
> Thanks a lot for your prompt reply.
>
> 1. Yes. This is exactly what I wanted. Creating a bunch of data sets and
> then writing script to plot them using gnuplot, but if something can produce
> directly 'plots' it will certainly be helpful.

Yes, indeed it is possible. You may want to explore matplotlib a bit.
You can start with this tutorial [1].

[1] http://www.loria.fr/~rougier/teaching/matplotlib/

>
> 2. Yes. By stitching them up I meant an animation.Sorry for the ambiguity.
> Exactly how we can do it Octave.
>
> Pls see this link:
> http://www.krizka.net/2009/11/06/creating-animations-with-octave/

Right, yes, if you see it uses mencoder/ffmpeg to create the
animation. So, if you save your individual plots and then use one of
these tools, you should be able to get the animation done.

Matplotlib itself seems to have some Animated plotting capabilities,
but I haven't had any experience with them.


Best,
Amit.


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


Re: [Tutor] HELP: Creating animation from multiple plots

2013-03-26 Thread Sayan Chatterjee
Yes, ffmpeg will do if multiple plots can be generated using mathplotlib .
I'll look up the links you provided and get back to you, if I can't figure
it out. :)




On 27 March 2013 12:12, Amit Saha  wrote:

> On Wed, Mar 27, 2013 at 4:36 PM, Sayan Chatterjee
>  wrote:
> > Thanks a lot for your prompt reply.
> >
> > 1. Yes. This is exactly what I wanted. Creating a bunch of data sets and
> > then writing script to plot them using gnuplot, but if something can
> produce
> > directly 'plots' it will certainly be helpful.
>
> Yes, indeed it is possible. You may want to explore matplotlib a bit.
> You can start with this tutorial [1].
>
> [1] http://www.loria.fr/~rougier/teaching/matplotlib/
>
> >
> > 2. Yes. By stitching them up I meant an animation.Sorry for the
> ambiguity.
> > Exactly how we can do it Octave.
> >
> > Pls see this link:
> > http://www.krizka.net/2009/11/06/creating-animations-with-octave/
>
> Right, yes, if you see it uses mencoder/ffmpeg to create the
> animation. So, if you save your individual plots and then use one of
> these tools, you should be able to get the animation done.
>
> Matplotlib itself seems to have some Animated plotting capabilities,
> but I haven't had any experience with them.
>
>
> Best,
> Amit.
>
>
> --
> http://amitsaha.github.com/
>



-- 


--
*Sayan  Chatterjee*
Dept. of Physics and Meteorology
IIT Kharagpur
Lal Bahadur Shastry Hall of Residence
Room AB 205
Mob: +91 9874513565
blog: www.blissprofound.blogspot.com

Volunteer , Padakshep
www.padakshep.org
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor