Re: How to tick checkboxes with the same name?

2013-07-26 Thread Peter Otten
malay...@gmail.com wrote:

> вторник, 23 июля 2013 г., 11:25:00 UTC+4 пользователь Peter Otten написал:
>> malay...@gmail.com wrote:

>> For all but the most popular projects a url works wonders. I'm assuming

>> http://grablib.org

> Well, I have read the documentation, I guess the problem lies in somewhat
> different field. As long as I understand it refers to Checkboxgroup
> classes. As checkboxes of interest belong to some common group with the
> common name "a", they do have values different from "True" or "False"
> (probably a sequence?) and I should guess somehow what are the real ones.
> How to do this?

I took a quick look into the source, and it seems that grab has no notion of 
multiple inputs with the same name. My suggested workaround 

>> set_input_by_id(_"a1", True)

doesn't work because (among other things) the id is immediately translated 
into the name. I fear you have to construct the request manually or choose 
another library -- maybe mechanize (Python 2 only)?

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


Newbie: Python 3 and web applications?

2013-07-26 Thread Rui Maciel
I'm currently learning Python, and I've been focusing on Python3.  To try to 
kill two birds with one stone, I would also like to learn the basics of 
writing small web applications.  

These web applications don't need to do much more than provide an interface 
to a small database, and they may not even be required to be accessible 
outside of a LAN.

Does anyone have any tips on what's the best way to start off this 
adventure?


Thanks in advance,
Rui Maciel
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hello Everyone! A simple questions!

2013-07-26 Thread Florian Baumgartner
As alex23 already indicated you created a recursive data-structure (by
inserting a reference to the list into the second place of the list) and
the interpreter handles this gracefully by showing [...].

In case you really want to insert the lists members into the second place
you can assign a copy of the list.

values = [0,1,2]
values[1] = values[:]





2013/7/26 Thanatos xiao 

> >>> values = [0, 1, 2]>>> values[1] = values>>> values[0, [...], 2]
>
> why??
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedded python and threading

2013-07-26 Thread Stefan Behnel
David M. Cotter, 26.07.2013 08:15:
> in my app i initialize python on the main thread, then immediately call 
> PyEval_SaveThread() because i do no further python stuff on the main thread.
> 
> then, for each script i want to run, i use boost::threads to create a new 
> thread, then on that thread i "ensure" the GIL, do my stuff, then release it.
> 
> so, to test concurrency, on my first background thread, i do an infinite loop 
> that just logs "i'm alive", then calls sleep(0.25)
> 
> so that thread continues to run forever (with it's GIL ensured)
> 
> according to the doc: "In order to emulate concurrency of execution, the 
> interpreter regularly tries to switch threads"
> 
> so i figure i can run another thread that does a single print statement:
> 
>> ensure gil
>> print my thing
>> release gil
> 
> and this DOES run.  however, after releasing it's gil, i guess the interpeter 
> gets back to the first back thread, but then has this error immediately:
> 
> 9: Traceback (most recent call last):
> 9:   File "", line 70, in ?
> 9:   File "", line 55, in main
> 9: AttributeError: 'builtin_function_or_method' object has no attribute 
> 'sleep'
> 
> suddenly the sleep module has been unloaded?? huh?  i thought the thread 
> state had been preserved?

You didn't show your code, but as a wild guess, maybe you did

from time import time

instead of

import time

somewhere? If not, please provide the exact example code that you are running.

Stefan


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


Re: Python Script Hashplings

2013-07-26 Thread Devyn Collier Johnson


On 07/25/2013 09:54 AM, MRAB wrote:

On 25/07/2013 14:42, Devyn Collier Johnson wrote:

If I execute a Python3 script with this haspling (#!/usr/bin/python3.3)
and Python3.3 is not installed, but Python3.2 is installed, would the
script still work? Would it fall back to Python3.2?


Why don't you try it?

I hope Dihedral is listening. I would like to see another response 
from HIM.




Good point, but if it falls back to Python3.2, how would I know? Plus, I 
have Python3.3, 3.2, and 2.7 installed. I cannot uninstall them due to 
dependencies.


DCJ
--
http://mail.python.org/mailman/listinfo/python-list


Re: Critic my module

2013-07-26 Thread Devyn Collier Johnson


On 07/25/2013 09:58 AM, Schneider wrote:

Hi,

nice idea.

mybe -  for security reasons - you should ensure, that the right tool 
is called and not some tool put the path with the same name.


bg,
Johannes

On Thu 25 Jul 2013 03:24:30 PM CEST, Devyn Collier Johnson wrote:

Aloha Python Users!

   I made a Python3 module that allows users to use certain Linux
shell commands from Python3 more easily than using os.system(),
subprocess.Popen(), or subprocess.getoutput(). This module (once
placed with the other modules) can be used like this

import boash; boash.ls()

   I attached the module. I plan to release it on the Internet soon,
but feel free to use it now. It is licensed under LGPLv3.

   The name comes from combining "Boa" with "SHell". Notice that the
module's name almost looks like "BASH", a common Linux shell. The Boa
is a constrictor snake. This module makes Unix shells easier to use
via Python3. This brings the system shell closer to the Python shell.


Mahalo,

Devyn Collier Johnson
devyncjohn...@gmail.com






--
GLOBE Development GmbH
Königsberger Strasse 260
48157 MünsterGLOBE Development GmbH
Königsberger Strasse 260
48157 Münster
0251/5205 390


What do you mean by that Schneider?

Mahalo,

Devyn Collier Johnson
devyncjohn...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Script Hashplings

2013-07-26 Thread Devyn Collier Johnson


On 07/25/2013 10:01 AM, Matthew Lefavor wrote:
The answer is "probably not." If you just want to use the latest 
version of Python 3 you have installed on your system, use: 
"#!/usr/bin/python3". When you use the specific minor version numbers, 
they point to that specific minor version.


Actually, the preferred shebang line is of the form: "#!/usr/bin/env 
python3". This way the end users can override the interpreter with, 
say, a virtualenv, rather than being stuck with the system default.



On Thu, Jul 25, 2013 at 9:54 AM, MRAB > wrote:


On 25/07/2013 14:42, Devyn Collier Johnson wrote:

If I execute a Python3 script with this haspling
(#!/usr/bin/python3.3)
and Python3.3 is not installed, but Python3.2 is installed,
would the
script still work? Would it fall back to Python3.2?

Why don't you try it?


I hope Dihedral is listening. I would like to see another
response from HIM.


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







Thanks Matthew Lefavor! But specifically, why use "#!/usr/bin/env 
python3" instead of "#!/usr/bin/python3"?


Mahalo,

DCJ

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


Re: Python Script Hashplings

2013-07-26 Thread Chris Angelico
On Fri, Jul 26, 2013 at 11:37 AM, Devyn Collier Johnson
 wrote:
>
> On 07/25/2013 09:54 AM, MRAB wrote:
>>
>> On 25/07/2013 14:42, Devyn Collier Johnson wrote:
>>>
>>> If I execute a Python3 script with this haspling (#!/usr/bin/python3.3)
>>> and Python3.3 is not installed, but Python3.2 is installed, would the
>>> script still work? Would it fall back to Python3.2?
>>>
>> Why don't you try it?
>>
>>> I hope Dihedral is listening. I would like to see another response from
>>> HIM.
>>>
>>
> Good point, but if it falls back to Python3.2, how would I know? Plus, I
> have Python3.3, 3.2, and 2.7 installed. I cannot uninstall them due to
> dependencies.

Easy:

#!/usr/bin/python3.3
import sys
print(sys.version)

Now run that on lots of different computers (virtual computers work
well for this).

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


Re: Python Script Hashplings

2013-07-26 Thread Tim Golden
On 26/07/2013 11:37, Devyn Collier Johnson wrote:
> 
> On 07/25/2013 09:54 AM, MRAB wrote:
>> On 25/07/2013 14:42, Devyn Collier Johnson wrote:
>>> If I execute a Python3 script with this haspling (#!/usr/bin/python3.3)
>>> and Python3.3 is not installed, but Python3.2 is installed, would the
>>> script still work? Would it fall back to Python3.2?
>>>
>> Why don't you try it?
>>
>>> I hope Dihedral is listening. I would like to see another response
>>> from HIM.
>>>
>>
> Good point, but if it falls back to Python3.2, how would I know? Plus, I
> have Python3.3, 3.2, and 2.7 installed. I cannot uninstall them due to
> dependencies.

Devyn, I'm not a *nix person so someone can point out if I'm wrong, but
my understanding is that the shebang line (or whatever you want to call
it) just tells the shell: run this command to run this file. So you can
put "#!/usr/bin/fish-and-chips" as the first line and it will try to run
the file using /usr/bin/fish-and-chips.

If you put #!/usr/bin/python3.3 the shell will use the executable
/usr/bin/python3.3. It doesn't know or care about Python or its
versions: it won't go looking for some alternative binary. If
/usr/bin/python3.3 isn't there, the shell will fail to run the code with
some kind of error message.

If you or your package manager symlink /usr/bin/python3 to whatever the
latest Python 3.x is on your system then you can safely use
/usr/bin/python3 throughout and let the symlink do the work!

TJG

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


Re: Critic my module

2013-07-26 Thread Devyn Collier Johnson


On 07/25/2013 10:09 AM, Alain Ketterlin wrote:

Devyn Collier Johnson  writes:


I made a Python3 module that allows users to use certain Linux
shell commands from Python3 more easily than using os.system(),
subprocess.Popen(), or subprocess.getoutput(). This module (once
placed with the other modules) can be used like this

Good, but I doubt it's really useful: I think nobody is going to add a
dependency on your module for, basically, one-line wrappers...

Here are a few comments:


def ls():
version = '0.3'
print(subprocess.getoutput('ls'))

version is local here, so basically your first statement is useless
(search for "global" in python's language ref).


def uname():
version = '0.3'
print(platform.uname())

I once learned: "never print anything in a library function". This is a
bad thing to do, for a variety of reasons. For instance, stdout may be
redirected during this call...


def man(x):
version = '0.3'
print(subprocess.getoutput('man' + x))

getoutput is (essentially) Popen(...,shell=True), and the doc says:

"the use of shell=True is strongly discouraged in cases where the
command string is constructed from external input"

(for very good reasons)


def clear_bash_history():
version = '0.3'
print(subprocess.getoutput('history -c'))

Who told you subprocess will use bash? Again, the doc:

"On Unix with shell=True, the shell defaults to /bin/sh."

All your uses of bash-isms may break (esp. "!!")


def firefox():
version = '0.3'
print(subprocess.Popen('(firefox &)'))

See section "Replacing the os.spawn family" in... the doc.


def go_back():
version = '0.3'
print(subprocess.Popen('cd !!:1'))

Hopeless. Have you tried this?


def reboot():
version = '0.3'
print(subprocess.Popen('shutdown -r now'))

What do you expect this to print? I mean, after shutdown/reboot.


version = '0.6b'

So, what's the version? 0.3 or 0.6b

(btw, are you sure this "version" is the same as the one you use in all
functions?).

-- Alain.


The version in each function is the version of that function if users 
want to know what version they are using. The last version is for the 
whole module. The module overall is version 0.6b. The module started 
with a few functions and as I increased the number of functions, I 
increased the module version number. It is a coincidence that all of the 
modules happen to have the same version number. I increase the version 
number after I work on a function. I cannot remember the command to 
print a module's/function's version number, but with that command, you 
could see the version of a particular function or module. No, I have not 
tried go_back(), thank you for catching that.


The main point of this is for shell users that are using Python and do 
not know some of the Python commands. This module would make Python more 
like a Linux shell. For instance, a shell user would type boash.uname() 
because they may not know they can type "import platform; platform.uname()".


I know that printing is not really the best of ideas, but how else can I 
make the output be displayed without quotes or newline marks?


Thank you very much Alain Ketterlin for your feedback!

Mahalo,

DCJ
--
http://mail.python.org/mailman/listinfo/python-list


Re: virtualenv problem

2013-07-26 Thread D. Xenakis
Yeah trying to run virtualenv under IDLE was a desperate move as i couldnt make 
anything work under cmd.

Apparently my problem was that i did not have correctly setup the new path.. 

Solution for me was the following from 
"http://forums.udacity.com/questions/100064678/pip-installation-instructions";

--
..We want to add that directory to your Path environment variable. Path is a 
list of directories where your OS looks for executable files. You will need to 
change the directory if you installed Python in a non-default location.

a. go to Control Panel » System » Advanced » Environment Variables, make sure 
Path is selected under "user variables for
user", and click edit.

b. Add ;C:\Python33\Scripts\ and ;C:\Python33\ (no spaces after the previous 
entry, ';' is the delimiter) to the end of variable value, then click ok. You 
should not be erasing anything, just adding to what's already there.

This just makes it so we don't have to type the full path name whenever we want 
to run pip or other programs in those directories.
"C:\Python33\Scripts\" is the one we want now, but "C:\Python33\" might be 
useful for you in the future.

Restart your computer.
--

I realised that even if i didn't do the above, i could still have got things 
rolling just by cd-ing from the cmd, to the script folder of my Python 
installation.

But hey - learning is a good thing
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RE Module Performance

2013-07-26 Thread wxjmfauth
Le jeudi 25 juillet 2013 22:45:38 UTC+2, Ian a écrit :
> On Thu, Jul 25, 2013 at 12:18 PM, Steven D'Aprano
> 
>  wrote:
> 
> > On Fri, 26 Jul 2013 01:36:07 +1000, Chris Angelico wrote:
> 
> >
> 
> >> On Fri, Jul 26, 2013 at 1:26 AM, Steven D'Aprano
> 
> >>  wrote:
> 
> >>> On Thu, 25 Jul 2013 14:36:25 +0100, Jeremy Sanders wrote:
> 
>  "To conserve memory, Emacs does not hold fixed-length 22-bit numbers
> 
>  that are codepoints of text characters within buffers and strings.
> 
>  Rather, Emacs uses a variable-length internal representation of
> 
>  characters, that stores each character as a sequence of 1 to 5 8-bit
> 
>  bytes, depending on the magnitude of its codepoint[1]. For example,
> 
>  any ASCII character takes up only 1 byte, a Latin-1 character takes up
> 
>  2 bytes, etc. We call this representation of text multibyte.
> 
> >>>
> 
> >>> Well, you've just proven what Vim users have always suspected: Emacs
> 
> >>> doesn't really exist.
> 
> >>
> 
> >> ... lolwut?
> 
> >
> 
> >
> 
> > JMF has explained that it is impossible, impossible I say!, to write an
> 
> > editor using a flexible string representation. Since Emacs uses such a
> 
> > flexible string representation, Emacs is impossible, and therefore Emacs
> 
> > doesn't exist.
> 
> >
> 
> > QED.
> 
> 
> 
> Except that the described representation used by Emacs is a variant of
> 
> UTF-8, not an FSR.  It doesn't have three different possible encodings
> 
> for the letter 'a' depending on what other characters happen to be in
> 
> the string.
> 
> 
> 
> As I understand it, jfm would be perfectly happy if Python used UTF-8
> 
> (or presumably the Emacs variant) as its internal string
> 
> representation.

--

And emacs it probably working smoothly.

Your comment summarized all this stuff very correctly and
very shortly.

utf8/16/32? I do not care. There are all working correctly,
smoothly and efficiently. In fact, these utf's are already
doing correctly, what this FSR is doing in a wrong way.

My preference? utf32. Why? It is the most simple and
consequently performing choice. I'm not a narrow minded
ascii user. (I do not pretend to belong to those who
are solving the quadrature of the circle, I pretend to
belong to those who know, the quadrature of the circle
is not solvable).

Note: text processing tools or tools that have to process
characters — and the tools to build these tools — are all
moving to utf32, if not already done. There are technical
reasons behind this, which are going beyond the
pure raw unicode. There are however still 100% Unicode
compliant.

jmf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RE Module Performance

2013-07-26 Thread wxjmfauth
Le vendredi 26 juillet 2013 05:09:34 UTC+2, Michael Torrie a écrit :
> On 07/25/2013 11:18 AM, Steven D'Aprano wrote:
> 
> > JMF has explained that it is impossible, impossible I say!, to write an 
> 
> > editor using a flexible string representation. Since Emacs uses such a 
> 
> > flexible string representation, Emacs is impossible, and therefore Emacs 
> 
> > doesn't exist.
> 
> 
> 
> Now I'm even more confused.  He once pointed to Go as an example of how
> 
> unicode should be done in a language.  yet Go uses UTF-8 I think.
> 
> 
> 
> But I don't think UTF-8 is what JMF refers to as "flexible string
> 
> representation."  FSR does use 1,2 or 4 bytes per character, but each
> 
> character in the string uses the same width.  That's different from
> 
> UTF-8 or UTF-16, which is variable width per character.

-

>>> sys.getsizeof('––') - sys.getsizeof('–')

I have already explained / commented this.




Hint: To understand Unicode (and every coding scheme), you should
understand "utf". The how and the *why*.

jmf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyGLet, 2to3...?

2013-07-26 Thread Jerry Hill
On Thu, Jul 25, 2013 at 7:49 PM, John Ladasky
 wrote:
> ===
>
> john@john:~/Desktop/pyglet-1.2alpha1$ sudo python3 setup.py install
>
> [sudo] password for john:
>
> running install
> running build
> running build_py
> running install_lib
> running install_egg_info
> Removing /usr/local/lib/python3.3/dist-packages/pyglet-1.2alpha1.egg-info
> Writing /usr/local/lib/python3.3/dist-packages/pyglet-1.2alpha1.egg-info

Pyglet was installed to /usr/local/lib/python3.3/dist-packages ...

> john@john:~/Desktop/pyglet-1.2alpha1$ python3
>
> Python 3.3.1 (default, Apr 17 2013, 22:30:32)
> [GCC 4.7.3] on linux
> Type "help", "copyright", "credits" or "license" for more information.
 import pyglet
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "./pyglet/__init__.py", line 276
> print '[%d] %s%s %s' % (thread, indent, name, location)
>^
> SyntaxError: invalid syntax

... But here, the error message is talking about ./pyglet/__init__.py.
 I think you're accidentally importing the pyglet package from the
local directory instead of from the proper location in dist-packages.
Try changing back to your home directory and trying this again.  I
think you're picking up the code from
~/Desktop/pyglet-1.2alpha1/pyglet instead of from
/usr/local/lib/python3.3/dist-packages.

-- 
Jerry
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RE Module Performance

2013-07-26 Thread wxjmfauth
Le vendredi 26 juillet 2013 05:20:45 UTC+2, Ian a écrit :
> On Thu, Jul 25, 2013 at 8:48 PM, Steven D'Aprano
> 
>  wrote:
> 
> > UTF-8 uses a flexible representation on a character-by-character basis.
> 
> > When parsing UTF-8, one needs to look at EVERY character to decide how
> 
> > many bytes you need to read. In Python 3, the flexible representation is
> 
> > on a string-by-string basis: once Python has looked at the string header,
> 
> > it can tell whether the *entire* string takes 1, 2 or 4 bytes per
> 
> > character, and the string is then fixed-width. You can't do that with
> 
> > UTF-8.
> 
> 
> 
> UTF-8 does not use a flexible representation.  A codec that is
> 
> encoding a string in UTF-8 and examining a particular character does
> 
> not have any choice of how to encode that character; there is exactly
> 
> one sequence of bits that is the UTF-8 encoding for the character.
> 
> Further, for any given sequence of code points there is exactly one
> 
> sequence of bytes that is the UTF-8 encoding of those code points.  In
> 
> contrast, with the FSR there are as many as three different sequences
> 
> of bytes that encode a sequence of code points, with one of them (the
> 
> shortest) being canonical.  That's what makes it flexible.
> 
> 
> 
> Anyway, my point was just that Emacs is not a counter-example to jmf's
> 
> claim about implementing text editors, because UTF-8 is not what he
> 
> (or anybody else) is referring to when speaking of the FSR or
> 
> "something like the FSR".




BTW, it is not necessary to use an endorsed Unicode coding
scheme (utf*), a string literal would have been possible,
but then one falls on memory issures.

All these utf are following the basic coding scheme.

I repeat again.
A coding scheme works with a unique set of characters
and its implementation works with a unique set of
encoded code points (the utf's, in case of Unicode).

And again, that why we live today with all these coding
schemes, or, to take the problem from the other side,
that's because one has to work with a unique set of
encoded code points, that all these coding schemes had to
be created.

utf's have not been created by newbies ;-)

jmf

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


Re: Python Script Hashplings

2013-07-26 Thread MRAB

On 26/07/2013 11:43, Chris Angelico wrote:

On Fri, Jul 26, 2013 at 11:37 AM, Devyn Collier Johnson
 wrote:


On 07/25/2013 09:54 AM, MRAB wrote:


On 25/07/2013 14:42, Devyn Collier Johnson wrote:


If I execute a Python3 script with this haspling (#!/usr/bin/python3.3)
and Python3.3 is not installed, but Python3.2 is installed, would the
script still work? Would it fall back to Python3.2?


Why don't you try it?


I hope Dihedral is listening. I would like to see another response from
HIM.




Good point, but if it falls back to Python3.2, how would I know? Plus, I
have Python3.3, 3.2, and 2.7 installed. I cannot uninstall them due to
dependencies.


Easy:

#!/usr/bin/python3.3
import sys
print(sys.version)

Now run that on lots of different computers (virtual computers work
well for this).


There's also sys.version_info:

>>> import sys
>>> sys.version_info
sys.version_info(major=3, minor=3, micro=2, releaselevel='final', serial=0)

If you want to test what would happen if that version wasn't installed,
set the shebang line to a future version, such as Python 3.4. I doubt
you have that installed! :-)

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


RE: Creating a Simple User Interface for a Function

2013-07-26 Thread Prasad, Ramit
CTSB01 wrote:
> On Thursday, July 25, 2013 3:19:27 PM UTC-4, Dave Angel wrote:
> > On 07/25/2013 12:03 PM, CTSB01 wrote:
> >
> > > I have the following code that runs perfectly:
> >
> >
> > >   def psi_j(x, j):
> >
> > >rtn = []
> >
> > >for n2 in range(0, len(x) * j - 2):
> >
> > >  n = n2 / j
> >
> > >  r = n2 - n * j
> >
> > >  rtn.append(j * x[n] + r * (x[n + 1] - x[n]))
> >
> > >  print 'n2 =', n2, ': n =', n, ' r =' , r, ' rtn =', rtn
> >
> > >return rtn
> >
> > No it doesn't run perfectly.  It'll get a syntax error on the print
> >
> > function call.  That's assuming you're still using Python 3.3.  You
> >
> > really need to start by specifying your environment, without making us
> >
> > look back through previous threads from you.
> >
> > > This code takes a string x = [0,1,1,1,2] for example
> >
> > That's not a string.  A string would be like
> >
> > xx = psi_j("0abcd1234")
> >
> > Perhaps you mean list?  And is it a list of integers, or of arbitrary
> >
> > numbers?  Are there any constraints on the sizes or signs of those numbers?
> >
> > > (it must always begin with 0) and a parameter j, say 2, and outputs a 
> > > string (x = [0, 1, 2, 2, 2,
> 2, 2, 3] in this example).
> >
> > > It does this in two steps: First it decomposes some number m into a 
> > > multiple of j and a remainder.
> >
> > Only if you replace the / with //.  Or just use the function divmod():
> >
> >n, r = divmod(n2, m)
> >
> > >  Then it runs this decomposition through a function on the rtn.append 
> > > line.
> >
> > > Notice that this has cj - 1 terms where c is the number of terms in the 
> > > input string and j is the
> parameter.  Normally, we would like it to be able to calculate cj terms.
> >
> > > This is an issue with the function that I am more than happy to put aside 
> > > for the moment.
> >
> > > My key interest is to be able to make this program
> >
> > So far you have a function, not a program.  If you put it in a text file
> >
> > and run it from python, it'll do nothing but display a syntax error
> >
> > message.  And when you fix that, it'll just run without doing anything.
> >
> >   usable for someone who has no knowledge of programming.  In
> >
> > particular, I need some kind of user interface that prompts
> >
> > > the user to input a string (ideally just by putting in numbers in the 
> > > form 011123334 for example)
> and a parameter,
> >
> > > and then displays the output sequence.  This is essentially what the 
> > > program already does but the
> idea is to make it usable
> >
> > > for even the most technologically disinclined.  Ideally it would do this 
> > > without needing to run
> Python at all.
> >
> > Then why are you asking on the Python forum?  Or perhaps you mean
> >
> > without him knowing he's running Python?  In that case, use a shebang
> >
> > line at the beginning, which will tell Linux to automatically invoke the
> >
> > specified program (or programming language in this case).
> >
> > >  If anyone is able to make this happen in Python I would be eternally 
> > > grateful.
> >
> > If we assume you're running Python 3.3 on Linux, and the user is willing
> >
> > to us the terminal, then how about parsing the string from the command
> >
> > line he types?  You can access it as011123334 a string from sys.argv,
> >
> > and convert it to separate numbers.  Of course as it stands now, you
> >
> > cannot tell whether the user wanted
> >
> >0,1,1,1,2,3,3,3,4
> >
> > or
> >
> >0, 111, 23, 3, 3, 4
> >
> > or something else.
> >
> > DaveA
> 
> Sorry Dave, to answer each part of your response:
> 
> 1) I decided to use Python 2.7, and I will be sure to specify this in all 
> future threads.
> 2) It is a list of positive integers.  In fact, it is always going to be a 
> list of positive increasing
> integers.
> 3) You're right.  What I meant was that if after running that bit of code I 
> enter
> >>> x = [0,1,2,3,4,5]
> >>> psi_j(x,2)
> I will get output that matches my requirements.
> 4) Yes, sorry that's what I meant (if I understood correctly).  I was told 
> elsewhere that I might want
> to try using tkinter.  Essentially I'm trying to create a user interface that 
> allows the user to just
> type in a string 01112345 for example, and choose a parameter (say j=2) and 
> then click a button to run
> the function.  I'd like to be able to run send a .exe file that the user can 
> just open up and use with
> no further setup.

Any UI will work whether graphical or command line. TK is a good choice if you 
assume that the user
has Python installed. If you are planning to create an exe (Windows) then you 
can probably
bundle any GUI library (wx/gtk/qt) but you might be limited by the support of 
the exe creating
tool. I have never created an executable like this, so I am not sure. 

> 
> So on top of the user interface I would also it looks like need to determine 
> how to make Python chang

Re: Python Script Hashplings

2013-07-26 Thread Chris Angelico
On Fri, Jul 26, 2013 at 2:53 PM, MRAB  wrote:
> If you want to test what would happen if that version wasn't installed,
> set the shebang line to a future version, such as Python 3.4. I doubt
> you have that installed! :-)

Be careful, some people DO have a python3.4 binary :) Go for 3.5 for a
bit more reliability.

rosuav@sikorsky:~$ python3.4
3.4.0a0 (default:da7d97ca1ef6, Jul 13 2013, 14:05:08)
[GCC 4.7.2]

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


Re: Newbie: Python 3 and web applications?

2013-07-26 Thread John Gordon
In  Rui Maciel  writes:

> I'm currently learning Python, and I've been focusing on Python3.  To try to 
> kill two birds with one stone, I would also like to learn the basics of 
> writing small web applications.  

> These web applications don't need to do much more than provide an interface 
> to a small database, and they may not even be required to be accessible 
> outside of a LAN.

> Does anyone have any tips on what's the best way to start off this 
> adventure?

I recommend using a web framework such as Django or Pylons.  It's more to
learn, but frameworks handle a ton of low-level details for you and make
web development overall much easier.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: PyGLet, 2to3...?

2013-07-26 Thread Kushal Kumaran
John Ladasky  writes:

> On Thursday, July 25, 2013 3:26:01 PM UTC-7, John Ladasky wrote:
>> I'll try again from scratch, and see whether that clears up my problems.
>
> Nope, that didn't work.
>
> ===
>
> john@john:~/Desktop/pyglet-1.2alpha1$ sudo python3 setup.py install
>
> [sudo] password for john: 
>
> running install
> running build
> running build_py
> running install_lib
> running install_egg_info
> Removing /usr/local/lib/python3.3/dist-packages/pyglet-1.2alpha1.egg-info
> Writing /usr/local/lib/python3.3/dist-packages/pyglet-1.2alpha1.egg-info
>
> john@john:~/Desktop/pyglet-1.2alpha1$ python3
>
> Python 3.3.1 (default, Apr 17 2013, 22:30:32) 
> [GCC 4.7.3] on linux
> Type "help", "copyright", "credits" or "license" for more information.
 import pyglet
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "./pyglet/__init__.py", line 276

--^

Your import is attempting to import from your current directory, which
has the pre-2to3 version of the files packaged in the original
distribution.  Switch away and try again.

> print '[%d] %s%s %s' % (thread, indent, name, location)
>^
> SyntaxError: invalid syntax
>
> ===
>
> The source code link that Kushal posted is dated December 19, 2012.  Since 
> that was several months ago, I double-checked the source code of setup.py in 
> the 1.2alpha1 package that I downloaded.  It would appear to perform the same 
> check of sys.version_info that was shown on the Google Code page.
>
> To see how that check actually runs, I saved a copy of setup.py as setup2.py, 
> adding diagnostic calls to print() as shown in the code block below:
>
> ===
>
> if sys.version_info >= (3,):
> # Automatically run 2to3 when using Python 3
> print("Python version is 3.0 or later.") # I added this
> if _have_setuptools:
> print("Have setuptools.") # I added this
> setup_info["use_2to3"] = True
> else:
> print("Do not have setuptools.") # I added this
> from distutils.command.build_py import build_py_2to3
> setup_info["cmdclass"] = {"build_py" : build_py_2to3}
>
> ===
>
> Here's the output:
>
> ===
>
> john@john:~/Desktop/pyglet-1.2alpha1$ sudo python3 setup2.py install
>
> Python version is 3.0 or later.
> Do not have setuptools.
> running install
> running build
> running build_py
> running install_lib
> running install_egg_info
> Removing /usr/local/lib/python3.3/dist-packages/pyglet-1.2alpha1.egg-info
> Writing /usr/local/lib/python3.3/dist-packages/pyglet-1.2alpha1.egg-info
>
> ===
>
> So, I don't know much yet about this _have_setuptools flag.  I don't know 
> whether it has to be True, instead of False, in order for 2to3 to work 
> properly.  I get the impression from the code that 2to3 should run regardless 
> of the _have_setuptools flag, it is just that the task is accomplished in two 
> different ways?

That seems correct.  My familiarity with the python packaging tools is
limited, though.

-- 
regards,
kushal
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Script Hashplings

2013-07-26 Thread Matthew Lefavor
>
>
> Thanks Matthew Lefavor! But specifically, why use "#!/usr/bin/env python3"
> instead of "#!/usr/bin/python3"?
>

The "env" program looks up its argument in the current $PATH environment
variable, and then executes that. This means you aren't necessarily tied to
/usr/bin/python3. It makes things more portable.

For example, old Linux distributions don't have Python 3 installed with
them, and the user might not have permissions to install Python 3
system-wide. Instead they have it in some sort of ~/HOME/bin directory, and
then that is placed on the path by their .bashrc file. If your shebang line
was "#!/usr/bin/python3", the program wouldn't work without them changing
that line. If the shebang ling was "#!/usr/bin/env python3", it would find
the Python3 binary no problem.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Critic my module

2013-07-26 Thread Alister
> 
> The main point of this is for shell users that are using Python and do
> not know some of the Python commands. This module would make Python more
> like a Linux shell. For instance, a shell user would type boash.uname()
> because they may not know they can type "import platform;
> platform.uname()".

But they will know how to import your module?

to be honest I think this module is a solution looking for a problem & 
you have re-invented the wheel (Square).
don't let that put you off, there are many command line tools that could 
do with a good wrapper to make them easier to use,perhaps you are tryingto 
be too general.
> 
> I know that printing is not really the best of ideas, but how else can I
> make the output be displayed without quotes or newline marks?

as this is a module intended for others to use in their programs (rather 
than a tool in its own right) the correct approach is to return the 
result & lave it for the user to print the result, or process it however 
they require.

-- 
I also never expected Intel to dispose of themselves in such
a cute way.

- Rik van Riel on linux-kernel
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Python Script Hashplings

2013-07-26 Thread Prasad, Ramit
Devyn Collier Johnson wrote:
> Thanks Matthew Lefavor! But specifically, why use "#!/usr/bin/env python3" 
> instead of
> "#!/usr/bin/python3"?
> 
> Mahalo,
> 
> DCJ

I believe this will work on Windows for Python 3.3+ and also with virtualenv. 
https://pypi.python.org/pypi/virtualenv

Virtualenv is highly recommended as it lets you create isolated Python
environments on a per project basis.


~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.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RE Module Performance

2013-07-26 Thread wxjmfauth
Le vendredi 26 juillet 2013 05:20:45 UTC+2, Ian a écrit :
> On Thu, Jul 25, 2013 at 8:48 PM, Steven D'Aprano
> 
>  wrote:
> 
> > UTF-8 uses a flexible representation on a character-by-character basis.
> 
> > When parsing UTF-8, one needs to look at EVERY character to decide how
> 
> > many bytes you need to read. In Python 3, the flexible representation is
> 
> > on a string-by-string basis: once Python has looked at the string header,
> 
> > it can tell whether the *entire* string takes 1, 2 or 4 bytes per
> 
> > character, and the string is then fixed-width. You can't do that with
> 
> > UTF-8.
> 
> 
> 
> UTF-8 does not use a flexible representation.  A codec that is
> 
> encoding a string in UTF-8 and examining a particular character does
> 
> not have any choice of how to encode that character; there is exactly
> 
> one sequence of bits that is the UTF-8 encoding for the character.
> 
> Further, for any given sequence of code points there is exactly one
> 
> sequence of bytes that is the UTF-8 encoding of those code points.  In
> 
> contrast, with the FSR there are as many as three different sequences
> 
> of bytes that encode a sequence of code points, with one of them (the
> 
> shortest) being canonical.  That's what makes it flexible.
> 
> 
> 
> Anyway, my point was just that Emacs is not a counter-example to jmf's
> 
> claim about implementing text editors, because UTF-8 is not what he
> 
> (or anybody else) is referring to when speaking of the FSR or
> 
> "something like the FSR".

-

Let's be clear. I'm perfectly understanding what is utf-8
and that's for that precise reason, I put the "editor"
as an exemple on the table.

This FSR is not *a* coding scheme. It is more a composite
coding scheme. (And form there, all the problems).

BTW, I'm pleased to read "sequence of bits" and not bytes.
Again, utf transformers are producing sequence of bits,
call Unicode Transformation Units, with lengths of
8/16/32 *bits*, from there the names utf8/16/32.
UCS transformers are (were) producing bytes, from there
the names ucs-2/4.

jmf


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


Re: how to package embedded python?

2013-07-26 Thread David M. Cotter
does nobody know how to do this?
does nobody know where proper documentation on this is?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedded python and threading

2013-07-26 Thread David M. Cotter
okay, i have simplified it:  here is the code

==
import time

def main():
while True:
print "i'm alive"
time.sleep(0.25)

#-
if __name__ == "__main__":
main()
==

the new error is:

==
9: Traceback (most recent call last):
9:   File "", line 10, in ?
9:   File "", line 6, in main
9: AttributeError: 'builtin_function_or_method' object has no attribute 
'sleep'
==
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedded python and threading

2013-07-26 Thread David Robinow
Works for me.
Except that if I then do:
  touch time.py

I get the same error as you do.

Can you figure out the problem now?

On Fri, Jul 26, 2013 at 11:57 AM, David M. Cotter  wrote:
> okay, i have simplified it:  here is the code
>
> ==
> import time
>
> def main():
> while True:
> print "i'm alive"
> time.sleep(0.25)
>
> #-
> if __name__ == "__main__":
> main()
> ==
>
> the new error is:
>
> ==
> 9: Traceback (most recent call last):
> 9:   File "", line 10, in ?
> 9:   File "", line 6, in main
> 9: AttributeError: 'builtin_function_or_method' object has no attribute 
> 'sleep'
> ==
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedded python and threading

2013-07-26 Thread John Gordon
In <965b463e-e5bf-4ccd-9a3c-b0cb964b3...@googlegroups.com> "David M. Cotter" 
 writes:

> ==
> 9: Traceback (most recent call last):
> 9:   File "", line 10, in ?
> 9:   File "", line 6, in main
> 9: AttributeError: 'builtin_function_or_method' object has no attribute 
> 'sleep'
> ==

You must have a file named 'time.py' in the current directory, and the
import statement is getting that module instead of the system time module.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Critic my module

2013-07-26 Thread Joshua Landau
On 26 July 2013 16:08, Alister  wrote:

> >
> > The main point of this is for shell users that are using Python and do
> > not know some of the Python commands. This module would make Python more
> > like a Linux shell. For instance, a shell user would type boash.uname()
> > because they may not know they can type "import platform;
> > platform.uname()".
>
> But they will know how to import your module?
>
> to be honest I think this module is a solution looking for a problem &
> you have re-invented the wheel (Square).
> don't let that put you off, there are many command line tools that could
> do with a good wrapper to make them easier to use,perhaps you are tryingto
> be too general.


I actually think
http://plumbum.readthedocs.org
, http://sarge.readthedocs.org and http://amoffat.github.io/sh/ do a really
good job at this. I might one day even try them ;).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedded python and threading

2013-07-26 Thread David M. Cotter
no, there is no "time.py" anywhere (except perhaps as the actual python library 
originally imported)

did you understand that the function works perfectly, looping as it should, up 
until the time i run a second script on a separate thread?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedded python and threading

2013-07-26 Thread David M. Cotter
DOH!  as my second thread, i had been using a sample script that i had 
copy-pasted without much looking at it.  guess what? it prints the time.  and 
yes, it did "from time import time", which explains it all.

thanks for the hints here, that helped me figure it out!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: embedded python and threading

2013-07-26 Thread Stefan Behnel
David M. Cotter, 26.07.2013 19:28:
> DOH!  as my second thread, i had been using a sample script that i had 
> copy-pasted without much looking at it.  guess what? it prints the time.  and 
> yes, it did "from time import time", which explains it all.

Ah, and you were using the same globals dict for both scripts, I guess?
That explains it then.

Stefan


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


dump a multi dimensional dictionary

2013-07-26 Thread cerr
Hi,

Can I somehow use pickle.dump() to store a dictionary of lists to a file?
I tried this:

>>> import pickle
>>> mylist = []
>>> mydict = {}
>>> mylist = '1','2'
>>> mydict['3'] = mylist
>>> fhg = open ("test", 'w')
>>> pickle.dump(fhg,mydict)
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.7/pickle.py", line 1370, in dump
Pickler(file, protocol).dump(obj)
  File "/usr/lib/python2.7/pickle.py", line 203, in __init__
self.write = file.write
AttributeError: 'dict' object has no attribute 'write'
>>> print mydict
{'3': ('1', '2')}

or should I just write my own dump function that can hanle thiS?

Please advise!

Thanks,
Ron
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dump a multi dimensional dictionary

2013-07-26 Thread John Gordon
In  cerr 
 writes:

> Can I somehow use pickle.dump() to store a dictionary of lists to a file?
> I tried this:

> >>> import pickle
> >>> mylist = []
> >>> mydict = {}
> >>> mylist = '1','2'
> >>> mydict['3'] = mylist
> >>> fhg = open ("test", 'w')
> >>> pickle.dump(fhg,mydict)
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python2.7/pickle.py", line 1370, in dump
> Pickler(file, protocol).dump(obj)
>   File "/usr/lib/python2.7/pickle.py", line 203, in __init__
> self.write = file.write
> AttributeError: 'dict' object has no attribute 'write'
> >>> print mydict
> {'3': ('1', '2')}

> or should I just write my own dump function that can hanle thiS?

I think you have the arguments to pickle.dump() in the wrong order.
The data to be dumped should come first, then the file object.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


RE: dump a multi dimensional dictionary

2013-07-26 Thread Prasad, Ramit
cerr wrote:
> Hi,
> 
> Can I somehow use pickle.dump() to store a dictionary of lists to a file?
> I tried this:
> 
> >>> import pickle
> >>> mylist = []
> >>> mydict = {}
> >>> mylist = '1','2'
> >>> mydict['3'] = mylist
> >>> fhg = open ("test", 'w')
> >>> pickle.dump(fhg,mydict)
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python2.7/pickle.py", line 1370, in dump
> Pickler(file, protocol).dump(obj)
>   File "/usr/lib/python2.7/pickle.py", line 203, in __init__
> self.write = file.write
> AttributeError: 'dict' object has no attribute 'write'
> >>> print mydict
> {'3': ('1', '2')}
> 
> or should I just write my own dump function that can hanle thiS?
> 
> Please advise!
> 
> Thanks,
> Ron

I think you have the parameters for dump backwards.

According to API http://docs.python.org/2/library/pickle.html#pickle.dump
the format is: pickle.dump(obj, file, protocol=None)

Which means you need to use: pickle.dump(mydict, fhg)


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.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Script Hashplings

2013-07-26 Thread Ben Finney
Tim Golden  writes:

> Devyn, I'm not a *nix person so someone can point out if I'm wrong,
> but my understanding is that the shebang line (or whatever you want to
> call it) just tells the shell: run this command to run this file. So
> you can put "#!/usr/bin/fish-and-chips" as the first line and it will
> try to run the file using /usr/bin/fish-and-chips.

Close: it's an instruction not to the shell, but to the kernel. The
shell defers any “run the program in this file” to the kernel, and it's
the kernel that pays attention to the file's shebang line.

-- 
 \  “When cryptography is outlawed, bayl bhgynjf jvyy unir |
  `\  cevinpl.” —Anonymous |
_o__)  |
Ben Finney

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


Re: Python Script Hashplings

2013-07-26 Thread Devyn Collier Johnson


On 07/26/2013 10:14 AM, Chris Angelico wrote:

On Fri, Jul 26, 2013 at 2:53 PM, MRAB  wrote:

If you want to test what would happen if that version wasn't installed,
set the shebang line to a future version, such as Python 3.4. I doubt
you have that installed! :-)

Be careful, some people DO have a python3.4 binary :) Go for 3.5 for a
bit more reliability.

rosuav@sikorsky:~$ python3.4
3.4.0a0 (default:da7d97ca1ef6, Jul 13 2013, 14:05:08)
[GCC 4.7.2]

ChrisA


Thank you everyone for your comments and suggestions. I made a script to 
test the question. see for yourself:


SCRIPT:

#!/usr/bin/env python3.5
import sys; print(sys.version)


OUTPUT IN TERMINAL:

collier@Nacho-Laptop:~$ ./test.py
/usr/bin/env: python3.5: No such file or directory


Mahalo,

DCJ
--
http://mail.python.org/mailman/listinfo/python-list


Re: dump a multi dimensional dictionary

2013-07-26 Thread Chris Angelico
On Fri, Jul 26, 2013 at 9:21 PM, cerr  wrote:
> >>> mylist = []
> >>> mydict = {}
> >>> mylist = '1','2'


Side point: mylist is no longer a list, it's a tuple. I don't think
pickle has problems with tuples, but it's worth noting that
difference.

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


Re: PyGLet, 2to3...?

2013-07-26 Thread John Ladasky
On Thursday, July 25, 2013 4:49:16 PM UTC-7, John Ladasky wrote:
> On Thursday, July 25, 2013 3:26:01 PM UTC-7, John Ladasky wrote:
> 
> > I'll try again from scratch, and see whether that clears up my problems.
> 
> Nope, that didn't work.

Thanks to both Jerry and Kushal.  You were right, I was doing a local import of 
Py2.x code, instead of importing the 2to3-converted code from site-packages.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyGLet, 2to3...?

2013-07-26 Thread John Ladasky
I'm making progress, but I'm not out of the woods yet.

I'm trying to run some of the programs from the tutorial web pages, and from 
the pyglet1.2alpha1/examples directory.  I've realized that I will probably 
need to run 2to3 on the many of the latter.  

The Hello, World example runs.

http://www.pyglet.org/doc/programming_guide/hello_world.html

The Image Viewer example... 

http://www.pyglet.org/doc/programming_guide/image_viewer.html

...runs if I provide a local image file, and load it using pyglet.image.load(). 
 As written, the example fails on the line:

image = pyglet.resource.image('kitten.jpg')  

It's possible that the alpha1.2 version of PyGLet is missing some resources.

It looks like the code for the bouncing ball example ought to work, but it 
doesn't.  That code can be found on the web at:

http://www.pyglet.org/doc/programming_guide/noisy.py

and also in the PyGLet package, in the folder pyglet1.2alpha1/examples/noisy.  

Here's my traceback which, I am sorry to report, I find less than fully 
informative:

===

Traceback (most recent call last):
  File "/usr/local/lib/python3.3/dist-packages/pyglet/__init__.py", line 332, 
in __getattr__
return getattr(self._module, name)
AttributeError: 'NoneType' object has no attribute 'load'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.3/dist-packages/pyglet/lib.py", line 111, in 
load_library
lib = ctypes.cdll.LoadLibrary(name)
  File "/usr/lib/python3.3/ctypes/__init__.py", line 431, in LoadLibrary
return self._dlltype(name)
  File "/usr/lib/python3.3/ctypes/__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libavbin.so: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "noisy.py", line 56, in 
sound = pyglet.resource.media(BALL_SOUND, streaming=False)
  File "/usr/local/lib/python3.3/dist-packages/pyglet/resource.py", line 610, 
in media
return media.load(path, streaming=streaming)
  File "/usr/local/lib/python3.3/dist-packages/pyglet/__init__.py", line 338, 
in __getattr__
__import__(import_name)
  File "/usr/local/lib/python3.3/dist-packages/pyglet/media/__init__.py", line 
1469, in 
from . import avbin
  File "/usr/local/lib/python3.3/dist-packages/pyglet/media/avbin.py", line 64, 
in 
darwin='/usr/local/lib/libavbin.dylib')
  File "/usr/local/lib/python3.3/dist-packages/pyglet/lib.py", line 118, in 
load_library
if ((self.linux_not_found_error not in o.message) and
AttributeError: 'OSError' object has no attribute 'message'

===

I think that only the top few lines of this traceback are relevant.  Somehow a 
None is being passed into some function in pyglet/__init__.py, when that 
function expects an object with an attribute named "load".  Looking at the 
source, the function being called is _ModuleProxy.__getattr__().

I often find that Python's tracebacks stop one level short of what I really 
want to know.  The top level calling function is frequently not named.  What 
part of noisy.py called the code that crashed?  Is there any way to get 
traceback to tell you more?

Anyway, I wondered whether this might be a Python compatibility wart in 
noisy.py.  Thus I tried running 2to3 on noisy.py, even though my eyes told me 
that the code was OK.  2to3 agreed with me, reporting: "RefactoringTool: No 
changes to noisy.py".

I'm not sure where to go next with this.  One thing is for certain, all of this 
is way over the heads of my students...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RE Module Performance

2013-07-26 Thread Michael Torrie
On 07/26/2013 07:21 AM, wxjmfa...@gmail.com wrote:
 sys.getsizeof('––') - sys.getsizeof('–')
> 
> I have already explained / commented this.

Maybe it got lost in translation, but I don't understand your point with
that.

> Hint: To understand Unicode (and every coding scheme), you should
> understand "utf". The how and the *why*.

Hmm, so if python used utf-8 internally to represent unicode strings
would not that punish *all* users (not just non-ascii users) since
searching a string for a certain character position requires an O(n)
operation?  UTF-32 I could see (and indeed that's essentially what FSR
uses when necessary does it not?), but not utf-8 or utf-16.

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


Re: Critic my module

2013-07-26 Thread Steven D'Aprano
As requested, some constructive criticism of your module.

On Thu, 25 Jul 2013 09:24:30 -0400, Devyn Collier Johnson wrote:

> #!/usr/bin/python3
> #Made by Devyn Collier Johnson, NCLA, Linux+, LPIC-1, DCTS

What's NCLA, Linux+, LPIC-1, DCTS? Do these mean anything? Are we 
supposed to know what they mean?

"Made by" has no legal significance. You probably want:

Copyright © 2013 Devyn Collier Johnson.


> #Made using the Geany IDE

Nobody gives a monkey's toss what editor you used to type up the module. 
You might as well mention the brand of monitor you used, or whether the 
keyboard is Dvorak or Qwerty. 


> #LGPLv3

You can't just drop in a mention of "LGPLv3" and expect it to mean 
anything. You actually have to obey the licence yourself, and that 
includes *actually including the licence in your work*. (You're 
technically in violation of the licence at the moment, however since the 
only person whose copyright you are infringing is yourself, it doesn't 
matter. However anyone else using your code is at risk.)

http://www.gnu.org/licenses/gpl-howto.html

In the case of the LGPL, you have to include the text of *both* the GPL 
and the LGPL, not just one.



> import re, sys, subprocess, platform
> def grep(regex,textf):
> #Sample Command: grep.grep("^x",dir()) #Syntax:
> boash.grep(regexp_string,list_of_strings_to_search)

Comments using # are only of use to people reading the source code. If 
you want comments to be available at the interactive prompt, you should 
write them as doc strings:

def grep(regex, textf):
"""This string is a docstring.

Sample command: ...
Blah blah blah
"""

Then, at the interactive prompt, the user can say:

help(boash.grep)

to read the docstring.


>   version = '0.2a'

That's quite useless, since it is a local variable invisible outside of 
the function.

Also, why would you bother giving every individual function a version 
number? That's rather pointless. The user cannot pick and choose function 
A with version number 0.6 and function B with version number 0.7 if the 
module provides versions 0.7 of both.


>   expr = re.compile(regex)
>   match = re.findall(expr, textf)
>   if match != None:
>   print(match)

When comparing with None, it is preferred to use "is" and "is not" rather 
than equality tests.


> def ls():
>   version = '0.3'
>   print(subprocess.getoutput('ls'))
> def dir():
>   version = '0.3'
>   print(subprocess.getoutput('dir'))

A blank line or two between functions does wonders for readability. There 
is no prize for conserving newlines.

You might like to read PEP 8, the Python style guide. It is optional, but 
still makes a very good guide.

http://www.python.org/dev/peps/pep-0008/


> def bash(*arg):
>   version = '0.3'
>   print(subprocess.getoutput(arg))
> def shell(*arg):
>   version = '0.3'
>   print(subprocess.getoutput(arg))

bash is not a synonym for "shell". "The shell" might be sh, csh, bash, or 
any one of many other shells, all of which are slightly (or not so 
slightly) different.


> def clear_bash_history():
>   version = '0.3'
>   print(subprocess.getoutput('history -c'))
[...]

Do you really need ten aliases for 'history -c'?

If you want to define aliases for a function, don't recreate the entire 
function ten times. Start with defining the function once, then:

clear_bash_hist = clear_hist = clear_history = clear_bash_history

etc. But really, having ten names for the one function just confuses 
people, who then wonder what subtle difference there is between 
delete_history and clear_history.

> def firefox():
>   version = '0.3'
>   print(subprocess.Popen('(firefox &)'))

Is Firefox really so important that it needs a dedicated command?

What about Debian users? Doesn't Iceweasel get a command?


> def xterm():
>   version = '0.3'
>   print(subprocess.Popen('(xterm &)'))

Surely the user already has an xterm open, if they are running this 
interactively? Why not just use your xterm's "new window" or "new tab" 
command?


[...delete more trivial calls to subprocess...]

> def repeat_cmd():
>   version = '0.3'
>   print(subprocess.Popen('!!'))
[... delete two exact copies of this function...]

> def ejcd():
>   version = '0.3'
>   print(subprocess.Popen('eject cdrom1'))
[... delete FOURTEEN exact copies of this function...]

Really? Is anyone going to type "eject_disc_tray" instead of "eject"?


I think that will do.

This doesn't really do anything except define a large number of trivial 
wrappers to commands already available in the shell. Emphasis on the 
*trivial* -- with the exception of the grep wrapper, which is all of four 
lines (ignoring the useless internal version number), every single one of 
these wrapper functions is a one-liner.[1] In other words, you're not 
adding any value to the shell commands by wrapping them in Python. There 
are plenty of big, complex shell commands that take a plethora of op

Re: dump a multi dimensional dictionary

2013-07-26 Thread Steven D'Aprano
On Fri, 26 Jul 2013 13:21:47 -0700, cerr wrote:

> or should I just write my own dump function that can hanle thiS?
> 
> Please advise!

Given the choice between reading the documentation to pickle.dump:

help(pickle.dump)


or spending the next month writing a replacement for pickle, testing it, 
debugging it, going through revision after revision to try to bring it to 
the same level of maturity as pickle, which would you prefer? 

:-)


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


Re: RE Module Performance

2013-07-26 Thread Steven D'Aprano
On Thu, 25 Jul 2013 21:20:45 -0600, Ian Kelly wrote:

> On Thu, Jul 25, 2013 at 8:48 PM, Steven D'Aprano
>  wrote:
>> UTF-8 uses a flexible representation on a character-by-character basis.
>> When parsing UTF-8, one needs to look at EVERY character to decide how
>> many bytes you need to read. In Python 3, the flexible representation
>> is on a string-by-string basis: once Python has looked at the string
>> header, it can tell whether the *entire* string takes 1, 2 or 4 bytes
>> per character, and the string is then fixed-width. You can't do that
>> with UTF-8.
> 
> UTF-8 does not use a flexible representation.

I disagree, and so does Jeremy Sanders who first pointed out the 
similarity between Emacs' UTF-8 and Python's FSR. I'll quote from the 
Emacs documentation again:

"To conserve memory, Emacs does not hold fixed-length 22-bit numbers that
are codepoints of text characters within buffers and strings. Rather,
Emacs uses a variable-length internal representation of characters, that
stores each character as a sequence of 1 to 5 8-bit bytes, depending on
the magnitude of its codepoint. For example, any ASCII character takes
up only 1 byte, a Latin-1 character takes up 2 bytes, etc."

And the Python FSR:

"To conserve memory, Python does not hold fixed-length 21-bit numbers that
are codepoints of text characters within buffers and strings. Rather,
Python uses a variable-length internal representation of characters, that
stores each character as a sequence of 1 to 4 8-bit bytes, depending on
the magnitude of the largest codepoint in the string. For example, any 
all-ASCII or all-Latin1 string takes up only 1 byte per character, an all-
BMP string takes up 2 bytes per character, etc."

See the similarity now? Both flexibly change the width used by code-
points, UTF-8 based on the code-point itself regardless of the rest of 
the string, Python based on the largest code-point in the string.


[...]
> Anyway, my point was just that Emacs is not a counter-example to jmf's
> claim about implementing text editors, because UTF-8 is not what he (or
> anybody else) is referring to when speaking of the FSR or "something
> like the FSR".

Whether JMF can see the similarities between different implementations of 
strings or not is beside the point, those similarities do exist. As do 
the differences, of course, but in this case the differences are in 
favour of Python's FSR. Even if your string is entirely Latin1, a UTF-8 
implementation *cannot know that*, and still has to walk the string byte-
by-byte checking whether the current code point requires 1, 2, 3, or 4 
bytes, while a FSR implementation can simply record the fact that the 
string is pure Latin1 at creation time, and then treat it as fixed-width 
from then on.

JMF claims that FSR is "impossible" to use efficiently, and yet he 
supports encoding schemes which are *less* efficient. Go figure. He tells 
us he has no problem with any of the established UTF encodings, and yet 
the FSR internally uses UTF-16 and UTF-32. (Technically, it's UCS-2, not 
UTF-16, since there are no surrogate pairs. But the difference is 
insignificant.)

Having watched this issue from Day One when JMF first complained about 
it, I believe this is entirely about denying any benefit to ASCII users. 
Had Python implemented a system identical to the current FSR except that 
it added a fourth category, "all ASCII", which used an eight-byte 
encoding scheme (thus making ASCII strings twice as expensive as strings 
including code points from the Supplementary Multilingual Planes), JMF 
would be the scheme's number one champion.

I cannot see any other rational explanation for why JMF prefers broken, 
buggy Unicode implementations, or implementations which are equally 
expensive for all strings, over one which is demonstrably correct, 
demonstrably saves memory, and for realistic, non-contrived benchmarks, 
demonstrably faster, except that he wants to punish ASCII users more than 
he wants to support Unicode users.


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


Re: Help

2013-07-26 Thread tyler
Thank you everybody who replied. The problem is fixed now and the program is 
running correctly. I will also try to use your suggestions in the future to 
make sure I don't make the same mistake. Thanks again :).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyGLet, 2to3...?

2013-07-26 Thread John Ladasky
On Friday, July 26, 2013 6:19:48 PM UTC-7, John Ladasky wrote:
> I'm making progress, but I'm not out of the woods yet.

And while I appreciate any comments that may appear here, I've just found the 
pyglet-users group...

https://groups.google.com/forum/#!forum/pyglet-users

...so that's probably the best place for me to ask further questions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RE Module Performance

2013-07-26 Thread Ian Kelly
On Fri, Jul 26, 2013 at 9:37 PM, Steven D'Aprano
 wrote:
> See the similarity now? Both flexibly change the width used by code-
> points, UTF-8 based on the code-point itself regardless of the rest of
> the string, Python based on the largest code-point in the string.

No, I think we're just using the word "flexible" differently.  In my
view, simply being variable-width does not make an encoding "flexible"
in the sense of the FSR.  But I'm not going to keep repeating myself
in order to argue about it.

> Having watched this issue from Day One when JMF first complained about
> it, I believe this is entirely about denying any benefit to ASCII users.
> Had Python implemented a system identical to the current FSR except that
> it added a fourth category, "all ASCII", which used an eight-byte
> encoding scheme (thus making ASCII strings twice as expensive as strings
> including code points from the Supplementary Multilingual Planes), JMF
> would be the scheme's number one champion.

I agree.  In fact I made a similar observation back in December:

http://mail.python.org/pipermail/python-list/2012-December/636942.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RE Module Performance

2013-07-26 Thread Steven D'Aprano
On Fri, 26 Jul 2013 22:12:36 -0600, Ian Kelly wrote:

> On Fri, Jul 26, 2013 at 9:37 PM, Steven D'Aprano
>  wrote:
>> See the similarity now? Both flexibly change the width used by code-
>> points, UTF-8 based on the code-point itself regardless of the rest of
>> the string, Python based on the largest code-point in the string.
> 
> No, I think we're just using the word "flexible" differently.  In my
> view, simply being variable-width does not make an encoding "flexible"
> in the sense of the FSR.  But I'm not going to keep repeating myself in
> order to argue about it.

But I paid for the full half hour!

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


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


Best python web framework to build university/academic website

2013-07-26 Thread b . krishna2020
Hi,

I got a chance to build an university website, within very short period of time.
I know web2py, little bit of Django, so please suggest me the best to build 
rapidly.

Thanks in advance

Raghu
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RE Module Performance

2013-07-26 Thread Steven D'Aprano
On Fri, 26 Jul 2013 08:46:58 -0700, wxjmfauth wrote:

> BTW, I'm pleased to read "sequence of bits" and not bytes. Again, utf
> transformers are producing sequence of bits, call Unicode Transformation
> Units, with lengths of 8/16/32 *bits*, from there the names utf8/16/32.
> UCS transformers are (were) producing bytes, from there the names
> ucs-2/4.


Not only does your distinction between bits and bytes make no practical 
difference on nearly all hardware in common use today[1], but the Unicode 
Consortium disagrees with you, and defines UTC in terms of bytes:

"A Unicode transformation format (UTF) is an algorithmic mapping from 
every Unicode code point (except surrogate code points) to a unique byte 
sequence."

http://www.unicode.org/faq/utf_bom.html#gen2




[1] There may still be some old supercomputers where a byte is more than 
8 bits in use, but they're unlikely to support Unicode.

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