Wednesday, November 13, 2013

comp.lang.python - 26 new messages in 7 topics - digest

comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en

comp.lang.python@googlegroups.com

Today's topics:

* Trying tcompile an use the Python 3.4a - 5 messages, 4 authors
http://groups.google.com/group/comp.lang.python/t/d6eb7f05008cbf25?hl=en
* change volume of single audio device - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/25745adad7a38baa?hl=en
* Jabberbot - 4 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/071b7def880cf522?hl=en
* Reading c struct via python - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/9036dee94b4a9bff?hl=en
* To whoever hacked into my Database - 8 messages, 8 authors
http://groups.google.com/group/comp.lang.python/t/1459c9bdf9ab0ada?hl=en
* Packing byte fields and an array object into struct - 5 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/5db6286e79bc4516?hl=en
* Oh look, another language (ceylon) - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/aca311b925493f87?hl=en

==============================================================================
TOPIC: Trying tcompile an use the Python 3.4a
http://groups.google.com/group/comp.lang.python/t/d6eb7f05008cbf25?hl=en
==============================================================================

== 1 of 5 ==
Date: Wed, Nov 13 2013 7:59 am
From: Steven D'Aprano


On Wed, 13 Nov 2013 16:26:37 +0200, Ferrous Cranus wrote:

> root@secure [~]# which python3
> /usr/local/bin/python3
> root@secure [~]# where pyhton3
> -bash: where: command not found

That just means that you don't have the "where" command installed. Oh
well, if it's not installed you can't use it. (I don't have it installed
on any of my systems either.)


> also how can a link the newset python to just /usr/bin/python.

Don't do that, you will break your system. The OS expects the python
command to be Python 2, not Python 3, and ESPECIALLY not an alpha-quality
version 3.4.

If you decide to ignore this advice, and break your system, don't bother
ask for help here. You won't get any from me.


> here is what i tried
>
> root@secure [~]# ln -s /usr/local/bin/python3 /usr/bin/python ln:
> creating symbolic link `/usr/bin/python': File exists root@secure [~]#

That's not a Python issue, that's a basic Linux sys admin issue. Go buy
yourself a book on Linux and study that. Or do some googling. Read the
man page for ln. Or just spend three seconds thinking about what an error
message like "File exists" could possibly mean.

Really Nikos, you're not a beginner at this. Your English is excellent.
Between simple logic and Google, you ought to be able to work out what
"File exists" means faster than writing a post and sending it here.


--
Steven




== 2 of 5 ==
Date: Wed, Nov 13 2013 8:13 am
From: Steven D'Aprano


On Wed, 13 Nov 2013 16:17:22 +0200, Ferrous Cranus wrote:

> $ mkdir temp
> $ cd temp
> $ wget http://www.python.org/ftp/python/3.4/Python-3.4.tar.bz2 $ tar
> -xjvf Python-3.4.tar.bz2
> $ cd Python-3.3.2
> $ ./configure
> $ make && make test
> $ su
> # make install
> # exit
> $ $ cd ../ && rm -rf Python-3.4
>
>
> root@secure [/home/nikos/www/cgi-bin]# python3 -V Python 3.4.0a4
>
>
> can yu please tell me where python 3.4a was placed in the system?
>
> i tried
>
> #!/usr/bin/python3
> #!/usr/local/bin/python3

And did they work? What result did you get? You've been here long enough
that you ought to know better than to post a question like this without
showing the actual error that you received.


> and also is there a way to call it like #!/usr/bin/python

Of course there is, but only if you wish to break your system. The OS
will be expecting /usr/bin/python to be Python 2. Leave it be.


> i know it can be done via ln 0s but i have to know where the newest
> python got installed.

Here's one way (although not the best):

sudo updatedb
locate python | grep bin

Or, you can start up the Python version of your choice, then do:


py> import sys
py> sys.executable
'/usr/local/bin/python2.5'


--
Steven




== 3 of 5 ==
Date: Wed, Nov 13 2013 8:38 am
From: Ferrous Cranus


Στις 13/11/2013 6:13 μμ, ο/η Steven D'Aprano έγραψε:

>> and also is there a way to call it like #!/usr/bin/python
>
> Of course there is, but only if you wish to break your system. The OS
> will be expecting /usr/bin/python to be Python 2. Leave it be.

Okey i will leave it be although i dislike the idea of using the shebang
constructor as #~/usr/local/bin/python3

Is there any way that i can use it as it was #!/usr/bin/python but
firing python3 instead of python 2.6.6 ?

Also i'm tryong 'yum install python-pip' because some modules like
'pymysql' and 'pygeoip' are missing but CentOS doesn't seem able to
detect it.

Please help me install 'pip' so i can install the modules.




== 4 of 5 ==
Date: Wed, Nov 13 2013 9:29 am
From: Ned Batchelder


On Wednesday, November 13, 2013 11:38:53 AM UTC-5, Ferrous Cranus wrote:
> Στις 13/11/2013 6:13 μμ, ο/η Steven D'Aprano έγραψε:
>
> >> and also is there a way to call it like #!/usr/bin/python
> >
> > Of course there is, but only if you wish to break your system. The OS
> > will be expecting /usr/bin/python to be Python 2. Leave it be.
>
> Okey i will leave it be although i dislike the idea of using the shebang
> constructor as #~/usr/local/bin/python3
>
> Is there any way that i can use it as it was #!/usr/bin/python but
> firing python3 instead of python 2.6.6 ?

No, you can't. "python" should mean Python 2.x. If you want to use Python 3, invoke it as "python3".

BUT: you should have a good reason to switch to Python 3. Your existing Python programs WILL NOT WORK with Python 3. They will require porting from Python 2 to Python 3, and that is not always a simple task, especially when you are dealing with text, such as on a web site.

I strongly recommend that you stay on Python 2, and focus on other concerns. "I want the latest Python" is probably not a good enough reason to switch.

--Ned.




== 5 of 5 ==
Date: Wed, Nov 13 2013 9:45 am
From: Chris "Kwpolska" Warrick


On Wed, Nov 13, 2013 at 5:38 PM, Ferrous Cranus <nikos.gr33k@gmail.com> wrote:
> Στις 13/11/2013 6:13 μμ, ο/η Steven D'Aprano έγραψε:
>
>
>>> and also is there a way to call it like #!/usr/bin/python
>>
>>
>> Of course there is, but only if you wish to break your system. The OS
>> will be expecting /usr/bin/python to be Python 2. Leave it be.
>
>
> Okey i will leave it be although i dislike the idea of using the shebang
> constructor as #~/usr/local/bin/python3
> Is there any way that i can use it as it was #!/usr/bin/python but firing
> python3 instead of python 2.6.6 ?

You can link it to /usr/bin/python3. There should be no problem when
you do this.

> Also i'm tryong 'yum install python-pip' because some modules like 'pymysql'
> and 'pygeoip' are missing but CentOS doesn't seem able to detect it.

That should install it for the Python 2.6.6 you have, and possibly
under the name `python-pip` because of various shenanigans in the
redhatesque repos.

> Please help me install 'pip' so i can install the modules.

http://www.pip-installer.org/en/latest/installing.html#install-or-upgrade-setuptools

Get ez_setup.py and get-pip.py, and run them with the desired Python.

--
Chris "Kwpolska" Warrick <http://kwpolska.tk>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense





==============================================================================
TOPIC: change volume of single audio device
http://groups.google.com/group/comp.lang.python/t/25745adad7a38baa?hl=en
==============================================================================

== 1 of 2 ==
Date: Wed, Nov 13 2013 8:05 am
From: Steven D'Aprano


On Wed, 13 Nov 2013 06:40:02 -0800, moldevort87 wrote:

> on executing i get
> [CODE]
> <<type 'exceptions.WindowsError'> Error 11 while setting volume
> <type 'exceptions.WindowsError'> Error 11 while setting volume
>
> waveOutGetNumDevs= 3
> mixerGetNumDevs 4
> res: 0
> wMid= 6553601
> wPid= 1537
> vDriverVersion= 2037083727
> szPname= o (AMD High Definition Audi
> dwFormats= 2
> wChannels= 36
> res 0
> l: 65535 r: 0
> [/CODE]
>
> Could anyone tell me why this error occurs?

It's a Windows error, not a Python error. You'll need to look up the
documentation for the Windows API used (I think it is
mixerSetControlDetails) and see what return code 11 means. I don't even
know if it's documented.

Start by googling for "mixerSetControlDetails return value 11" and go on
from there.



--
Steven




== 2 of 2 ==
Date: Wed, Nov 13 2013 8:12 am
From: Tim Chase


On 2013-11-13 16:05, Steven D'Aprano wrote:
> Start by googling for "mixerSetControlDetails return value 11" and
> go on from there.

Sounds like Nigel at work.[1]

-tkc


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





==============================================================================
TOPIC: Jabberbot
http://groups.google.com/group/comp.lang.python/t/071b7def880cf522?hl=en
==============================================================================

== 1 of 4 ==
Date: Wed, Nov 13 2013 8:12 am
From: Matt Graves


I'm using the jabberbot library and there is not a whole lot of documentation on it. Does anyone have experience with this library?

This is basically the only example given:


-------------------------
from jabberbot import JabberBot, botcmd
import datetime

class SystemInfoJabberBot(JabberBot):
@botcmd
def serverinfo( self, mess, args):
"""Displays information about the server"""
version = open('/proc/version').read().strip()
loadavg = open('/proc/loadavg').read().strip()

return '%s\n\n%s' % ( version, loadavg, )

@botcmd
def time( self, mess, args):
"""Displays current server time"""
return str(datetime.datetime.now())

@botcmd
def rot13( self, mess, args):
"""Returns passed arguments rot13'ed"""
return args.encode('rot13')

@botcmd
def whoami(self, mess, args):
"""Tells you your username"""
return mess.getFrom().getStripped()


username = 'xxxxxx@xxxx.xxxx.com'
password = 'xxxxx'
bot = SystemInfoJabberBot(username,password)
bot.serve_forever()

-------------------------
I cannot figure out how I would have it simulate a conversation. For example, if I added

@botcmd
def Hello(self, mess, args):
return "Hi, how are you?"

how would I get it to carry on from here? To look for different answers to the response that was returned. Any bit of information would be appreciated.




== 2 of 4 ==
Date: Wed, Nov 13 2013 8:32 am
From: Mark Lawrence



On 13/11/2013 16:12, Matt Graves wrote:
> I'm using the jabberbot library and there is not a whole lot of documentation on it. Does anyone have experience with this library?
>

[snip code from http://thp.io/2007/python-jabberbot/]

> I cannot figure out how I would have it simulate a conversation. For example, if I added
>
> @botcmd
> def Hello(self, mess, args):
> return "Hi, how are you?"
>
> how would I get it to carry on from here? To look for different answers to the response that was returned. Any bit of information would be appreciated.
>

From the link above "More examples

Starting with version 0.7, more examples can be found in the examples/
subdirectory of the source distribution."

Have you looked at these?

--
Python is the second best programming language in the world.
But the best has yet to be invented. Christian Tismer

Mark Lawrence





== 3 of 4 ==
Date: Wed, Nov 13 2013 8:42 am
From: Matt Graves


On Wednesday, November 13, 2013 11:32:24 AM UTC-5, Mark Lawrence wrote:
> On 13/11/2013 16:12, Matt Graves wrote:
>
> > I'm using the jabberbot library and there is not a whole lot of documentation on it. Does anyone have experience with this library?
>
> >
>
>
>
> [snip code from http://thp.io/2007/python-jabberbot/]
>
>
>
> > I cannot figure out how I would have it simulate a conversation. For example, if I added
>
> >
>
> > @botcmd
>
> > def Hello(self, mess, args):
>
> > return "Hi, how are you?"
>
> >
>
> > how would I get it to carry on from here? To look for different answers to the response that was returned. Any bit of information would be appreciated.
>
> >
>
>
>
> From the link above "More examples
>
>
>
> Starting with version 0.7, more examples can be found in the examples/
>
> subdirectory of the source distribution."
>
>
>
> Have you looked at these?
>
>
>
> --
>
> Python is the second best programming language in the world.
>
> But the best has yet to be invented. Christian Tismer
>
>
>
> Mark Lawrence

I have, but unfortunately they are about just as clear as the example I posted. The examples they posted are relevant for certain things, but not what I'm looking to do.




== 4 of 4 ==
Date: Wed, Nov 13 2013 8:56 am
From: Mark Lawrence



On 13/11/2013 16:42, Matt Graves wrote:
> On Wednesday, November 13, 2013 11:32:24 AM UTC-5, Mark Lawrence wrote:
>> On 13/11/2013 16:12, Matt Graves wrote:
>>
>>> I'm using the jabberbot library and there is not a whole lot of documentation on it. Does anyone have experience with this library?
>>
>>>
>>
>>
>>
>> [snip code from http://thp.io/2007/python-jabberbot/]
>>
>>
>>
>>> I cannot figure out how I would have it simulate a conversation. For example, if I added
>>
>>>
>>
>>> @botcmd
>>
>>> def Hello(self, mess, args):
>>
>>> return "Hi, how are you?"
>>
>>>
>>
>>> how would I get it to carry on from here? To look for different answers to the response that was returned. Any bit of information would be appreciated.
>>
>>>
>>
>>
>>
>> From the link above "More examples
>>
>>
>>
>> Starting with version 0.7, more examples can be found in the examples/
>>
>> subdirectory of the source distribution."
>>
>>
>>
>> Have you looked at these?
>>
>>
>>
>> --
>>
>> Python is the second best programming language in the world.
>>
>> But the best has yet to be invented. Christian Tismer
>>
>>
>>
>> Mark Lawrence
>
> I have, but unfortunately they are about just as clear as the example I posted. The examples they posted are relevant for certain things, but not what I'm looking to do.
>

Bah humbug, back to the drawing board :(

Slight aside, would you please read and action this
https://wiki.python.org/moin/GoogleGroupsPython, a quick glance above
will tell you why, thanks.

--
Python is the second best programming language in the world.
But the best has yet to be invented. Christian Tismer

Mark Lawrence






==============================================================================
TOPIC: Reading c struct via python
http://groups.google.com/group/comp.lang.python/t/9036dee94b4a9bff?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Nov 13 2013 9:59 am
From: "Lakshmipathi.G"


> Looks like your "e"... Is that the key field?

Yes, you are right 'e' is the key. And rest of them are data.

>AND the order of the items is "o" before "i"
>-- that doesn't seem to match your C struct definition.

Sorry, I was testing the bdb and while doing that I noticed,
c-struct order is not same as inserted bdb record . But forgot to
fix the struct order before posting it here.

(And also I didn't expect someone will dig this deeper on the binary
string output :p . Thanks for your effort! )


>"s" format in which you precode the length of the string in the
>format ("10s" is a 10 character string), and "p" format in which the first
>byte of the string is the length (0..255) of the rest of the string. The
>struct module doesn't handle C-type null terminated strings directly.

I think we can use 'p' format. (Thus storing the string-length before
actual
string content). That should help us unpack easily.

Thanks Dennis Lee Bieber, for the detailed info and step by step parsing
of the output. It really helped.



--
> Wulfraed Dennis Lee Bieber AF6VN
> wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



--
----
Cheers,
Lakshmipathi.G
FOSS Programmer.
www.giis.co.in





==============================================================================
TOPIC: To whoever hacked into my Database
http://groups.google.com/group/comp.lang.python/t/1459c9bdf9ab0ada?hl=en
==============================================================================

== 1 of 8 ==
Date: Wed, Nov 13 2013 10:11 am
From: Antoon Pardon


Op 13-11-13 15:10, Ian Kelly schreef:

>> Well you can expect all you want. It is not going to happen. Your
>> expectations are completely unrealistic and the way you react will
>> be perceived by a number of people as just an attempt to getting those
>> that are frustrated silenced without much care about what caused those
>> frustrations.
>
> There is absolutely nothing that I can do about what caused those
> frustrations, so what practical difference does it make whether I care
> or not?

If you want to persuade people to change their behaviour, it matters
very much if you can show them you care.

>> It looks like in your world you have a very limited idea of how adults
>> behave. Expecting the others to behave like adults has often enough
>> been the strategy of the priveledged to ignore justified frustration.
>
> Nobody is being disenfranchised here. If you want to make this about
> privilege, then I will just say that I think it is the height of
> privilege to be fussing over the fact that there are people who annoy
> you on the internet, and moreover doing so to the detriment of the
> community.

Is it? Then why are you fussing here? Why don't you address the spoon
feeders who frustrate other group members to the detriment of the community.

>> It is a win either way. If the frustration is uttered in an adult,
>> mature way it doesn't cause much discomfort and is easily ignored. So
>> when those who are frustrated see that being adult and mature doesn't
>> get them much and start reacting a bit less adultly and maturely the
>> frustration can now be dismissed as not being done in an adult and
>> mature way.
>>
>> That is your goal here too. You are not interested in the frustrations
>> of a number of people. You just want to be able to ignore there are
>> frustrated people on the news group.
>
> It's not about me at all. If it were, I would be more likely to just
> unsubscribe than to raise a fuss about it. It's also not about you,
> and it's not even about Nikos. What it is about is that this crap
> about Nikos is often the first thing that newcomers will see when they
> join this group.

So? If this wasn't about you, this just wouldn't make a difference to
you.

> You seem very concerned in your posts about what
> kind of message I'm sending by what I choose to respond to.

Just making sure you were aware of that aspect as the rest of your contribution
strongly suggested you were not.

> Well,
> think about what kind of message it sends to a new user when their
> introduction to the group -- which is supposedly about Python -- is a
> lot of flaming directed at some poster whom they know nothing about.

Well one message obviously is that it is possible to annoy the regulars to
the point that they start flaming you. I don't think that is bad.

> You keep trying to cast certain people who are frustrated by Nikos as
> victims in all this, but they're not. I think that all who have
> posted in this thread, and many who haven't, are probably all
> frustrated in one way or another by all this -- I know that I
> certainly am. The victims are the community as a whole,

The community as a whole suffers when its members get frustrated and
one part of the community telling the other part to just deal with
it is no way to turn the community into something welcoming again and
is IMO more detrimental to the community than a number of people
venting their frustration.

You expect those that get frustrated to tolerate Nikos and to tolerate
the spoon feeding, but you are unable to tolerate the venting of
frustrations.

> and anybody
> who decides not to join because they see this fracas and decide to
> seek out a more inviting forum.

Why would they be a victim? What is there to be victim about seeking
out a more inviting forum? I also think you are confusing a welcome
community with a community without conflict.

> Here's my plea to everybody, in a nutshell. Remember that the name of
> this group is comp.lang.python. It's *not*
> alt.misc.flame.trolls.nikos.sucks.

It is also not alt.misc.keep.spoon.feeding.nikos.

> The topic here is Python, and if
> you want to talk about that, then welcome and please do. If on the
> other hand you just want to vent your frustration, then find somewhere
> else to do it. Please.

But if you want to spoon feed a help vampire to the detriment of the
group you can go right ahead?

--
Antoon Pardon




== 2 of 8 ==
Date: Wed, Nov 13 2013 10:27 am
From: superchromix




hi all,

I've been thinking about learning Python for scientific programming.. but all of these flame war type posts make the user community look pretty lame. How did all of these nice packages get written when most of the user interaction is .... this??

Can anyone tell me, is there another newsgroup where the discussion is more on python programming?

thanks




== 3 of 8 ==
Date: Wed, Nov 13 2013 10:30 am
From: Ned Batchelder


On Wednesday, November 13, 2013 1:27:39 PM UTC-5, superchromix wrote:
> hi all,
>
> I've been thinking about learning Python for scientific programming.. but all of these flame war type posts make the user community look pretty lame. How did all of these nice packages get written when most of the user interaction is .... this??
>
> Can anyone tell me, is there another newsgroup where the discussion is more on python programming?
>
> thanks

I apologize for all of the flame wars. All online communities have to deal with negative forces in their midst, and we are no exception. It doesn't always go smoothly.

Please start a new thread with your question about scientific programming. I promise it won't go badly.

--Ned.




== 4 of 8 ==
Date: Wed, Nov 13 2013 10:47 am
From: lconrad@go2france.com






On Wednesday 13/11/2013 at 12:31 pm, superchromix wrote:
>
>
> hi all,
>
> I've been thinking about learning Python for scientific programming..
> but all of these flame war type posts make the user community look
> pretty lame. How did all of these nice packages get written when most
> of the user interaction is .... this??
>
> Can anyone tell me, is there another newsgroup where the discussion is
> more on python programming?

"most of the user interaction is .... this??"

LOL

hope your problem and code analysis is better than your social
analysis





== 5 of 8 ==
Date: Wed, Nov 13 2013 11:02 am
From: Steve Simmons



On 13/11/2013 19:27, superchromix wrote:
>
> hi all,
>
> I've been thinking about learning Python for scientific programming.. but all of these flame war type posts make the user community look pretty lame. How did all of these nice packages get written when most of the user interaction is .... this??
>
> Can anyone tell me, is there another newsgroup where the discussion is more on python programming?
>
> thanks
Sadly, I'm inclined to agree with you but this is a relatively recent
development.

I joined this group about a year ago and, while it wasn't all 'sweetness
and light', it was a lot better than '. . . . this' - in fact I'd say it
was pretty good, I certainly got treated well and got quality answers to
my (few) questions. Right now, we have a 'help vampire' who has
demanded an inordinate amount of time from the list members - and not in
a polite or well structured way. The members of this list have
responded in various ways, ranging from continuing to help through to
kill-file on the offending person. The discourse around how to deal with
this issue has degenerated into some unfortunate and vitriolic debate.

As far as I can see, it remains possible to post sensible, well
constructed questions and get sensible well-considered answers - just
let the intense arguments pass you by and focus on your own issues and
their resolutions and you'll be fine on this list. There are plenty of
very capable Pythonistas ready to help.

Some basic advice (not wanting to teach you to suck eggs):
- Include relevant info on your environment (OS; version of Python; any
specialist libraries in use; etc)
- Come to the list with a clear description of what you are trying to do
- Preferably include a code sample that displays the problem
- Include the trace-back if you are getting one
- Try to avoid using Google Groups as your 'reader'

Welcome! Ignore the BS and Enjoy :-)

Steve S





== 6 of 8 ==
Date: Wed, Nov 13 2013 11:24 am
From: Zachary Ware


On Wed, Nov 13, 2013 at 12:27 PM, superchromix <markb77@gmail.com> wrote:
>
>
> hi all,
>
> I've been thinking about learning Python for scientific programming.. but all of these flame war type posts make the user community look pretty lame. How did all of these nice packages get written when most of the user interaction is .... this??
>
> Can anyone tell me, is there another newsgroup where the discussion is more on python programming?

Please don't judge the whole community by this thread, I promise we're
not all bad! The majority of the traffic on this list is of a useful
sort, and you can learn fairly quickly the addresses that are best
ignored, blocked, or otherwise passed over. For myself using Gmail, I
have a filter set up to mark particular threads that I don't want to
be notified about and mute them after the first few mails come in. I
didn't see your message initially because it was part of a muted
thread, I only saw it at all because the thread spilled over the 100
message mark into a "new" thread in Gmail with one of the replies to
your message.

Also, if you have a specific question about how to do something in
Python you can try the tutor list (tutor@python.org) which is much
more focused, much lower traffic, and has several very knowledgeable
Pythonistas listening in.

Give us a chance, and I don't think we'll let you down :)

--
Zach




== 7 of 8 ==
Date: Wed, Nov 13 2013 11:36 am
From: Oscar Benjamin


On Nov 13, 2013 6:31 PM, "superchromix" <markb77@gmail.com> wrote:
>
> I've been thinking about learning Python for scientific programming.. but
all of these flame war type posts make the user community look pretty lame.
How did all of these nice packages get written when most of the user
interaction is .... this??

This isn't usually what happens on this list. Most people on this list
(myself included) are ignoring or at least not contributing to these
particular threads.

>
> Can anyone tell me, is there another newsgroup where the discussion is
more on python programming?

For a beginner I would certainly recommend the python-tutor list. I've
never seen a flame war there. Threads tend to stay on-topic and are usually
helpful to the OP. The tutor list is for generic python problems but you
can usually get help for simple scientific programming problems.

https://mail.python.org/mailman/listinfo/tutor

Oscar




== 8 of 8 ==
Date: Wed, Nov 13 2013 12:11 pm
From: William Ray Wing


On Nov 13, 2013, at 1:27 PM, superchromix <markb77@gmail.com> wrote:

>
>
> hi all,
>
> I've been thinking about learning Python for scientific programming.. but all of these flame war type posts make the user community look pretty lame. How did all of these nice packages get written when most of the user interaction is .... this??
>
> Can anyone tell me, is there another newsgroup where the discussion is more on python programming?
>
> thanks
> --
> https://mail.python.org/mailman/listinfo/python-list

I'd like to add one final thought to the note about joining the python-tutor list.
For scientific programming you are almost certainly going to want to learn about scipy, numpy and matplotlib.

These specialized libraries have dedicated discussion groups, which can be found at: <numpy-discussion@scipy.org>, and <matplotlib-users@lists.sourceforge.net>

I'd recommend looking over the material at

http://www.scipy.org

Welcome to the community.

-Bill




==============================================================================
TOPIC: Packing byte fields and an array object into struct
http://groups.google.com/group/comp.lang.python/t/5db6286e79bc4516?hl=en
==============================================================================

== 1 of 5 ==
Date: Wed, Nov 13 2013 10:31 am
From: krishna2prasad@gmail.com


Hello,

I am trying to build a structure to be passed down to an I2C device driver. The driver expects a struct that has a data array of size 512 bytes among other things. This is my code -

rd_wr = 0x0 # Read operation
i2c_addr = addr
mux = mux_sel
multi_len = count
cmd = 0x0
i2c_inst_type = CHEL_I2C_AUTO_RD_TYPE_5
flag = CHEL_I2C_AUTO_VALID
status = 0x0
data = array.array('B', (0 for x in range(0,512)))

os_inst_bytes = (struct.pack('B', rd_wr) +
struct.pack('B', i2c_addr) +
struct.pack('B', mux) +
struct.pack('B', multi_len) +
struct.pack('B', cmd) +
struct.pack('B', i2c_inst_type) +
struct.pack('B', flag) +
struct.pack('I', status) +
struct.pack('512B', data))

#Convert to byte array
os_inst = bytearray(os_inst_bytes)

ret = fcntl.ioctl(self._dev_fd,
self.__IOWR(FXCB_FPGAIO_I2C_AUTO_OS_INST),
os_inst, 1)

I get an error like this -

591 struct.pack('B', flag) +
592 struct.pack('I', status) +

--> 593 struct.pack('512B', data))

error: pack requires exactly 512 arguments

In [1]:

Even though data is a 512 element array, it is not treat as such in this struct.pack. The data field is used to return data from the driver. I should be able to unpack the struct os_inst and read the data buffer after the IOCTL call. How can I achieve this ?

Thanks in advance!




== 2 of 5 ==
Date: Wed, Nov 13 2013 10:44 am
From: Ned Batchelder


On Wednesday, November 13, 2013 1:31:49 PM UTC-5, krishna...@gmail.com wrote:
> Hello,
>
> I am trying to build a structure to be passed down to an I2C device driver. The driver expects a struct that has a data array of size 512 bytes among other things. This is my code -
>
> rd_wr = 0x0 # Read operation
> i2c_addr = addr
> mux = mux_sel
> multi_len = count
> cmd = 0x0
> i2c_inst_type = CHEL_I2C_AUTO_RD_TYPE_5
> flag = CHEL_I2C_AUTO_VALID
> status = 0x0
> data = array.array('B', (0 for x in range(0,512)))
>
> os_inst_bytes = (struct.pack('B', rd_wr) +
> struct.pack('B', i2c_addr) +
> struct.pack('B', mux) +
> struct.pack('B', multi_len) +
> struct.pack('B', cmd) +
> struct.pack('B', i2c_inst_type) +
> struct.pack('B', flag) +
> struct.pack('I', status) +
> struct.pack('512B', data))
>
> #Convert to byte array
> os_inst = bytearray(os_inst_bytes)
>
> ret = fcntl.ioctl(self._dev_fd,
> self.__IOWR(FXCB_FPGAIO_I2C_AUTO_OS_INST),
> os_inst, 1)
>
> I get an error like this -
>
> 591 struct.pack('B', flag) +
> 592 struct.pack('I', status) +
>
> --> 593 struct.pack('512B', data))
>
> error: pack requires exactly 512 arguments
>
> In [1]:
>
> Even though data is a 512 element array, it is not treat as such in this struct.pack. The data field is used to return data from the driver. I should be able to unpack the struct os_inst and read the data buffer after the IOCTL call. How can I achieve this ?
>
> Thanks in advance!

To make a 512-byte field in struct, use '512s' with a data value of ''. It will zero-pad the result and give you 512 zero bytes. Also, you can use multiple format specifiers in one struct.pack call:

os_inst_bytes = struct.pack('7BI512s', rd_wr, i2c_addr, muc, multi_len, cmd, i2c_inst_type, flag, status, '')

Lastly, I suspect the value returned from struct.pack is byte-string enough for the ioctl call, no need to use bytearray.

--Ned.




== 3 of 5 ==
Date: Wed, Nov 13 2013 12:41 pm
From: krishna2prasad@gmail.com


Thanks for your reply Ned!

I tried this your suggestion and this is what it complains...

os_inst_bytes = struct.pack('7BI512s', 0, 0x51, 0x10, 5, 0, 0xD, 0x80, 0, '')

---------------------------------------------------------------------------
error
Traceback (most recent call last)
<ipython-input-6-d36f45a8d3e6> in <module>()
----> 1 os_inst_bytes = struct.pack('7BI512s', 0, 0x51, 0x10, 5, 0, 0xD, 0x80, 0, "")

error: argument for 's' must be a bytes object

In [7]:


And about the bytearray() call, I want to pass a mutable object to the IOCTL to be able to get the data back from the driver. Without bytearray(), the ioctl with mutable flag set to 1 would complain.

I tried to use the p format specifier with pack after converting the array object to byte stream. Packing seems fine. However, I cant seem to unpack.

In [1]: import array

In [2]: import struct

In [3]: data = array.array('B', (1 for x in range(5)))

In [4]: data_bytes = data.tobytes()

In [5]: os_inst_bytes = struct.pack('7BIp', 0, 0x51, 0x10, 5, 0, 0xD, 0x80, 0, data_bytes)

In [6]:

In [6]: os_inst = bytearray(os_inst_bytes)

In [7]: result = struct.unpack('7B', os_inst[0:7])

In [8]: print(result)
(0, 81, 16, 5, 0, 13, 128)

In [9]: result = struct.unpack('I', os_inst[7:11])

In [10]: print(result)
(0,)

In [11]: result = struct.unpack('5s', os_inst[11:16])
---------------------------------------------------------------------------
error Traceback (most recent call last)
<ipython-input-11-da14a6693435> in <module>()
----> 1 result = struct.unpack('5s', os_inst[11:16])

error: unpack requires a bytes object of length 5

In [12]:






== 4 of 5 ==
Date: Wed, Nov 13 2013 12:43 pm
From: krishna2prasad@gmail.com



Correction in the last input line...

In [16]: result = struct.unpack('5p', os_inst[11:16])
---------------------------------------------------------------------------
error Traceback (most recent call last)
<ipython-input-16-42b59e00d5af> in <module>()
----> 1 result = struct.unpack('5p', os_inst[11:16])

error: unpack requires a bytes object of length 5

In [17]:




== 5 of 5 ==
Date: Wed, Nov 13 2013 12:47 pm
From: Ned Batchelder


On Wednesday, November 13, 2013 3:41:03 PM UTC-5, krishna...@gmail.com wrote:
> Thanks for your reply Ned!
>
> I tried this your suggestion and this is what it complains...
>
> os_inst_bytes = struct.pack('7BI512s', 0, 0x51, 0x10, 5, 0, 0xD, 0x80, 0, '')
>
> ---------------------------------------------------------------------------
> error
> Traceback (most recent call last)
> <ipython-input-6-d36f45a8d3e6> in <module>()
> ----> 1 os_inst_bytes = struct.pack('7BI512s', 0, 0x51, 0x10, 5, 0, 0xD, 0x80, 0, "")
>
> error: argument for 's' must be a bytes object
>

OK, looks like you are using Python 3 (it helps to specify these things up-front). Use b"" to get an empty byte-string.


> In [7]:
>
>
> And about the bytearray() call, I want to pass a mutable object to the IOCTL to be able to get the data back from the driver. Without bytearray(), the ioctl with mutable flag set to 1 would complain.

OK, keep the bytearray call if it helps.

--Ned.





==============================================================================
TOPIC: Oh look, another language (ceylon)
http://groups.google.com/group/comp.lang.python/t/aca311b925493f87?hl=en
==============================================================================

== 1 of 1 ==
Date: Wed, Nov 13 2013 11:33 am
From: Neal Becker


http://ceylon-lang.org/documentation/1.0/introduction/





==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en

To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate