[issue46164] New `both()` operator for matching multiple variables to one

2021-12-23 Thread Billy


New submission from Billy :

A new `both()` operator for matching multiple variables to one at the same time.

Currently,
```py
if a == 1 and b == 1:
...
```

With a `both()` operator, it can be done as follows (concept):
```py
if both(a, b) == 1:
...
```

Why? 
-> With the increasing number of variables, it may be hard to compare each of 
them at once, hence this operator can help a lot in such situations. 
Of course, using lists appropriately can solve this issue easily, but a 
general-direct method for achieving this would be a lot helpful. This also 
makes the code more simplistic and easily readable and understandable.



*Sorry for the bad formatting if markdown is not supported for this comment 
section, I couldn't find it mentioned anywhere in the python developer's guide. 
Hence I'm assuming it is supported since it's a common and highly needed 
feature nowadays.

--
messages: 409091
nosy: billyeatcookies
priority: normal
severity: normal
status: open
title: New `both()` operator for matching multiple variables to one
type: enhancement

___
Python tracker 
<https://bugs.python.org/issue46164>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22107] tempfile module misinterprets access denied error on Windows

2019-04-23 Thread Billy McCulloch

Billy McCulloch  added the comment:

I stand by the patch file I previously submitted on 2016-05-04. A more detailed 
analysis / description of my reasoning follows.

Change 1 in _get_default_tempdir:
A PermissionError is thrown on Windows if you attempt to create a file whose 
filename matches an existing directory. As the code currently stands, the `if` 
statement checks whether the proposed file's *parent* directory is a directory 
(which it is, or a FileNotFoundError would have been thrown), instead of 
whether the proposed filename conflicts with an existing directory. The edited 
expression is really a typo that, in the context of the code block, always 
evaluates `True`.
Here’s what we’re now saying in the `if` block: when a PermissionError is 
raised, if we’re on Windows (the only currently supported platform to throw 
nonsense errors at us) AND the filename we chose simply conflicts with an 
existing directory AND we supposedly have write access to the parent directory, 
then we were just unlucky with the chosen name and should try again in the same 
parent directory. (I say supposedly because Windows seems to erroneously report 
True on this check, even when we don’t have write access. I wouldn’t be 
surprised if this last check does something useful in certain contexts, I just 
don’t know what they are.)

Change 2 in _mkstemp_inner:
Same as above for Change 1. While _get_default_tempdir uses this code block to 
make sure the system tempdir is really writable, and _mkstemp_inner does it so 
that a file descriptor can be returned, the result and arguments are the same.

Change 3 in mkdtemp:
For _get_default_tempdir and _mkstemp_inner, the blocks of code in question are 
creating temporary files. As such, they need to handle the oddball case for 
Windows where attempts to create a file with a filename which conflicts with an 
existing directory name result in a PermissionError. The same block of error 
handling code is copied in mkdtemp, even though this function never tries to 
create a file – it only tries to create a directory. As such, in the case that 
we try to create a directory with a name that already exists (whether as a file 
or a directory), we wouldn't be dealing with a PermissionError, we'd have a 
FileExistsError, which is already handled in mkdtemp by the preceding lines. 
The only way I’ve seen a PermissionError crop up for a call to mkdir on Windows 
is if the user doesn’t have permission to create filesystem objects in the 
parent directory. This is the intended usage of a PermissionError, so no 
special handling needed is required. Remember, a PermissionError shouldn’t 
happen if mkdtemp is called without a `dir` kwarg, because the _sanitize_params 
will invoke _get_default_tempdir, which will check to ensure that the parent 
directory is writable. As such, this block of code was superfluous, and the 
patch should not raise PermissionError in user code where it previously was 
caught.

--

___
Python tracker 
<https://bugs.python.org/issue22107>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: any one used moviepy please come in!!! I need help, thanks!

2017-02-23 Thread Billy Earney
 imagemagick (ie, convert) has a policy.xml file that stops you from
accessing any resource that starts with '@'.

type 'identify -list policy'
the first line should tell you where your policy.xml file is located. My
policy.xml file is lcoated at /etc/ImageMagick-6/policy.xml

open that file, and goto to the end and comment out (or remove the line
that reads)



since this is xml, you can comment out this line by appending the line with


Hope this helps!

On Thu, Feb 23, 2017 at 1:05 AM,  wrote:

> On Thursday, January 26, 2017 at 8:12:24 AM UTC+5:30, Tony Chen wrote:
> > On Wednesday, January 25, 2017 at 8:34:01 PM UTC+13, Chris Angelico
> wrote:
> > > On Wed, Jan 25, 2017 at 6:22 PM, Tony Chen 
> wrote:
> > > > This error can be due to the fact that ImageMagick is not installed
> on your computer, or (for Windows users) that you didn't specify the path
> to the ImageMagick binary in file conf.py, or.that the path you specified
> is incorrect
> > >
> > > So... is ImageMagick installed?
> > >
> > > ChrisA
> >
> > Okay... Yes it's installed. This problem has been solved haha. Thank you
> for replying.
>
> Hi Tony,
> same issue facing by me. kindly help me
> please list the solution
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue28274] asyncio does not call exception handler if task stored

2016-09-25 Thread Billy Foster

New submission from Billy Foster:

I found a very strange bug in asyncio where whether exception handlers are 
called depends on whether a task is stored.

To illustrate, the following code works as expected, printing out that it made 
it to the exception handler:

import asyncio
async def run():
raise RuntimeError
def exception_handler(loop, context):
print('Made it to exception handler.')
loop = asyncio.get_event_loop()
loop.set_exception_handler(exception_handler)
loop.create_task(run())
loop.run_forever()

However, if you take that exact same code but store the task that is returned 
from create_task, the exception handler will NOT be called:

import asyncio
async def run():
raise RuntimeError
def exception_handler(loop, context):
print('Made it to exception handler.')
loop = asyncio.get_event_loop()
loop.set_exception_handler(exception_handler)
task = loop.create_task(run())
loop.run_forever()

This is completely bizarre, and I have been unable to track down the reason.

--
components: asyncio
messages: 277394
nosy: billyfoster, gvanrossum, yselivanov
priority: normal
severity: normal
status: open
title: asyncio does not call exception handler if task stored
versions: Python 3.5

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28274>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Python 3.5 Cross Compile for ARM

2016-05-23 Thread billy . t . west
Hi.

Can anyone point me to documentation/instructions for cross compiling Python 
3.5?  I'm trying to compile Python for an ARM processor.

It seems like something broke with cross compilation in 3.5 and a patch was 
created (https://bugs.python.org/issue22359), but I don't even know where to 
begin with this.

If anyone could help me out, I would appreciate it.

Thanks.

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


[issue22107] tempfile module misinterprets access denied error on Windows

2016-05-03 Thread Billy McCulloch

Billy McCulloch added the comment:

I've also run into this bug on Windows. In my case, the tempdir path includes 
directories on a network share, which I lack write access permissions to. 
Python tries to generate a *lot* of files, and never figures out it should move 
on to another directory. The attached patch for tempdir.py resolves my issue.

In _get_default_tempdir() and _mkstemp_inner(), you want to know if the 
filename you tried to create already exists as a directory, not whether the 
parent directory is a directory – that's handled in _get_default_tempdir().

In mkdtemp(), attempting to create a directory with the same name as an 
existing directory does not throw a PermissionError, so the code is superfluous.

--
nosy: +Billy McCulloch
Added file: http://bugs.python.org/file42704/master...bjmcculloch_patch-1.diff

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue22107>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: pyjs - a compiler from Python to JavaScript

2015-08-12 Thread Billy Earney
Uri,

Brython on the other hand, tries to stay true to python (python
compatible).  As stated before it doesn't compile to stand alone
Javascript, but the compile time is usually minimal.  Access to Javascript
libraries is supported.  You really should give it a try..
http://brython.info

Billy

On Tue, Aug 11, 2015 at 7:52 PM, Chris Angelico ros...@gmail.com wrote:

 On Wed, Aug 12, 2015 at 5:08 AM, Fabio Zadrozny fabi...@gmail.com wrote:
 
  As it's just a way to convert from a Python-like syntax to JavaScript
 syntax you can even switch to plain JavaScript later on if you want -- in
 fact, when you debug the code you'll be debugging JavaScript and not Python
 (it's like CoffeScript but with a Python-like syntax).
 

 So, it functions with ECMAScript semantics everywhere? This is an
 important consideration. A Python integer is not the same as an
 ECMAScript number (which is a float), and a Python string is not the
 same as an ECMAScript string, and a Python dictionary has attributes
 and keys which don't collide.

 I'm more than a little tickled by the PyPyJS project:

 http://pypyjs.org/

 That's PyPy running in your web browser. The semantics are 100%
 Python, but... uhh, it does require a fairly hefty download of code
 before it can do anything. That _is_ a bit of a downside, but it's
 still a pretty cool project!

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

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


Re: pyjs - a compiler from Python to JavaScript

2015-08-10 Thread Billy Earney
Uri,

It has been a few years since I have messed with py2js.  Have you checked
out brython?  http://brython.info
It supports javascript libraries such as jQuery, raphael.js, etc.

Billy

On Fri, Aug 7, 2015 at 6:00 AM, Uri Even-Chen u...@speedy.net wrote:

 To Python developers,

 Are you familiar with pyjs http://pyjs.org/? I saw the website and I
 see that the latest stable release is from May 2012. Is it possible to use
 pyjs to compile Python to JavaScript? Which versions of Python are
 supported? Are versions 2.7 and 3.4 supported? And is it possible to use
 Django (in the client side) and JavaScript frameworks such as jQuery,
 jQuery UI and jQuery plugins together with pyjs?

 Thanks,
 Uri.

 *Uri Even-Chen*   [image: photo] Phone: +972-54-3995700
 Email: u...@speedy.net
 Website: http://www.speedysoftware.com/uri/en/
 http://www.facebook.com/urievenchen
 http://plus.google.com/+urievenchen
 http://www.linkedin.com/in/urievenchen  http://twitter.com/urievenchen
  Speedypedia in Hebrew and English
 http://www.speedysoftware.com/uri/blog/speedypedia-in-hebrew-and-english/

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


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


[issue12978] Figure out extended attributes on BSDs

2015-07-20 Thread Billy Foster

Billy Foster added the comment:

Is there any chance of getting this finalized?  I have been using William Orr's 
patch as a workaround for months now, but it would be nice to not have to 
manually apply it each version bump...

--
nosy: +billyfoster

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12978
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Pure Python Data Mangling or Encrypting

2015-06-24 Thread Billy Earney
Freenet seems to come to mind.. :)

On Wed, Jun 24, 2015 at 4:24 PM, Grant Edwards invalid@invalid.invalid
wrote:

 On 2015-06-24, Randall Smith rand...@tnr.cc wrote:
  On 06/24/2015 01:29 PM, Grant Edwards wrote:
  On 2015-06-24, Randall Smith rand...@tnr.cc wrote:
  On 06/24/2015 06:36 AM, Steven D'Aprano wrote:
 
  I don't understand how mangling the data is supposed to protect the
  recipient. Don't they have the ability unmangle the data, and thus
  expose themselves to whatever nasties are in the files?
 
  They never look at the data and wouldn't care to unmangle it.
 
  I obviously don't get it. If the recipient is never going look at
  the data or unmangle it, why not convert every received file to a
  single null byte?  That way you save on disk space as well --
  especially if you just create links for all files after the initial
  one.  ;)
 
  These are machines storing chunks of other people's data.  The data
  owner chunks a file, compresses and encrypts it, then sends it to
  several storage servers.  The storage server might be a Raspberry PI
  with a USB disk or a Windows XP machine - I can't know which.

 OK.  But if the recipient (the server) mangles the data and then never
 unmangles or reads the data, there doesn't seem to be any point in
 storing it.  I must be misunderstanding your statement that the data
 is never read/unmangled.

 --
 Grant Edwards   grant.b.edwardsYow! A can of ASPARAGUS,
   at   73 pigeons, some LIVE
 ammo,
   gmail.comand a FROZEN DAQUIRI!!
 --
 https://mail.python.org/mailman/listinfo/python-list

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


a python pitfall

2015-05-14 Thread Billy Earney
Hello friends:

I saw the following example at
http://nafiulis.me/potential-pythonic-pitfalls.html#using-mutable-default-arguments
and
did not believe the output produced and had to try it for myself

def foo(a,b,c=[]):
c.append(a)
c.append(b)
print(c)

foo(1,1)
foo(1,1)
foo(1,1)

produces:
[1, 1]
[1, 1, 1, 1]
[1, 1, 1, 1, 1, 1]

One would expect the following output:
[1, 1]
[1, 1]
[1, 1]

Doesn't this valid the zen of python: Explicit is better than implicit.  ?

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


Re: seek operation in python

2015-04-29 Thread Billy Earney
if your filename is input.cpp, you first line of code should be:

file=open(input*.cpp*,r)

On Wed, Apr 29, 2015 at 1:26 PM, siva sankari R buddingros...@gmail.com
wrote:

 There is a file named input.cpp(c++ file) that contains some 80 lines of
 code.
 --
 https://mail.python.org/mailman/listinfo/python-list

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


Re: Python implementations in JavaScript

2015-02-14 Thread Billy Earney
Jonathan,

There is Brython.   It has been actively developed for a few years now.  It
is missing some advance python features, but is becoming more python 3.x
compliant every day.  You should check it out,  http://brython.info

You ask, are any of the implementations ready to rely on?   For Brython, it
depends, on what you want to do.   It also hooks into regular javascript
libraries (jquery, etc), if you want to access those.  The Brython docs
cover much of this.

Billy

On Fri, Feb 13, 2015 at 5:05 PM, Jonathan Hayward j...@jsh.name wrote:

 What is the relative maturity of different Python implementations in
 JavaScript? Are any of the implementations ready to rely on?

 --
 [image: Christos Jonathan Seth Hayward] http://jonathanscorner.com/
 Jonathan S. Hayward, a full stack web developer with Python/Django and
 AngularJS/jQuery.

 Articles on Technology http://jonathanscorner.com/technology/ • Book: 
 *Django
 JavaScript Integration*
 http://www.packtpub.com/django-javascript-integration-ajax-and-jquery/book
  • *Email j...@jsh.name* • Github http://github.com/JonathanHayward •
 LinkedIn http://www.linkedin.com/in/jonathanhayward • Main Website
 http://jonathanscorner.com/ • *Professional Site http://jsh.name/*

 I invite you to visit my professional site! http://jsh.name/

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


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


Re: Future of python on android

2014-12-25 Thread Billy Earney
try kivy, instead of sl4a http://kivy.org/

I believe in the past year or two, the python foundation gave a grant to
kivy to add further functionality..

According to wikipedia http://en.wikipedia.org/wiki/Guido_van_Rossum  Guido
works for dropbox.

Billy

On Thu, Dec 25, 2014 at 9:31 AM, Fetchinson . fetchin...@googlemail.com
wrote:

 Hi all,

 I was using sl4a for quite some time on android and it basically
 worked very well although some features are missing. It looks like
 sl4a is dead, although I could be wrong. Does anyone knowledgeable
 have any further info on the future of sl4a? For instance it doesn't
 work with android 5 and there doesn't seem to be any activity around
 it for the past couple of years.

 If sl4a is out, what's the preferred way of running python on android?
 Guido is still working at google, right? This makes me suspect that
 python is ought to be part of the android ecosystem but can't find
 anything else beyond sl4a.

 So what's the future proof way of writing/deploying/installing python
 programs on android?

 Cheers,
 Daniel


 --
 Psss, psss, put it down! - http://www.cafepress.com/putitdown
 --
 https://mail.python.org/mailman/listinfo/python-list

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


PySchool.net, kickstarter campaign

2014-12-14 Thread Billy Earney
Greetings!

For the past few months, I've been developing a website for educators and
students to learn computer programming (ie, Python).  My first project has
been to create a basic programming environment entirely within a browser.
Students can create, edit, load, save, and execute Python scripts directly
in the browser.This coding environment (or IDE) is somewhat similar to
cloud9, but has education in mind, and thus provides a much simpler
environment for those focused on learning.

To keep things short,  here is the URL pyschool.net if you would be
interested in looking at the website.  This is a working application.  Feel
free to use it. There is also a gallery where you can view and execute
examples (many of these come off of the brython.info website,  which helps
power the pyschool.net app).   This is not written in stone.  If educators
make it clear that some other environment is needed, I'm willing to adjust.

I've decided to try to kick this into high gear (it took several months of
my free time (nights/weekends) to get the site where it is). I'd like to
work on this full time, and greatly enhance the site, add tutorials,
(compile existing web resources) and also look at adding some K-4 level
computing resources like blockly (https://code.google.com/p/blockly/)  and
tools to help educators and students.   To do this, I've created a
kickstarter campaign.

The main directives of PySchool.net is to be free for educators and
students forever, to reduce the technological burdens of hosting
programming classes,  and help compile resources to help produce lesson
plans, etc.

Here's the campaign link:

https://www.kickstarter.com/projects/2030013583/pyschoolnet-advancing-python-in-the-classroom

Feel free to check it out.. :)

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


Re: Python console rejects an object reference, having made an object with that reference as its name in previous line

2014-12-14 Thread Billy Earney
It looks like the last line (producer_entries...) is not indented at the
same extent as the previous line.  Maybe this is causing the issue?

On Sun, Dec 14, 2014 at 10:15 AM, Simon Evans musicalhack...@yahoo.co.uk
wrote:

 Dear Python programmers,
 Having input the line of code in text:
 cd Soup
 to the Windows console, and having put the file 'EcologicalPyramid.html'
 into the Directory 'Soup', on the C drive, in accordance with instructions
 I input the following code to the Python console, as given on page 30 of
 'Getting Started with Beautiful Soup':

 
 Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]
 on win
 32
 Type help, copyright, credits or license for more information.
  from bs4 import BeautifulSoup
  with open(ecologicalpyramid.html,r) as ecological_pyramid:
 ...  soup = BeautifulSoup(ecological_pyramid,lxml)
 ... producer_entries = soup.find(ul)

^
 SyntaxError: invalid syntax
  producer_entries = soup.find(ul)
 Traceback (most recent call last):
   File stdin, line 1, in module
 NameError: name 'soup' is not defined
 
^

 
 so I cannot proceed with the next line withh would 've been :

 
 print(producer_entries.li.div.string)

 
 which would've given (according to the book) the output:
 ---
 plants

 Maybe that is getting a bit far ahead, but I can't quite see where I have
 gone wrong - 'soup' has been defined as an object made of file
 'EcologicalPyramid.html

 I hope you can help me on this point.
 Yours
 Simon
 --
 https://mail.python.org/mailman/listinfo/python-list

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


Re: PySchool.net, kickstarter campaign

2014-12-14 Thread Billy Earney
ChrisA,

Yes, you are correct.  The scripts get compiled to javascript and then
executed in the browser.   Like you say, there are limitations, but most of
these focus around browser security issues,  and on the plus side, these
scripts do not get executed on the server side, so that helps reduce risk
there as well.

billy

On Sun, Dec 14, 2014 at 5:26 PM, Chris Angelico ros...@gmail.com wrote:

 On Mon, Dec 15, 2014 at 2:07 AM, Billy Earney billy.ear...@gmail.com
 wrote:
  Students can create, edit, load, save, and execute Python scripts
 directly
  in the browser.

 Importantly, these scripts are actually executed in the client - they
 are NOT being sent to the server for execution. That means there are
 limitations on the language, to be sure, but none of the security
 risks of letting untrusted users run Python code on the server.

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

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


Re: PySchool.net, kickstarter campaign

2014-12-14 Thread Billy Earney
Thanks..  I appreciate your contribution!

On Sun, Dec 14, 2014 at 5:48 PM, Chris Angelico ros...@gmail.com wrote:

 On Mon, Dec 15, 2014 at 10:41 AM, Billy Earney billy.ear...@gmail.com
 wrote:
  Yes, you are correct.  The scripts get compiled to javascript and then
  executed in the browser.   Like you say, there are limitations, but most
 of
  these focus around browser security issues,  and on the plus side, these
  scripts do not get executed on the server side, so that helps reduce risk
  there as well.

 Right. Every form of let the users type Python code in a web site and
 see what it does will have limitations; most of them also have
 security risks, but Brython specifically doesn't.

 I tossed a few dollars into your KS campaign, BTW, but you're going to
 need a *lot* more people than me :)

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

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


Re: Invalid Syntax Installing pip - ez_setup.py

2014-12-01 Thread Billy Furlong
Hi Chris,

Yep that got me closer.  I found that using | sudo python2.7 was a bad command. 
 So I changed over to | python2.7.


[root@myserver tmp]# wget https://bootstrap.pypa.io/ez_setup.py 
--no-check-certificate -O - | python2.7
--2014-12-01 12:57:07--  https://bootstrap.pypa.io/ez_setup.py
Resolving bootstrap.pypa.io... 23.235.46.175
Connecting to bootstrap.pypa.io|23.235.46.175|:443... connected.
WARNING: certificate common name `*.c.ssl.fastly.net' doesn't match requested 
host name `bootstrap.pypa.io'.
HTTP request sent, awaiting response... 200 OK
Length: 10476 (10K) [text/x-python]
Saving to: `STDOUT'

100%[=]
 10,476  --.-K/s   in 0s

2014-12-01 12:57:07 (30.8 MB/s) - `-' saved [10476/10476]

Downloading 
https://pypi.python.org/packages/source/s/setuptools/setuptools-7.0.zip
Traceback (most recent call last):
  File stdin, line 332, in module
  File stdin, line 327, in main
  File stdin, line 287, in download_setuptools
  File stdin, line 224, in download_file_wget
  File stdin, line 169, in _clean_check
  File /opt/python2.7/lib/python2.7/subprocess.py, line 542, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['wget', 
'https://pypi.python.org/packages/source/s/setuptools/setuptools-7.0.zip', 
'--quiet', '--output-document', '/tmp/setuptools-7.0.zip']' returned non-zero 
exit status 1


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


Re: Invalid Syntax Installing pip - ez_setup.py

2014-12-01 Thread Billy Furlong
Success.

Whats happening is that the second wget command is not recognizing the 
--no-check-certificate.  So I went around the problem and installed it manually.

wget https://pypi.python.org/packages/source/s/setuptools/setuptools-7.0.zip 
--no-check-certificate
unzip setuptools-7.0.zip
python2.7 setup.py install
easy_install pip

I'm good.  Pip is installed.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue22699] cross-compilation of Python3.4

2014-10-22 Thread Billy

New submission from Billy:

Who knows to cross-compile Python 3.4?

--
messages: 229828
nosy: bill9889
priority: normal
severity: normal
status: open
title: cross-compilation of Python3.4
type: resource usage
versions: Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22699
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22659] SyntaxError in the configure_ctypes

2014-10-17 Thread Billy

New submission from Billy:

Hi all,

I have a issue with the cross-compilation, here I let it:

  File ../src/setup.py, line 1849
exec(f.read(), globals(), fficonfig)
SyntaxError: unqualified exec is not allowed in function 'configure_ctypes' it 
contains a nested function with free variables
make[1]: *** [sharedmods] Error 1

Who wants to help me, please

Best regards.

--
components: Cross-Build
messages: 229584
nosy: bill9889
priority: normal
severity: normal
status: open
title: SyntaxError in the configure_ctypes
type: compile error
versions: Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22659
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22654] issue with PYTHON_FOR_BUILD

2014-10-16 Thread Billy

New submission from Billy:

Hi all,

I've been cross-compiling Python3.4.1, but I have a issue than is following:

_PYTHON_PROJECT_BASE=/home/aphillips/work/leo368-20141008/fs/apps/python-3.4.1/arm
 _PYTHON_HOST_PLATFORM=linux-arm PYTHONPATH=../src/Lib:../src/Lib/plat-linux  
-S -m  sysconfig --generate-posix-vars ; \
if test $? -ne 0 ; then \
echo generate-posix-vars failed ; \
rm -f ./pybuilddir.txt ; \
exit 1 ; \
fi
/bin/sh: -S: command not found
generate-posix-vars failed
make[1]: *** [pybuilddir.txt] Error 1

If who knows about that, could you help me.

Best regards.

--
components: Cross-Build
messages: 229553
nosy: bill9889
priority: normal
severity: normal
status: open
title: issue with PYTHON_FOR_BUILD
type: compile error
versions: Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22654
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22654] issue with PYTHON_FOR_BUILD

2014-10-16 Thread Billy

Billy added the comment:

Yes, I applied a patch in the configure for than it can make the configuration.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22654
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22654] issue with PYTHON_FOR_BUILD

2014-10-16 Thread Billy

Billy added the comment:

Ned Deil,

For my application I need to use Python 3.4.1 and Why do I need to run the 
./configure for second time?.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22654
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22654] issue with PYTHON_FOR_BUILD

2014-10-16 Thread Billy

Billy added the comment:

I added a patch for the resolution of the issue but it didn't work. You can see 
in my first comment than there is a issue with PYTHONPATH, Do you know why 
happen that.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22654
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Brython (Python in the browser)

2013-12-27 Thread billy . earney
Awesome..  Wonderful work!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is Python in the browser a dead-end ?

2011-10-28 Thread Billy Earney
I believe that python maybe had missed an opportunity to get in early and be
able to take over a large market share from javascript.  But that doesn't
mean python is dead in the browser, it just means it will have more
competition if it wants to replace javascript for Rich Internet
Applications.

there's also emscripten, which takes c code and compiles it into
javascript.  the c python compiler is one of its primary examples as you can
see here:

http://syntensity.com/static/python.html

I've also contributed some code to Skupt so that a person can do something
like

script type='text/python'
 put python code here.
/script

Hopefully eventually, the code I submitted will be of use someday! :)

On Fri, Oct 28, 2011 at 7:07 AM, Amirouche Boubekki 
amirouche.boube...@gmail.com wrote:

 Héllo,

 There was a thread recently about the missed opportunity for Python to be a
 language that could replace Javascript in the browser.

 They are several attempts at doing something in this spirit here are the
 ones I'm aware of:

 - pyjamas aka. pyjs it is to Python what GWT is to Java : http://pyjs.org/
 - py2js which compiles Python to Javascript without high level widget like
 pyjamas does https://github.com/qsnake/py2js
 - skulpt unlike py2js and pyjs there is no compilation phase
 http://www.skulpt.org/

 And SubScript [1], which I am the creator, a Python-like language [2] and
 Sissi [3] which aims at being the stdlib of SubScript, currently it's
 implemented with py2js. It relies heavly on Google Closure tools [4]. I'm
 planning to add streamer [5] support if I can wrap my head around it.

 I'm done with self advertisement.

 Before starting SubScript I gave it some thoughts, and I think that it can
 bring value to web development.

 Here are articles that backs up my vision:

 - Javascript gurus claims that Javascript is indeed the assembly of the
 web [6], which means that Javascript is viable target for a compiler

 - Similar projects exists with Coffescript and ClojureScript which seems to
 have the lead and are gaining traction in web development community. Dart is
 another example.

 - The thing that makes Javascript development difficult is that it's hard
 to debug, but map JS [7] is making its way into Firefox which will help
 greatly

 Why do people think that this projects are doomed ?

 I ask this question to understand other point of views before commiting
 myself at finish SubScript  Sissi, I don't want to code something that will
 be useless.

 Thanks in advance,

 Amirouche

 [1] https://bitbucket.org/abki/subscript
 [2] currently Subscript code is parsed by Python parsing library the exact
 same syntax should be supported
 [3] https://bitbucket.org/abki/sissi/overview
 [4] http://code.google.com/intl/fr/closure/
 [5] https://github.com/Gozala/streamer
 [6]
 http://www.hanselman.com/blog/JavaScriptIsAssemblyLanguageForTheWebSematicMarkupIsDeadCleanVsMachinecodedHTML.aspx
 [7] https://bugzilla.mozilla.org/show_bug.cgi?id=618650

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


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


Re: Java is killing me! (AKA: Java for Pythonheads?)

2011-08-12 Thread Billy Earney
Look into jython.  You might be able to run your python code, directly in
java. :)

http://www.jython.org/


On Fri, Aug 12, 2011 at 12:02 PM, kj no.em...@please.post wrote:




 *Please* forgive me for asking a Java question in a Python forum.
 My only excuse for this no-no is that a Python forum is more likely
 than a Java one to have among its readers those who have had to
 deal with the same problems I'm wrestling with.

 Due to my job, I have to port some Python code to Java, and write
 tests for the ported code.  (Yes, I've considered finding myself
 another job, but this is not an option in the immediate future.)

 What's giving me the hardest time is that the original Python code
 uses a lot of functions with optional arguments (as is natural to
 do in Python).

 As far as I can tell (admittedly I'm no Java expert, and have not
 programmed in it since 2001), to implement a Java method with n
 optional arguments, one needs at least 2**n method definitions.
 Even if all but one of these definitions are simple wrappers that
 call the one that does all the work, it's still a lot of code to
 wade through, for nothing.

 That's bad enough, but even worse is writing the unit tests for
 the resulting mountain of fluffCode.  I find myself writing test
 classes whose constructors also require 2**n definitions, one for
 each form of the function to be tested...

 I ask myself, how does the journeyman Python programmer cope with
 such nonsense?

 For the sake of concreteness, consider the following run-of-the-mill
 Python function of 3 arguments (the first argument, xs, is expected
 to be either a float or a sequence of floats; the second and third
 arguments, an int and a float, are optional):

   def quant(xs, nlevels=MAXN, xlim=MAXX):
if not hasattr(xs, '__iter__'):
return spam((xs,), n, xlim)[0]

if _bad_quant_args(xs, nlevels, xlim):
raise TypeError(invalid arguments)

retval = []
for x in xs:
# ...
# elaborate acrobatics that set y
# ...
retval.append(y)

return retval

 My Java implementation of it already requires at least 8 method
 definitions, with signatures:

short[] quant (float[], int, float)
short[] quant (float[], int   )
short[] quant (float[],  float)
short[] quant (float[])

short   quant (float  , int, float)
short   quant (float  , int   )
short   quant (float  ,  float)
short   quant (float  )

 Actually, for additional reasons, too arcane to go into, I also
 need four more:

short   quant (Float  , Integer, Float)
short   quant (Float  , Integer   )
short   quant (Float  ,  Float)
short   quant (Float  )

 Writing JUnit tests for these methods is literally driving me
 INSANE.

 Some advice on implementing and testing functions with optional
 arguments in Java would be appreciated.

 TIA!

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

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


Re: PyWhich

2011-08-05 Thread Billy Mays

On 08/04/2011 10:03 PM, Chris Angelico wrote:

On Fri, Aug 5, 2011 at 1:34 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info  wrote:

Especially for a tool aimed at programmers (who else would be interested in
PyWhich?)


The use that first springs to my mind is debugging import paths etc.
If you have multiple pythons installed and aren't sure that they're
finding the right modules, you could fire up PyWhich on an innocuous
module like math or sys, and see if it's loading it from the right
path. People doing this might not necessarily be programmers, they
might be sysadmins; but you're right that it's most likely this will
be used by competent Python programmers.

ChrisA


I am trying to do debugging.  I have had some trouble with multiple 
python installs with virtualenv, and I was trying to see where given 
modules came from.  I knew about the code execution, but I couldn't 
think of a clean way to just find out the location rather than load it.


The reason I used stdout was because I was going to be using it in a 
tool chain where the stdout might need to be formatted for another 
program to read in.  Thats also why I was catching ImportError since a 
later version of this script might need to do something special with it.


This is also useful to see if python is really using the module you 
think it is.


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


PyWhich

2011-08-04 Thread Billy Mays

Hey c.l.p.,

I wrote a little python script that finds the file that a python module 
came from.  Does anyone see anything wrong with this script?



#!/usr/bin/python

import sys
if __name__ == '__main__':
if len(sys.argv)  1:
try:
m = __import__(sys.argv[1])
sys.stdout.write(m.__file__ + '\n')
sys.stdout.flush()
sys.exit(0)
except ImportError:
sys.stderr.write(No such module '%s'\n % sys.argv[1])
sys.stderr.flush()
sys.exit(1)
else:
sys.stderr.write(Usage: pywhich module\n)
sys.stderr.flush()
sys.exit(0)


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


Re: where the function has problem? n = 900 is OK , but n = 1000 is ERROR

2011-08-02 Thread Billy Mays

On 08/01/2011 06:06 PM, Steven D'Aprano wrote:

Does your definition of fixed mean gives wrong results for n= 4 ?


fibo(4) == 3

False



Well, I don't know if you're trolling or just dumb:

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

In [2]: for i in range(10):
   ...: print fibo(i)
   ...:
   ...:
0.0
1.0
1.0
2.0
3.0
5.0
8.0
13.0
21.0
34.0


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


Re: where the function has problem? n = 900 is OK , but n = 1000 is ERROR

2011-08-02 Thread Billy Mays

On 08/02/2011 08:45 AM, Alain Ketterlin wrote:

produce integers. And it will fail with overflow for big values.


If it would make you feel better I can use decimal.

Also, perhaps I can name my function billy_fibo(n), which is defined as 
billy_fibo(n) +error(n) = fibo(n), where error(n) can be made 
arbitrarily small.  This runs in constant time rather than linear 
(memoized) or exponential (fully recursive) at the cost of a minutia of 
accuracy.  I find this tradeoff acceptable.


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


Re: where the function has problem? n = 900 is OK , but n = 1000 is ERROR

2011-08-02 Thread Billy Mays

On 08/02/2011 10:15 AM, Steven D'Aprano wrote:

So you say, but I don't believe it. Given fibo, the function you provided
earlier, the error increases with N:


fibo(82) - fib(82)  # fib returns the accurate Fibonacci number

160.0

fibo(182) - fib(182)

2.92786721937918e+23

Hardly arbitrarily small.


Perhaps the individual number is big, but compare that to:

(fibo(n) - fib(n)) / fib(n)

The number is still quite close to the actual answer.


Your function also overflows for N = 1475:


fibo(1475)

Traceback (most recent call last):
   File stdin, line 1, inmodule
   File stdin, line 3, in fibo
OverflowError: (34, 'Numerical result out of range')


The correct value only has 307 digits, so it's not that large a number for
integer math. I won't show them all, but it starts and ends like this:

8077637632...87040886025


Yes, I mentioned possibly using the decimal class, which I suppose does 
lose the constant access time depending on how its implemented.



A good memoisation scheme will run in constant time (amortised).


Amortized perhaps, but this assumes the call happening a number of 
times.  Also, this requires linear memory to store previous values.



Good heavens no. Only the most naive recursive algorithm is exponential.
Good ones (note plural) are linear. Combine that with memoisation, and you
have amortised constant time.



Not all recursive functions can be memoized (or they can but for 
practically no benefit).  What I was getting at was that a closed form 
expression of a recurrence might be significantly faster at an 
acceptable loss in accuracy.  For an example, see the Ackermann function.



Given that Fibonacci numbers are mostly of interest to number theorists, who
care about the *actual* Fibonacci numbers and not almost-but-not-quite
Fibonacci numbers, I'm having a lot of difficulty imagining what sort of
application you have in mind that could legitimately make that trade-off.


I was trying to show that there is an alternate method of calculation. 
Accuracy losses are really a problem with the underlying machinery 
rather than the high level code.  If the recursive form of fib() were 
written in c, the integers would have overflown a long while ago 
compared to float.


One other note, Fibonacci numbers grow exponentially fast (with respect 
to the number of bits), and python's integer multiplication takes 
exponential time (karatsuba rather than fft).  If we are going to 
discuss the behavior of python's numeric types, then lets talk about how 
slow python will become for the nth Fibonacci integer and how much space 
it will take compared to the floating point short concise and almost as 
close form.


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


Re: where the function has problem? n = 900 is OK , but n = 1000 is ERROR

2011-08-01 Thread Billy Mays

On 08/01/2011 05:11 AM, jc wrote:

# Get Fibonacci Value
#Fibonacci(N) = Fibonacci(N-1) + Fibonacci(N-2)
#
# n = 900 is OK
# n = 1000 is ERROR , Why
#
# What Wrong?
#


I have fixed the problem for you:


def fibo(n):
phi = (1+5**.5)/2; iphi = 1-phi;
return (phi**n - iphi**n) / (5**.5)


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


What is xrange?

2011-07-29 Thread Billy Mays
Is xrange not a generator?  I know it doesn't return a tuple or list, so 
what exactly is it?  Y doesn't ever complete, but x does.


x = (i for i in range(10))
y = xrange(10)

print ===X===
while True:
for i in x:
print i
break
else:
break

print ===Y===
while True:
for i in y:
print i
break
else:
break
--
http://mail.python.org/mailman/listinfo/python-list


Re: What's in a name?

2011-07-29 Thread Billy Mays

On 7/29/2011 11:25 PM, Andrew Berg wrote:

In case you want to see the code (not complete by a long shot, and they
need to be refactored):
Module -
http://elucidation.hg.sourceforge.net/hgweb/elucidation/elucidation/file/f8da0b15ecca/elucidation.py
CLI app -
http://disillusion-cli.hg.sourceforge.net/hgweb/disillusion-cli/disillusion-cli/file/947d230dbfc3/disillusion.py
I have no code written for the GUI app yet.

Any ideas?


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


Re: NoneType and new instances

2011-07-28 Thread Billy Mays

On 07/28/2011 11:39 AM, Ethan Furman wrote:

class 'NoneType'
Traceback (most recent call last):
File stdin, line 3, in module
TypeError: cannot create 'NoneType' instances

Why is NoneType unable to produce a None instance? I realise that None
is a singleton, but so are True and False, and bool is able to handle
returning them:

-- bool(0) is bool(0)
True

This feels like a violation of 'Special cases aren't special enough to
break the rules.'

~Ethan~



Probably for the same reason Ellipsis and NotImplemented also can't be 
instantiated.  What that reason is I don't know.  Related:


http://bugs.python.org/issue6477#msg90641

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


Re: How can I make a program automatically run once per day?

2011-07-27 Thread Billy Mays

On 07/27/2011 08:35 AM, Chris Angelico wrote:

On Wed, Jul 27, 2011 at 10:27 PM, Dave Angelda...@ieee.org  wrote:

As Chris pointed out, you probably aren't getting the script's directory
right.  After all, how can the scheduler guess where you put it?  The
obvious answer is to use a full path for the script's filename.  Another
alternative is to fill in the current directory in the appropriate field of
the scheduler's entry.


I would prefer setting the current directory, as that allows the
script to find any data files it needs, but either works.


I find it useful to only add batch files to the scheduler.  Those batch
files can do any setup and cleanup necessary.  In this case, the batch file
might simply set the current directory to the location of the script.


And that is an excellent idea. Definitely recommended.

ChrisA


If it hasn't been mentioned already:

import time

while True:
t1 = time.time()

#your code here

t2 = time.time()
time.sleep( 86400 - (t2 - t1) )



This doesn't take into account leap seconds, but it doesn't depend on a 
task scheduler.  It is also independent of the time your code takes to 
execute.


This is simpler, but it might drift slightly over time.

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


Re: Programming Python for Absolute Beginners

2011-07-27 Thread Billy Mays

On 7/27/2011 11:50 PM, harrismh777 wrote:





No one cares and don't spam the list.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Convolution of different sized arrays

2011-07-26 Thread Billy Mays

On 07/26/2011 08:10 AM, Olenka Subota wrote:

If anyone of you can help, please do it..
Thanks!


You would probably get a better answer asking on one of the mailing 
lists here: http://new.scipy.org/mailing-lists.html

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


Re: reading zipfile; problem using raw buffer

2011-07-26 Thread Billy Mays

On 07/26/2011 08:42 AM, Sells, Fred wrote:

I'm tring to unzip a buffer that is uploaded to django/python.  I can
unzip the file in batch mode just fine, but when I get the buffer I get
a BadZipfile exception.  I wrote this snippet to try to isolate the
issue but I don't understand what's going on.  I'm guessing that I'm
losing some header/trailer somewhere?

def unittestZipfile(filename):
 buffer = ''
 f = open(filename)
 for i in range(22):
 block = f.read()
 if len(block) == 0:
 break
 else:
 buffer += block

 print len(buffer)
 tmp = open('tmp.zip', 'w')
 tmp.write(buffer)
 tmp.close()
 zf = zipfile.ZipFile('tmp.zip')
 print dir(zf)
 for name in zf.namelist():
 print name
 print zf.read(name)

2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)]
Traceback (most recent call last):
   File
C:\all\projects\AccMDS30Server\mds30\app\uploaders\xmitzipfile.py,
line 162, inmodule
 unittestZipfile('wk1live7.8to7.11.zip')
   File
C:\all\projects\AccMDS30Server\mds30\app\uploaders\xmitzipfile.py,
line 146, in unittestZipfile
 print zf.read(name)
   File C:\alltools\python26\lib\zipfile.py, line 837, in read
 return self.open(name, r, pwd).read()
   File C:\alltools\python26\lib\zipfile.py, line 867, in open
 raise BadZipfile, Bad magic number for file header
zipfile.BadZipfile: Bad magic number for file header



You need to specify the file mode since I'm guessing you use Windows 
from the traceback:


f = open(filename, 'rb')

and later:

tmp = open('tmp.zip', 'wb')

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


Re: Only Bytecode, No .py Files

2011-07-26 Thread Billy Mays

On 07/26/2011 11:19 AM, Eldon Ziegler wrote:

Is there a way to have the Python processor look only for bytecode
files, not .py files? We are seeing huge numbers of Linux audit messages
on production system on which only bytecode files are stored. The audit
subsystem is recording each open failure.

Thanks,
Eldon Ziegler




How are you opening your files?

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


Re: Pipe in the return statement

2011-07-25 Thread Billy Mays

On 07/25/2011 10:16 AM, Archard Lias wrote:

On Jul 25, 2:03 pm, Ian Collinsian-n...@hotmail.com  wrote:

On 07/26/11 12:00 AM, Archard Lias wrote:


Hi,



Still I dont get how I am supposed to understand the pipe and its task/
idea/influece on control flow, of:
returnstatement|statement
??


It's simply a bitwise OR.

--
Ian Collins


Yes, but how does it get determined, which one actually gets returned?



The return statement returns a single value from a function context. 
The pipe operator takes 2 values and bitwise ORs* them together.  That 
result is then returned to the caller.  The pipe character in this 
instance is not the same as in a shell.


* This is not exactly true, but don't worry about it.

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


Re: Convert '165.0' to int

2011-07-25 Thread Billy Mays

On 07/25/2011 05:48 AM, Steven D'Aprano wrote:

But if you're calling a function in both cases:

map(int, data)
[int(x) for x in data]



I am aware the premature optimization is a danger, but its also 
incorrect to ignore potential performance pitfalls.


I would favor a generator expression here, if only because I think its 
easier to read.  In addition, it properly handles large amounts of data 
by not duplicating the list.  For very long input sequences, genexp 
would be the proper thing to do (assuming you don't need to index into 
results, in which case, its wrong.)


I think the fastest way to solve the OP's problem is the following: ;)

def convert_165_0_to_int(arg):
return 165


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


Re: Convert '165.0' to int

2011-07-24 Thread Billy Mays

On 7/24/2011 2:27 PM, SigmundV wrote:

On Jul 21, 10:31 am, Frank Millmanfr...@chagford.com  wrote:

Is there a short cut, or must I do this every time (I have lots of them!) ?
I know I can write a function to do this, but is there anything built-in?


I'd say that we have established that there is no shortcut, no built-
in for this. You write you own function:

string_to_int = lambda s: int(float(s))

Then you apply it to your list of strings:

list_of_integers = map(string_to_int, list_of_strings)

Of course, this will be horribly slow if you have thousands of
strings. In such a case you should use an iterator (assuming you use
python 2.7):

import itertools as it
iterator = it.imap(string_to_int, list_of_strings)


Regards,

Sigmund


if the goal is speed, then you should use generator expressions:

list_of_integers = (int(float(s)) for s in list_of_strings)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Convert '165.0' to int

2011-07-23 Thread Billy Mays

On 7/23/2011 3:42 AM, Chris Angelico wrote:


int(s.rstrip('0').rstrip('.'))



Also, it will (in?)correct parse strings such as:

'16500'

to 165.

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


Re: Convert '165.0' to int

2011-07-23 Thread Billy Mays

On 7/23/2011 2:28 PM, rantingrick wrote:


On Jul 23, 1:53 am, Frank Millmanfr...@chagford.com  wrote:

--
The problem with that is that it will silently ignore any non-zero
digits after the point. Of course int(float(x)) does the same, which I
had overlooked.
--


Wait a minute; first you said all you wanted was to cast string
floats to integers NOW your changing the rules.


--
I do not expect any non-zero digits after the point, but if there are,
I would want to be warned, as I should probably be treating it as a
float, not an int.
--

Then the solution is a try:except.

py  def castit(value):
... try:
... v = int(value)
... return v
... except ValueError:
... return float(value)
...
py  castit('165')
165
py  castit('165.0')
165.0
py  castit('165.333')
165.333
py  castit('3.3')
3.3


--
To recap, the original problem is that it would appear that some third-
party systems, when serialising int's into a string format, add a .0
to the end of the string. I am trying to get back to the original int
safely.
--


But you also said you wanted floats too, i am confused??


--
The ideal solution is the one I sketched out earlier - modify python's
'int' function to accept strings such as '165.0'.
--


NO! You create your OWN casting function for special cases.

PythonZEN: Special cases aren't special enough to break the rules.


I'll probably get flak for this, but damn the torpedoes:

def my_int(num):
import re
try:
m = re.match('^(-?[0-9]+)(.0)?$', num)
return int(m.group(1))
except AttributeError:
#raise your own error, or re raise
raise


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


Re: Convert '165.0' to int

2011-07-22 Thread Billy Mays

On 07/22/2011 10:21 AM, Grant Edwards wrote:

While that may be clear to you, that's because you've made some
assumptions.  Convert a properly formatted string representation of a
floating point number to an integer is not a rigorous definition.


What does properly formatted mean?  Who says that the character
representing the radix is . rather than ,?



Properly formatted means that Python would accept the string as an 
argument to float() without raising an exception.




Notice the last digit switched from a 3 to a 2?  Floats in python don't
have arbitrary accuracy.  You would need to import decimal and use it
for rounding to work properly.


It should be floor() though, for that is what int() does.


Um, what?


The example given by the OP implied that int(float(s)) did what he
wanted.  That is _not_ rounding the float.  It's the equivalent of
using the floor() function.



int(float(s)) does the right thing for short strings.  However, for 
longer strings it loses information due to the way floats are 
implemented in Python.  Python uses the IEEE754 double precision 
datatype(double) to implement floating point numbers.  The floats only 
have 53 bits in the mantissa portion of the number which means python 
can only accurately represent integers up to 2**53 correctly as floats.


Compare this to integers in Python, which are automatically upcast to 
longs if overflow would occur.  The int() call will never lose accuracy 
when converting a properly formatted integer string.  float() will lose 
accuracy, even if the float string is properly formatted.  The is no 
floor() being called or used, this is simply the behavior of the float 
datatype.


You seem to be worrying about python producing invalid output for 
invalid input (period  separated numbers).  You should be worrying if 
valid input (a very long float string) produces invalid output.


--
Bill





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


Re: Convert '165.0' to int

2011-07-22 Thread Billy Mays

On 07/22/2011 10:58 AM, Grant Edwards wrote:

On 2011-07-22, Billy 
Mays81282ed9a88799d21e77957df2d84bd6514d9...@myhashismyemail.com  wrote:

Properly formatted means that Python would accept the string as an
argument to float() without raising an exception.


Then you can't assume that '.' is the radix character.



When you use radix, I assume you mean the grouping separator for large 
numbers, not the base correct?  I have always heard radix used as the 
base (ie base 2) of the number, as in radix sort.



No, I'm talking about the claim that you should use decmial so that
you can use rounding when the OP's example showed that rounding was
not what he wanted.



Yes, you are right.  I mistyped what I was thinking.  Let me rephrase:

decimal is needed to preserve the accuracy of the string to `number` 
conversion.


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


Re: Convert '165.0' to int

2011-07-21 Thread Billy Mays

On 07/21/2011 08:46 AM, Web Dreamer wrote:

If you do not want to use 'float()' try:

int(x.split('.')[0])



This is right.


But, the problem is the same as with int(float(x)), the integer number is
still not as close as possible as the original float value.

I would in fact consider doing this:

int(round(float(x)))


This is wrong, since there is a loss of information in the float cast:

 float('9007199254740993.0')
9007199254740992.0

Notice the last digit switched from a 3 to a 2?  Floats in python don't 
have arbitrary accuracy.  You would need to import decimal and use it 
for rounding to work properly.


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


Re: Can someone help please

2011-07-21 Thread Billy Mays

On 07/21/2011 01:02 PM, Gary wrote:

Hi
Can someone help me with this code below please,
For some reason it will not send me the first text file in the directory.
I made up an empty file a.txt file with nothing on it and it sends the
files i need but would like to fix the code.
Thanks




total = ' '
os.chdir('/home/woodygar/Desktop/Docs')
for i in os.listdir('.'):
if '.txt' in i:
f = open(i, 'r')
total += f.read()
f.close()
message = \
Subject: %s
%s

% (SUBJECT,total)



Does the file end with '.TXT' ? This might help:

total = ' '
os.chdir('/home/woodygar/Desktop/Docs')
txts = (nm for nm in os.listdir('.') if nm.lower().endswith('.txt') )
for nm in txts:
f = open(nm, 'r')
total += f.readlines()
f.close()
message = \
Subject: %s
%s

% (SUBJECT,total)




I also changed read to readlines().
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can someone help please

2011-07-21 Thread Billy Mays

On 07/21/2011 01:41 PM, Gary Herron wrote:

On 07/21/2011 10:23 AM, Billy Mays wrote:

On 07/21/2011 01:02 PM, Gary wrote:

Hi
Can someone help me with this code below please,
For some reason it will not send me the first text file in the
directory.
I made up an empty file a.txt file with nothing on it and it sends the
files i need but would like to fix the code.
Thanks




total = ' '
os.chdir('/home/woodygar/Desktop/Docs')
for i in os.listdir('.'):
if '.txt' in i:
f = open(i, 'r')
total += f.read()
f.close()
message = \
Subject: %s
%s

% (SUBJECT,total)



Does the file end with '.TXT' ? This might help:

total = ' '
os.chdir('/home/woodygar/Desktop/Docs')
txts = (nm for nm in os.listdir('.') if nm.lower().endswith('.txt') )
for nm in txts:
f = open(nm, 'r')
total += f.readlines()
f.close()
message = \
Subject: %s
%s

% (SUBJECT,total)




I also changed read to readlines().

That won't work (You must not have even tried to run this.) The call
f.readlines() returns a list which causes an error when added to a string:

TypeError: cannot concatenate 'str' and 'list' objects


Gary Herron





You're right, I didn't.  But thats not really the important part of the 
code.  I believe the generator should work, (and in fact, should 
probably use os.path.walk instead of os.listdir )


--
Bill

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


Re: Convert '165.0' to int

2011-07-21 Thread Billy Mays

On 7/21/2011 10:40 PM, Thomas 'PointedEars' Lahn wrote:

Billy Mays wrote:


On 07/21/2011 08:46 AM, Web Dreamer wrote:

If you do not want to use 'float()' try:

int(x.split('.')[0])


This is right.


Assuming that the value of `x' is in the proper format, of course.  Else you
might easily cut to the first one to three digits of a string representation
(if `.' is the thousands separator of the locale, e. g.)



The point (which was clear to me) was to convert a properly formatted 
string representation of a floating point number to an integer.  We 
might also assume the number could be a hex encoded float or be in 
scientific notation.  If the input is not properly formatted, it is 
unreasonable for us to return a correct value.




But, the problem is the same as with int(float(x)), the integer number is
still not as close as possible as the original float value.

I would in fact consider doing this:

int(round(float(x)))


This is wrong, since there is a loss of information in the float cast:

float('9007199254740993.0')
9007199254740992.0

Notice the last digit switched from a 3 to a 2?  Floats in python don't
have arbitrary accuracy.  You would need to import decimal and use it
for rounding to work properly.


It should be floor() though, for that is what int() does.


Um, what?

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


Return and set

2011-07-19 Thread Billy Mays
I have a method getToken() which checks to see if a value is set, and if 
so, return it.  However, it doesn't feel pythonic to me:


def getToken(self):
if self.tok:
t = self.tok
self.tok = None
return t
# ...


Is there a way to trim the 'if' block to reset self.tok upon return?

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


Re: Return and set

2011-07-19 Thread Billy Mays

On 07/19/2011 09:43 AM, Ben Finney wrote:

Billy Mays
81282ed9a88799d21e77957df2d84bd6514d9...@myhashismyemail.com  writes:


I have a method getToken() which checks to see if a value is set, and
if so, return it. However, it doesn't feel pythonic to me:


Clearly that's because the function name is not Pythonic :-)

I'll assume the name is a PEP-8 compatible ‘get_token’.


def getToken(self):
 if self.tok:
 t = self.tok
 self.tok = None
 return t
 # ...


Are you testing ‘self.tok’ in a boolean context because you don't care
whether it it might be ‘’ or ‘0’ or ‘0.0’ or ‘[]’ or ‘False’ or lots
of other things that evaluate false in a boolean context?

If you want to test whether it is any value other than ‘None’, that's
not the way to do it. Instead, use ‘if self.token is not None’.

But I don't see why you test it at all, in that case, since you're
immediately setting it to ‘None’ afterward.

Also, the function name is quite misleading; the implication for a
function named ‘get_foo’ is that it is a non-destructive read. I would
expect the name of this function to indicate what's going on much more
explicitly.


My suggestion::

 def get_and_reset_token(self):
 result = self.token
 self.token = None
 return result



This function is used in a file parser.  There are two methods, 
getToken() and peekToken().  getToken pops a token from the file, while 
peekToken keeps the token, but still returns it.


Code:

def getToken(self):
if self.tok:
t = self.tok
self.tok = None
return t
try:
t = self.gen.next()
except StopIteration:
return NULL
else:
return t

def peekToken(self):
if not self.tok:
self.tok = self.getToken()
return self.tok

NULL is an enumerated value I have defined above.  The idea is for 
peekToken to reuse getToken, but to keep the token still around.





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


Re: Return and set

2011-07-19 Thread Billy Mays

On 07/19/2011 01:00 PM, Micah wrote:

That sounds artificially backwards; why not let getToken() reuse peekToken()?

def peek(self):
 if self.tok is None:
 try:
 self.tok = self.gen.next()
 except StopIteration:
 self.tok = NULL
 return self.tok

def pop(self):
 token = self.peek()
 self.tok = None
 return token


I actually like this way better, thanks!

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


Re: Return and set

2011-07-19 Thread Billy Mays

On 07/19/2011 01:02 PM, Terry Reedy wrote:


You did not answer Ben's question about the allowed values of self.tok
and whether you really want to clobber all 'false' values. The proper
code depends on that answer.


NULL is an enumerated value I have defined above. The idea is for
peekToken to reuse getToken, but to keep the token still around.


I think about reversing and have getToken use peekToken and then reset.
But that depends on the exact logic which depends on the specs. I would
more likely have just one function with a reset parameter defaulted to
the more common value.



self.gen is a generator that gets filters single characters from a file. 
 Values that come from self.gen.next() will always be string values 
since the file generator closes on EOF.  I can be sure that I will 
either get a string from self.gen.next() or catch an exception so its 
okay to use NULL (which evaluates to 0).


You are correct it makes more sense to use peekToken() to do the lifting 
and getToken() to reuse the token.  However, I am not sure what you mean 
by reset.


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


Re: a little parsing challenge ☺

2011-07-19 Thread Billy Mays

On 07/19/2011 01:14 PM, Xah Lee wrote:

I added other unicode brackets to your list of brackets, but it seems
your code still fail to catch a file that has mismatched curly quotes.
(e.g.http://xahlee.org/p/time_machine/tm-ch04.html  )

LOL Billy.

  Xah


I suspect its due to the file mode being opened with 'rb' mode.  Also, 
the diction of characters at the top, the closing token is the key, 
while the opening one is the value.  Not sure if thats obvious.


Also returning the position of the first mismatched pair is somewhat 
ambiguous.  File systems store files as streams of octets (mine do 
anyways) rather than as characters.  When you ask for the position of 
the the first mismatched pair, do you mean the position as per 
file.tell() or do you mean the nth character in the utf-8 stream?


Also, you may have answered this earlier but I'll ask again anyways: You 
ask for the first mismatched pair, Are you referring to the inner most 
mismatched, or the outermost?  For example, suppose you have this file:


foo[(])bar

Would the ( be the first mismatched character or would the ]?

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


Re: Saving changes to path

2011-07-19 Thread Billy Mays

On 07/19/2011 02:24 PM, Chess Club wrote:

Hello,

I used sys.path.append() to add to the path directory, but the changes
made are not saved when I exit the compiler. Is there a way to save
it?

Thank you.


Since python is running in a child process, it only affects its own 
environment variables.  I'm not sure that a process can change its 
parents' environment variables in a platform independent way.



I also tried:
 $ python -c 'import os; os.system(export FOO=1)'
 $ echo $FOO

 $

but it doesn't seem to work.

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


Re: a little parsing challenge ☺

2011-07-18 Thread Billy Mays

On 07/17/2011 03:47 AM, Xah Lee wrote:

2011-07-16


I gave it a shot.  It doesn't do any of the Unicode delims, because 
let's face it, Unicode is for goobers.



import sys, os

pairs = {'}':'{', ')':'(', ']':'[', '':'', ':', '':''}
valid = set( v for pair in pairs.items() for v in pair )

for dirpath, dirnames, filenames in os.walk(sys.argv[1]):
for name in filenames:
stack = [' ']
with open(os.path.join(dirpath, name), 'rb') as f:
chars = (c for line in f for c in line if c in valid)
for c in chars:
if c in pairs and stack[-1] == pairs[c]:
stack.pop()
else:
stack.append(c)
print (Good if len(stack) == 1 else Bad) + ': %s' % name

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


Re: a little parsing challenge ☺

2011-07-18 Thread Billy Mays

On 7/18/2011 7:56 PM, Steven D'Aprano wrote:

Billy Mays wrote:


On 07/17/2011 03:47 AM, Xah Lee wrote:

2011-07-16


I gave it a shot.  It doesn't do any of the Unicode delims, because
let's face it, Unicode is for goobers.


Goobers... that would be one of those new-fangled slang terms that the young
kids today use to mean its opposite, like bad, wicked and sick,
correct?

I mention it only because some people might mistakenly interpret your words
as a childish and feeble insult against the 98% of the world who want or
need more than the 127 characters of ASCII, rather than understand you
meant it as a sign of the utmost respect for the richness and diversity of
human beings and their languages, cultures, maths and sciences.




TL;DR version: international character sets are a problem, and Unicode 
is not the answer to that problem).


As long as I have used python (which I admit has only been 3 years) 
Unicode has never appeared to be implemented correctly.  I'm probably 
repeating old arguments here, but whatever.


Unicode is a mess.  When someone says ASCII, you know that they can only 
mean characters 0-127.  When someone says Unicode, do the mean real 
Unicode (and is it 2 byte or 4 byte?) or UTF-32 or UTF-16 or UTF-8? 
When using the 'u' datatype with the array module, the docs don't even 
tell you if its 2 bytes wide or 4 bytes.  Which is it?  I'm sure that 
all the of these can be figured out, but the problem is now I have to 
ask every one of these questions whenever I want to use strings.


Secondly, Python doesn't do Unicode exception handling correctly. (but I 
suspect that its a broader problem with languages) A good example of 
this is with UTF-8 where there are invalid code points ( such as 0xC0, 
0xC1, 0xF5, 0xF6, 0xF7, 0xF8, ..., 0xFF, but you already knew that, as 
well as everyone else who wants to use strings for some reason).


When embedding Python in a long running application where user input is 
received, it is very easy to make mistake which bring down the whole 
program.  If any user string isn't properly try/excepted, a user could 
craft a malformed string which a UTF-8 decoder would choke on.  Using 
ASCII (or whatever 8 bit encoding) doesn't have these problems since all 
codepoints are valid.


Another (this must have been a good laugh amongst the UniDevs) 'feature' 
of unicode is the zero width space (UTF-8 code point 0xE2 0x80 0x8B). 
Any string can masquerade as any other string by placing  few of these 
in a string.  Any word filters you might have are now defeated by some 
cheesy Unicode nonsense character.  Can you just just check for these 
characters and strip them out?  Yes.  Should you have to?  I would say no.


Does it get better?  Of course! international character sets used for 
domain name encoding use yet a different scheme (Punycode).  Are the 
following two domain names the same: tést.com , xn--tst-bma.com ?  Who 
knows!


I suppose I can gloss over the pains of using Unicode in C with every 
string needing to be an LPS since 0x00 is now a valid code point in 
UTF-8 (0x for 2 byte Unicode) or suffer the O(n) look up time to do 
strlen or concatenation operations.


Can it get even better?  Yep.  We also now need to have a Byte order 
Mark (BOM) to determine the endianness of our characters.  Are they 
little endian or big endian?  (or perhaps one of the two possible middle 
endian encodings?)  Who knows?  String processing with unicode is 
unpleasant to say the least.  I suppose that's what we get when we 
things are designed by committee.


But Hey!  The great thing about standards is that there are so many to 
choose from.


--
Bill






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


Re: Possible File iteration bug

2011-07-15 Thread Billy Mays

On 07/15/2011 04:01 AM, bruno.desthuilli...@gmail.com wrote:

On Jul 14, 9:46 pm, Billy Maysno...@nohow.com  wrote:

I noticed that if a file is being continuously written to, the file
generator does not notice it:

def getLines(f):
  lines = []
  for line in f:
  lines.append(line)
  return lines


what's wrong with file.readlines() ?


Using that will read the entire file into memory which may not be 
possible.  In the library reference, it mentions that using the 
generator (which calls file.next()) uses a read ahead buffer to 
efficiently loop over the file.  If I call .readline() myself, I forfeit 
that performance gain.


I was thinking that a convenient solution to this problem would be to 
introduce a new Exception call PauseIteration, which would signal to the 
caller that there is no more data for now, but not to close down the 
generator entirely.


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


Re: Possible File iteration bug

2011-07-15 Thread Billy Mays

On 07/15/2011 08:39 AM, Thomas Rachel wrote:

Am 14.07.2011 21:46 schrieb Billy Mays:

I noticed that if a file is being continuously written to, the file
generator does not notice it:


Yes. That's why there were alternative suggestions in your last thread
How to write a file generator.

To repeat mine: an object which is not an iterator, but an iterable.

class Follower(object):
def __init__(self, file):
self.file = file
def __iter__(self):
while True:
l = self.file.readline()
if not l: return
yield l

if __name__ == '__main__':
import time
f = Follower(open(/var/log/messages))
while True:
for i in f: print i,
print all read, waiting...
time.sleep(4)

Here, you iterate over the object until it is exhausted, but you can
iterate again to get the next entries.

The difference to the file as iterator is, as you have noticed, that
once an iterator is exhausted, it will be so forever.

But if you have an iterable, like the Follower above, you can reuse it
as you want.



I did see it, but it feels less pythonic than using a generator.  I did 
end up using an extra class to get more data from the file, but it seems 
like overhead.  Also, in the python docs, file.next() mentions there 
being a performance gain for using the file generator (iterator?) over 
the readline function.


Really what would be useful is some sort of PauseIteration Exception 
which doesn't close the generator when raised, but indicates to the 
looping header that there is no more data for now.


--
Bill


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


Re: Possible File iteration bug

2011-07-15 Thread Billy Mays

On 07/15/2011 10:28 AM, Thomas Rachel wrote:

Am 15.07.2011 14:52 schrieb Billy Mays:


Also, in the python docs, file.next() mentions there
being a performance gain for using the file generator (iterator?) over
the readline function.


Here, the question is if this performance gain is really relevant AKA
feelable. The file object seems to have another internal buffer
distinct from the one used for iterating used for the readline()
function. Why this is not the same buffer is unclear to me.



Really what would be useful is some sort of PauseIteration Exception
which doesn't close the generator when raised, but indicates to the
looping header that there is no more data for now.


a None or other sentinel value would do this as well (as ChrisA already
said).


Thomas


A sentinel does provide a work around, but it also passes the problem 
onto the caller rather than the callee:


def getLines(f):
lines = []

while True:
yield f.readline()

def bar(f):
for line in getLines(f):
if not line: # I now have to check here instead of in getLines
break
foo(line)


def baz(f):
for line in getLines(f) if line: # this would be nice for generators
foo(line)


bar() is the correct way to do things, but I think baz looks cleaner.  I 
found my self writing baz() first, finding it wasn't syntactically 
correct, and then converting it to bar().  The if portion of the loop 
would be nice for generators, since it seems like the proper place for 
the sentinel to be matched.  Also, with potentially infinite (but 
pauseable) data, there needs to be a nice way to catch stuff like this.


--
Bill






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


Re: Looking for general advice on complex program

2011-07-15 Thread Billy Mays

On 07/15/2011 03:47 PM, Josh English wrote:




I remember reading that file locking doesn't work on network mounted 
drives (specifically nfs mounts), but you might be able to simply create 
a 'lock' (mydoc.xml.lock or the like) file for the XML doc in question. 
 If that file exists you could either hang or silently give up.  Not 
sure if that helps.


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


Re: String formatting - mysql insert

2011-07-14 Thread Billy Mays

On 07/14/2011 11:00 AM, Christian wrote:

Hi,

I get some problem  when i like to set the table name dynamic.
I'm appreciate for any help.

Christian

### works 
newcur.execute (   INSERT INTO events (id1,id2)   VALUES  (%s,%s);
 , (rs[1],rs[2]))

### works not
newcur.execute (   INSERT INTO %s_events (id1,id2)   VALUES  (%s,
%s);  , (table_name,rs[1],rs[2]))

### works but is not really perfect: None from rs list result in
None instead of NULL.
newcur.execute (   INSERT INTO %s_events (id1,id2)   VALUES
('%s','%s');   %  (table_name,rs[1],rs[2]))


You shouldn't use The bottom form at all since that is how injection 
attacks occur.


The reason the second version doesn't work is because the the execute 
command escapes all of the arguments before replacing them.  Example:


sql = SELECT * FROM table WHERE col = %s;
cur.execute(sql, ('name',))
# The actual sql statement that gets executed is:
# SELECT * FROM table WHERE col = 'name';
# Notice the single quotes.

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


Possible File iteration bug

2011-07-14 Thread Billy Mays
I noticed that if a file is being continuously written to, the file 
generator does not notice it:




def getLines(f):
lines = []
for line in f:
lines.append(line)
return lines

with open('/var/log/syslog', 'rb') as f:
lines = getLines(f)
# do some processing with lines
# /var/log/syslog gets updated in the mean time

# always returns an empty list, even though f has more data
lines = getLines(f)




I found a workaround by adding f.seek(0,1) directly before the last 
getLines() call, but is this the expected behavior?  Calling f.tell() 
right after the first getLines() call shows that it isn't reset back to 
0.  Is this correct or a bug?


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


Re: Possible File iteration bug

2011-07-14 Thread Billy Mays

On 07/14/2011 04:00 PM, Ian Kelly wrote:

On Thu, Jul 14, 2011 at 1:46 PM, Billy Maysno...@nohow.com  wrote:

def getLines(f):
lines = []
for line in f:
lines.append(line)
return lines

with open('/var/log/syslog', 'rb') as f:
lines = getLines(f)
# do some processing with lines
# /var/log/syslog gets updated in the mean time

# always returns an empty list, even though f has more data
lines = getLines(f)




I found a workaround by adding f.seek(0,1) directly before the last
getLines() call, but is this the expected behavior?  Calling f.tell() right
after the first getLines() call shows that it isn't reset back to 0.  Is
this correct or a bug?


This is expected.  Part of the iterator protocol is that once an
iterator raises StopIteration, it should continue to raise
StopIteration on subsequent next() calls.


Is there any way to just create a new generator that clears its `closed` 
status?


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


How to write a file generator

2011-07-12 Thread Billy Mays
I want to make a generator that will return lines from the tail of 
/var/log/syslog if there are any, but my function is reopening the file 
each call:


def getLines():
with open('/var/log/syslog', 'rb') as f:
while True:
line = f.readline()
if line:
yield line
else:
raise StopIteration


I know the problem lies with the StopIteration, but I'm not sure how to 
tell the caller that there are no more lines for now.


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


Re: How to write a file generator

2011-07-12 Thread Billy Mays

On 07/12/2011 11:52 AM, Thomas Jollans wrote:

On 07/12/2011 04:46 PM, Billy Mays wrote:

I want to make a generator that will return lines from the tail of
/var/log/syslog if there are any, but my function is reopening the file
each call:

def getLines():
 with open('/var/log/syslog', 'rb') as f:
 while True:
 line = f.readline()
 if line:
 yield line
 else:
 raise StopIteration


I know the problem lies with the StopIteration, but I'm not sure how to
tell the caller that there are no more lines for now.

--
Bill


http://stackoverflow.com/questions/1475950/tail-f-in-python-with-no-time-sleep



That was actually the behavior I was trying to avoid.  If there is no 
data to be read, the call will hang.  That function is actually called 
by a webserver (from wsgiref) so it cannot hang indefinitely.


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


Re: Why isn't there a good RAD Gui tool for python

2011-07-11 Thread Billy Mays

On 07/11/2011 02:59 PM, Elias Fotinis wrote:

On Mon, 11 Jul 2011 20:11:56 +0300, Stefan Behnel stefan...@behnel.de
wrote:


Just a quick suggestion regarding the way you posed your question. It's
usually better to ask if anyone knows a good tool to do a specific job
(which you would describe in your post), instead of complaining about
there
being none.


Opinion is divided on this… http://bash.org/?152037



There is another way: http://bash.org/?684045
--
http://mail.python.org/mailman/listinfo/python-list


Re: Finding duplicated photo

2011-07-08 Thread Billy Mays

On 07/08/2011 07:29 AM, TheSaint wrote:

Hello,

I came across the problem that Gwenview moves the photo from the camera
memory by renaming them, but later I forgot which where moved.
Then I tought about a small script in python, but I stumbled upon my
ignorance on the way to do that.

PIL can find similar pictures. I was thinking to reduce the foto into gray
scale and resize them to same size, what algorithm should take place?
Is PIL able to compare 2 images?



I recently wrote a program after reading an article ( 
http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html 
) using the DCT method he proposes.  It worked surprisingly well even 
with just the 64bit hash it produces.


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


Re: Finding duplicated photo

2011-07-08 Thread Billy Mays

On 07/08/2011 10:14 AM, TheSaint wrote:

Billy Mays wrote:


It worked surprisingly well even
with just the 64bit hash it produces.


I'd say that comparing 2 images reduced upto 32x32 bit seems too little to
find if one of the 2 portrait has a smile referred to the other.
I think it's about that mine and your suggestion are similar, but I'd like
to scale pictures not less than 256x256 pixel.
Also to take a wider case which the comparison involve a rotated image.



Originally I thought the same thing.  It turns out that doing a DCT on 
an image typically moves the more important data to the top left corner 
of the output.  This means that most of the other data in the output an 
be thrown away since most of it doesn't significantly affect the image. 
 The 32x32 is an arbitrary size, you can make it any square block that 
you want.


Rotation is harder to find.  You can always take a brute force approach 
by simply rotating the image a couple of times and try running the 
algorithm on each of the rotated pics.  Image matching is a difficult 
problem.


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


Re: String concatenation vs. string formatting

2011-07-08 Thread Billy Mays

On 07/08/2011 04:18 PM, Andrew Berg wrote:

Is it bad practice to use this

logger.error(self.preset_file + ' could not be stored - ' +
sys.exc_info()[1])

Instead of this?

logger.error('{file} could not be stored -
{error}'.format(file=self.preset_file, error=sys.exc_info()[1]))



Other than the case where a variable isn't a string (format() converts
variables to strings, automatically, right?) and when a variable is used
a bunch of times, concatenation is fine, but somehow, it seems wrong.
Sorry if this seems a bit silly, but I'm a novice when it comes to
design. Plus, there's not really supposed to be more than one way to do
it in Python.

If it means anything, I think concatenation is faster.

__TIMES__
a() -  0.09s
b() -  0.09s
c() - 54.80s
d() -  5.50s

Code is below:

def a(v):
out = 
for i in xrange(100):
out += v
return len(out)

def b(v):
out = 
for i in xrange(10):
out += v+v+v+v+v+v+v+v+v+v
return len(out)

def c(v):
out = 
for i in xrange(100):
out = %s%s % (out, v)
return len(out)

def d(v):
out = 
for i in xrange(10):
out = %s%s%s%s%s%s%s%s%s%s%s % (out,v,v,v,v,v,v,v,v,v,v)
return len(out)

print a, a('xx')
print b, b('xx')
print c, c('xx')
print d, d('xx')

import  profile

profile.run(a('xx'))
profile.run(b('xx'))
profile.run(c('xx'))
profile.run(d('xx'))
--
http://mail.python.org/mailman/listinfo/python-list


Large number multiplication

2011-07-06 Thread Billy Mays
I was looking through the python source and noticed that long 
multiplication is done using the Karatsuba method (O(~n^1.5)) rather 
than using FFTs O(~n log n).  I was wondering if there was a reason the 
Karatsuba method was chosen over the FFT convolution method?


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


Re: Large number multiplication

2011-07-06 Thread Billy Mays

On 07/06/2011 04:05 PM, Christian Heimes wrote:

Am 06.07.2011 21:30, schrieb Billy Mays:

I was looking through the python source and noticed that long
multiplication is done using the Karatsuba method (O(~n^1.5)) rather
than using FFTs O(~n log n).  I was wondering if there was a reason the
Karatsuba method was chosen over the FFT convolution method?


The Karatsuba algorithm uses just addition, subtraction and
multiplication, so you don't need to resort to floats and have no
rounding errors. On the other hand FFT are based on e, complex numbers
or trigonometric functions (=floats), which mean you'll get rounding errors.

We don't want rounding errors for large long multiplication.

Christian



I believe it is possible to do FFTs without significant rounding error. 
 I know that the GIMPS's Prime95 does very large multiplications using 
FFTs (I don't know if they use the integer based or double based 
version).  I also know they have guards to prevent rounding errors so I 
don't think it would be impossible to implement.


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


Re: Large number multiplication

2011-07-06 Thread Billy Mays

On 07/06/2011 04:02 PM, Ian Kelly wrote:

On Wed, Jul 6, 2011 at 1:30 PM, Billy Maysno...@nohow.com  wrote:

I was looking through the python source and noticed that long multiplication
is done using the Karatsuba method (O(~n^1.5)) rather than using FFTs O(~n
log n).  I was wondering if there was a reason the Karatsuba method was
chosen over the FFT convolution method?


According to Wikipedia:


In practice the Schönhage–Strassen algorithm starts to outperform
older methods such as Karatsuba and Toom–Cook multiplication for
numbers beyond 2**2**15 to 2**2**17 (10,000 to 40,000 decimal digits).


I think most Python users are probably not working with numbers that
large, and if they are, they are probably using specialized numerical
libraries anyway, so there would be little benefit in implementing it
in core.


You are right that not many people would gain significant use of it. 
The reason I ask is because convolution has a better (best ?) complexity 
class than the current multiplication algorithm.  I do like the idea of 
minimizing reliance on external libraries, but only if the changes would 
be useful to all the regular users of python.


I was more interested in finding previous discussion (if any) on why 
Karatsuba was chosen, not so much as trying to alter the current 
multiplication implementation.


Side note: Are Numpy/Scipy the libraries you are referring to?

--
Bill

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


Better way to iterate over indices?

2011-06-21 Thread Billy Mays
I have always found that iterating over the indices of a list/tuple is 
not very clean:


for i in range(len(myList)):
doStuff(i, myList[i])




I know I could use enumerate:

for i, v in enumerate(myList):
doStuff(i, myList[i])

...but that stiff seems clunky.

Are there any better ways to iterate over the indices of a list /tuple?

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


Standard Deviation One-liner

2011-06-03 Thread Billy Mays
I'm trying to shorten a one-liner I have for calculating the standard 
deviation of a list of numbers.  I have something so far, but I was 
wondering if it could be made any shorter (without imports).



Here's my function:

a=lambda d:(sum((x-1.*sum(d)/len(d))**2 for x in d)/(1.*(len(d)-1)))**.5


The functions is invoked as follows:

 a([1,2,3,4])
1.2909944487358056


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


Re: Updated blog post on how to use super()

2011-06-01 Thread Billy Mays

On 5/31/2011 10:44 PM, Raymond Hettinger wrote:

I've tightened the wording a bit, made much better use of keyword
arguments instead of kwds.pop(arg), and added a section on defensive
programming (protecting a subclass from inadvertently missing an MRO
requirement).  Also, there is an entry on how to use assertions to
validate search order requirements and make them explicit.

   http://bit.ly/py_super
  or
   http://rhettinger.wordpress.com/2011/05/26/super-considered-super/

Any further suggestions are welcome.  I'm expecting this to evolve
into how-to guide to be included in the regular Python standard
documentation.  The goal is to serve as a reliable guide to using
super and how to design cooperative classes in a way that lets
subclasses compose and extent them.


Raymond Hettinger


follow my python tips on twitter: @raymondh


I read this when it was on HN the other day, but I still don't see what 
is special about super().  It seems (from your post) to just be a stand 
in for the super class name?  Is there something special I missed?


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


Re: Updated blog post on how to use super()

2011-06-01 Thread Billy Mays

On 6/1/2011 12:42 PM, Ian Kelly wrote:

On Wed, Jun 1, 2011 at 7:03 AM, Billy Maysno...@nohow.com  wrote:

I read this when it was on HN the other day, but I still don't see what is
special about super().  It seems (from your post) to just be a stand in for
the super class name?  Is there something special I missed?


It's not a stand-in for the super-class name.  It's a stand-in for
whatever class is next in the Method Resolution Order (MRO), which is
determined at run-time and can vary depending on what the actual class
of the object is.  For example, in this inheritance situation:

class A(object):
 ...

class B(object):
 ...

class C(A, B):
 ...

a = A()
c = C()

The MRO of A is (A, object).
The MRO of B is (B, object).
The MRO of C is (C, A, B, object).

Thus, super(A, a) is going to resolve to object, as you might expect.
But super(A, c) is going to resolve to B, because the next class after
A in the MRO for C instances is B.

That's a pretty quick and dirty explanation.  If it doesn't make
sense, I suggest reading the article again.


What it does is clear to me, but why is it interesting or special isn't. 
 This looks like a small feature that would be useful in a handful of 
cases.


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


Re: in house pypi?

2011-03-24 Thread Billy Earney
Another possible solution, would be to use urlimport
http://pypi.python.org/pypi/urlimport/
http://pypi.python.org/pypi/urlimport/if the packages are 100% python (no
c, etc), you could create a single repository, serve that via a web server,
and users could easy import modules without even installing them..

This isn't exactly what you asked for, but depending on your situation,
could be useful.

Hope this helps.

On Thu, Mar 24, 2011 at 6:22 AM, Christian Heimes li...@cheimes.de wrote:

 Am 24.03.2011 04:19, schrieb Miki Tebeka:
  Greetings,
 
  My company want to distribute Python packages internally. We would like
 something like an internal PyPi where people can upload and easy_install
 from packages.
 
  Is there such a ready made solution?
  I'd like something as simple as possible, without my install headache.

 Plain simple solution:

  * configure a host in your apache config and point it to a directory on
 the file system
  * create directory simple  and turn directory index on for it and all
 its descendants
  * create a directory for every package and download the files into
 these directories

 The download link for e.g. lxml 2.3 should look like
 http://your.pipy.com/simple/lxml/lxml-2.3.tar.gz. Now point run
 easy_install --index-url http://your.pipy.com/simple lxml==2.3

 Christian

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

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


[issue11652] urlib2 returns a pair of integers as the content-length value

2011-03-23 Thread Billy Saelim

New submission from Billy Saelim sae...@gmail.com:

urlopen does not always return a single value for 'content-length'.  For 
example:


 import urllib2
 request = 
 'http://wwwsearch.sourceforge.net/mechanize/src/mechanize-0.1.11.zip'
 fp = urllib2.urlopen(request)
 fp.info().dict
{'content-length': '289519, 289519', 'x-varnish': '929586024', 'via': '1.1 
varnish', 'age': '0', 'expires': 'Fri, 25 Mar 2011 14:36:43 GMT', 'server': 
'Apache/2.2.3 (CentOS)', 'last-modified': 'Sat, 07 Feb 2009 19:15:15 GMT', 
'connection': 'close', 'etag': '46aef-46258f510b6c0', 'date': 'Wed, 23 Mar 
2011 14:36:43 GMT', 'content-type': 'application/zip'}

--
components: Library (Lib)
messages: 131894
nosy: Billy.Saelim
priority: normal
severity: normal
status: open
title: urlib2 returns a pair of integers as the content-length value
type: behavior
versions: Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11652
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



looking for new members to join grid of storage nodes using tahoe-lafs which is implemented in python.

2011-02-02 Thread Billy Earney
Would you like to be able to back up ~1 TB of data to secure,
highly-reliable, off-site storage, for free?

By highly-reliable I mean that your data should survive pretty much
anything short of the collapse of civilization. By free I mean no
monetary cost, although you have to provide some hardware and a little of
your time.

There's a very cool distributed file system project implemented in python
called Tahoe-LAFS (http://tahoe-lafs.org) . The idea is that when you store
files in this file system, they actually get split into multiple pieces and
moved to servers elsewhere on the Internet. Even better, the splitting is
done in such a way that even if some of the pieces get lost or destroyed,
your data is still perfectly intact and retrievable at any time. Oh and all
of your pieces are encrypted so that no one who has access to the servers
hosting them can see your data.

Where are these other servers? Well, they can be anywhere, but in this
case, the server grid that I'm using is provided by a group of volunteers,
all of whom want highly-reliable off-site backup storage. The cost of using
this grid is that you have to provide a backup server of your own, which
will host pieces of other peoples' data. We call it volunteergrid2. The
two is because there's also a volunteergrid1, which is working fine, but
I've found doesn't meet my requirements. Basically, I want to store a lot
more stuff than that grid is set up to accept, so I've been pushing for this
new grid.

Here are the basic requirements to join the grid:


   1. You have to have a computer which is always on and always connected to
   the Internet. In fact, you have to commit to keeping that machine up and
   connected at least 95% of the time (no more than 8 hours per week or 1.5
   days per month downtime). It's easier if the machine runs a Unix operating
   system, though Windows works, too.
   2. You have to provide at least 500 GB of storage to the grid.
   3. You have to be able to open a couple of ports through your
   router/firewall to expose that portion of your server to the Internet. If
   you need help with this, the members of the grid can probably help.
   4. You may consume as much storage from the grid as what you provide to
   the grid, with one caveat and one issue to consider. The issue is that when
   your files are split into pieces, depending on the splitting parameters you
   choose (and we'll be glad to help you make good choices), your files will
   get larger. So if your parameters cause your files to grow by a factor of
   three, and you provide 500 GB of storage to the grid, then you can store 170
   GB of your data in the grid. The caveat is that there is a 1 TB cap. You may
   not store more than 1 TB in the grid -- not without approval of the rest of
   the grid members, anyway. The group makes decisions by consensus.

So far, the grid has about 10 storage servers, each contributing 500 GB, for
a total of 5 TB. We'd like to get that up to at least 20 servers and 10-15
TB, and I'd really like to get to 40 servers and 30-40 TB, because with more
servers you can use more efficient splitting so you get the same level of
reliability but with less expansion.

Over time, I expect we'll gradually raise the bar, requiring all
participants to provide at least 750 GB, then 1 TB, and so on, so that our
available storage keeps pace with the growth in common drive capacities.

If you are interested, you can find out more information at
http://bigpig.org.  We have a subscription list which members use as their
main line of communication to other members.  You can subscribe at
http://tahoe-lafs.org/cgi-bin/mailman/listinfo/volunteergrid2-l

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


Re: Developing a program to make a family tree.

2011-01-14 Thread Billy Earney
try http://gramps-project.org/, which is created in python.. :)

On Fri, Jan 14, 2011 at 1:39 PM, Ata Jafari a.j.romani...@gmail.com wrote:

 Hi there.
 I'm trying to develop a program like family tree maker. I have all
 information, so there is no need to search on the net. This must be
 something like trees. Can someone help me? I'm at the beginning.
 Thanks.

 --
 Ata J. Tabrizi
 atae.tabr...@metu.edu.tr
 --
 http://mail.python.org/mailman/listinfo/python-list

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


RE: Visual Python programming and decompilers?

2010-03-12 Thread Billy Earney
Ludolph,

This reminds me of the orange project which is developed in python.
http://www.ailab.si/orange/
It is actually for data mining, but many of the concepts could be used for a
more general programming structure.

Billy

-Original Message-
From: python-list-bounces+billy.earney=gmail@python.org
[mailto:python-list-bounces+billy.earney=gmail@python.org] On Behalf Of
Ludolph
Sent: Thursday, March 11, 2010 12:39 PM
To: python-list@python.org
Subject: Visual Python programming and decompilers?

Hi Guys

At work I have been exposed to a Agile Platform called OutSystems. It
allows you to visually program your web applications
http://i.imgur.com/r2F0i.png and I find the idea very intriguing.

So I have started to play around with the idea on how will I be able
to visually represent Python code as in the above image and then allow
the programmer to change some of the flow/code/logic visually and then
get it back as python source code. I don't know if this have been
tried before and after some googling I can't find anything like this,
so maybe I'm just lacking basic googling skills or a python solution
like the above does not exist yet.

If anybody knows of such solution please let me know, so that I don't
spend a lot of time recreating the wheel. Otherwise help me out on the
following problem:

I decided I can use byteplay3 http://pypi.python.org/pypi/byteplay/ to
disassemble the code to workable objects, It even allows me to rebuild
the objects to bytecode. So if I define patterns on how python
interrupts the source code to bytecode I can visually represent this
and also so convert my visual representations back to bytecode.

The only problem I have at the moment is how will I get this bytecode
back to python source code. I have googled for python decompiler but
only found old projects like unpyc, decompyle and some online
services. I would like to know if anybody know of a well maintained or
at least recent module that can help me accomplish the above
mentioned, because I'm hoping I can implement this in Python 3.1.

So any input or suggestion would be greatly appreciated.

Kind Regards,

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

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


RE: checking 'type' programmatically

2009-11-20 Thread Billy Earney
Try looking at the function 'isinstance', so for example

if isinstance(obj, str):
print object is a string..
elif isinstance(obj, int):
print object is an integer.. 

-Original Message-
From: python-list-bounces+billy.earney=gmail@python.org
[mailto:python-list-bounces+billy.earney=gmail@python.org] On Behalf Of
mk
Sent: Friday, November 20, 2009 4:10 AM
To: python-list@python.org
Subject: checking 'type' programmatically


Disclaimer: this is for exploring and debugging only. Really.

I can check type or __class__ in the interactive interpreter:

Python 2.6.2 (r262:71600, Jun 16 2009, 16:49:04)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type help, copyright, credits or license for more information.
  import subprocess
  
p=subprocess.Popen(['/bin/ls'],stdout=subprocess.PIPE,stderr=subprocess.PIPE
)
  p
subprocess.Popen object at 0xb7f2010c
  (so, se) = p.communicate()
  so
'abc.txt\nbak\nbox\nbuild\ndead.letter\nDesktop\nhrs\nmbox\nmmultbench\nmmul
tbench.c\npyinstaller\nscreenlog.0\nshutdown\ntaddm_import.log\nv2\nvm\nwork
space\n'
  se
''
  so.__class__
type 'str'
  type(so)
type 'str'
  type(se)
type 'str'

But when I do smth like this in code that is ran non-interactively (as 
normal program):

req.write('stderr type %sbr' % type(se))
req.write('stderr class %sbr' % str(se.__class__))

then I get empty output. WTF?

How do I get the type or __class__ into some object that I can display?


Why do that: e.g. if documentation is incomplete, e.g. documentation on 
Popen.communicate() says communicate() returns a tuple (stdoutdata, 
stderrdata) but doesn't say what is the class of stdoutdata and 
stderrdata (a file object to read? a string?).

Regards,
mk



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

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


RE: Web development with Python 3.1

2009-10-27 Thread Billy Earney
I would agree with Alan.  Most of the libraries you should use are
compatible with the 2.x series..  I still use versions 2.5 and 2.6 for all
development.

 

From: python-list-bounces+billy.earney=gmail@python.org
[mailto:python-list-bounces+billy.earney=gmail@python.org] On Behalf Of
Alan Harris-Reid
Sent: Tuesday, October 27, 2009 6:08 AM
To: Python List
Subject: Re: Web development with Python 3.1

 

Aaron Watters wrote: 

On Oct 25, 7:52 pm, Alan Harris-Reid  mailto:a...@baselinedata.co.uk
a...@baselinedata.co.uk wrote:
  

I am very much new to Python, and one of my first projects is a simple
data-based website. I am starting with Python 3.1 (I can hear many of
you shouting don't - start with 2.6), but as far as I can see, none of
the popular python-to-web frameworks (Django, CherryPy, web.py, etc.)
are Python3 compatible yet.
 
So, what can I use to start my web programming experience using 3.1?
 
Any help would be appreciated.
 
Alan


 
Don't. use python 2.6 with WHIFF :)
  http://aaron.oirt.rutgers.edu/myapp/GenBankTree/index
  http://whiff.sourceforge.net
 
-- Aaron Watters

Thanks for the advice

Alan

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


Python class gotcha with scope?

2009-06-21 Thread billy
I don't quite understand why this happens. Why doesn't b have its own
version of r? If r was just an int instead of a dict, then it would.

 class foo:
... r = {}
... def setn(self, n):
... self.r[f] = n
...
 a = foo()
 a.setn(4)

 b = foo()
 b.r
{'f': 4}

thanks,

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


Re: Python class gotcha with scope?

2009-06-21 Thread billy
great, thanks for the quick responses :)


On Jun 21, 2:41 am, Carl Banks pavlovevide...@gmail.com wrote:
 On Jun 20, 11:32 pm, billy billy.cha...@gmail.com wrote:

  I don't quite understand why this happens. Why doesn't b have its own
  version of r? If r was just an int instead of a dict, then it would.

   class foo:

  ...     r = {}
  ...     def setn(self, n):
  ...             self.r[f] = n
  ... a = foo()
   a.setn(4)

   b = foo()
   b.r

  {'f': 4}

 r is a class attribute, that is, it is attacted to the class itself.
 Look at what happens when you enter foo.r at the interactive prompt:

  foo.r

 {'f': 4}

 You want an instance attribute, a value attached to the instance of
 the class.  You create those in the __init__ method:

 class foo:
     def __init__(self):
         self.r = {}
     def setn(self,n):
         self.r[n] = n

 Carl Banks

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


Re: PyGilState_Ensure interrupts python critical sections

2007-11-15 Thread billy . omahony
 the GIL
 P   *   Python thread exits critical section and releases
 the object lock
 *   *   Python thread releases the GIL (can be in any
 order with next state)
 *   C   The C thread acquires the object lock and blocks on the 
 GIL
 C   C   C thread acquires the GIL and continues execution.

  One thing that may work (though the documentation does not
  specifically say so) is using setcheckinterval() to set the check
  interval to a very large value, acessing my shared structure and then
  setting the check interval back to the previous value. Provided my
  access to the shared structure takes less byte codes than what I set
  checkinterval to I should be okay. However that would be very
  dependant on the exact fine detail of how the check interval works and
  may not be compatible with other Python releases

  Maybe someone familiar with the python source code would know for
  sure?

  I am using Python 2.4.3 on windows XP.

  Thanks for any help/suggestions offered!
  BR,
  Billy.

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

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


PyGilState_Ensure interrupts python critical sections

2007-11-12 Thread billy . omahony
Hi,

I have a native windows thread in a c python module which calls into
python code and adds an item to a data structure (a home-grown
circular buffer). At the same time my main python application is
removing items from this data structure.

Unlike native python containers adding and removing items from the
circular buffer is not atomic. So I need to put access to it in a
critical section. Using threading.Lock will work for native python
threads competing for access. But when access is from a windows thread
this will not work. That is because my call to PyGilState_ensure will
preempt my native python thread ***even when it is inside the critical
section***.

What is going on looks something like this (I think).


   Py  Python   Windows   Py   threading.Lock
resource
  SchedThread   Thread   Code|  |
| || |  |
|Go (GIL)#|| |  |
|#|| |  |
|#|| |  |
|#...Doit.|...| |  |
|#||. acquire...|  |
|-PyGILState_Ensure--|| |  |
|   ...  ...  ...   ...
|Stop#
|---`|
|
|Ensure rtns-# PyObject_  ||
 |   :|CallMethod  | |  |
 |   :|.(Doit)... |. acquire...| DEADLOCK |
 :
 :
 :.how does python thread tell
PyScheduler not to give away
  Gil until we are done with
  critical section??

So my question is how in python do I tell the scheduler not to prempt
the current python thread. Especially how to tell it not to give the
GIL to any calls to PyGILState_ensure until further notice (i.e. until
I am outside my critical section?? It sounds like a reasonable request
- surely this exists already but I can't find it.

One thing that may work (though the documentation does not
specifically say so) is using setcheckinterval() to set the check
interval to a very large value, acessing my shared structure and then
setting the check interval back to the previous value. Provided my
access to the shared structure takes less byte codes than what I set
checkinterval to I should be okay. However that would be very
dependant on the exact fine detail of how the check interval works and
may not be compatible with other Python releases

Maybe someone familiar with the python source code would know for
sure?

I am using Python 2.4.3 on windows XP.

Thanks for any help/suggestions offered!
BR,
Billy.

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


* * * New eBooks Store * * *

2007-07-17 Thread Billy Bean


Multiple categories including literature, business, home  garden,
computers  internet, and more! Learn how to make money at home, start
your own business, try new recipes, etc. Complete resell rights
included!

http://www.grandgold.net

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