Re: Free to a good home - Python Pocket Reference

2008-10-11 Thread Evans
On 11 Oct, 16:59, [EMAIL PROTECTED] wrote:
> Trying to get rid of stuff in preparation for moving I came across an unused
> Python Pocket Reference by Mark Lutz (1st ed, published 1998).  If you'd
> like it, drop me a note.  No charge for the book, but you pay the actual
> postage.
>
> --
> Skip Montanaro - [EMAIL PROTECTED] -http://www.webfast.com/~skip/

I was giving away a few weeks ago myself, but none them was a Python
book.
http://www.jroller.com/evans/entry/giving_away_unused_books I wouldn't
mind having it... will mail you directly.

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


Re: Is Python a commercial proposition ?

2012-07-29 Thread Aled Evans
On Sunday, July 29, 2012 5:01:00 PM UTC+1, lipska the kat wrote:
> Pythoners
> 
> 
> 
> Firstly, thanks to those on the tutor list who answered my questions.
> 
> 
> 
> I'm trying to understand where Python fits into the set of commonly 
> 
> available, commercially used languages of the moment.
> 
> 
> 
> My most recent experience is with Java. The last project I was involved 
> 
> with included 6775 java source files containing 1,145,785 lines of code. 
> 
> How do I know this? because I managed to cobble together a python script 
> 
> that walks the source tree and counts the lines of code. It ignores 
> 
> block and line comments and whitespace lines so I'm fairly confident 
> 
> it's an accurate total. It doesn't include web interface files (mainly 
> 
> .jsp and HTML) or configuration files (XML, properties files and what 
> 
> have you). In fact it was remarkably easy to do this in python which got 
> 
> me thinking about how I could use the language in a commercial environment.
> 
> 
> 
> I was first attracted to python by it's apparent 'Object Orientedness' I 
> 
> soon realised however that by looking at it in terms of the language I 
> 
> know best I wasn't comparing like with like. Once I had 'rebooted the 
> 
> bioware' I tried to approach python with an open mind and I have to say 
> 
> it's growing on me.
> 
> 
> 
> The questions I have are ...
> 
> 
> 
> How is python used in the real world.
> 
> What sized projects are people involved with
> 
> Are applications generally written entirely in python or is it more 
> 
> often used for a subset of functionality.
> 
> 
> 
> I hope this is an acceptable question for this group
> 
> 
> 
> Many thanks
> 
> 
> 
> Lipska
> 
> 
> 
> -- 
> 
> Lipska the Kat: Troll hunter, sandbox destroyer
> 
> and farscape dreamer of Aeryn Sun

If you check Google's job listings:

http://www.google.com/about/jobs/teams/engineering/

On the software side of things you'll see very few listings that don't ask for 
coding in Python as a requirement or, at the very least, an advantageous skill 
to have.

I'd say slowly, but surely, many people are coming around the fact that Python 
is not only as powerful as Java and other high-level languages, but it's also 
easier to read and write. That, and people (that I've spoken to, at least), 
find it far more fun to code in Python!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parse a Wireshark pcap file

2013-01-23 Thread John Evans
The import "from scapy.all import *" does work for me with macports and
10.6.8  When I installed the scapy port, I did see that macports installed
the py27-libdnet package as well.





On Wed, Jan 23, 2013 at 1:24 AM, Dennis Lee Bieber wrote:

> On Tue, 22 Jan 2013 22:43:24 -0500, Kevin Holleran 
> declaimed the following in gmane.comp.python.general:
>
> >
> > Mac OS 10.8.2
> > Python v.2.7
> > I downloaded from the sourceforge site, then tried to install with
> MacPorts
> > when some dependencies were failing.  I then downloaded & installed
> > pcapy-0.10.6 when that dependency still failed.  That solved that but I
> > received the dnet error:
> >
> > from scapy.all import conf
> >   File "/Library/Python/2.7/site-packages/scapy/all.py", line 16, in
> > 
> > from arch import *
> >   File "/Library/Python/2.7/site-packages/scapy/arch/__init__.py", line
> 75,
> > in 
> > from bsd import *
> >   File "/Library/Python/2.7/site-packages/scapy/arch/bsd.py", line 12, in
> > 
> > from unix import *
> >   File "/Library/Python/2.7/site-packages/scapy/arch/unix.py", line 20,
> in
> > 
> > from pcapdnet import *
> >   File "/Library/Python/2.7/site-packages/scapy/arch/pcapdnet.py", line
> > 160, in 
> > import dnet
> > ImportError: No module named dnet
> >
> > So I downloaded and compiled libdnet-1.11 with a:
> >  $ sudo ./configure && make
> >
> > I see it compile fine & the libraries have been installed to:
> > /usr/local/sbin/dnet
> >
> > However, python can't find it... I am not clear on how to point Python
> > there...
> >
> "libdnet" is likely a shared object binary... What I /think/ you
> are
> missing is the Python library that interfaces with that binary...
>
> Could http://pypi.python.org/pypi/dnet answer the question?
> --
> Wulfraed Dennis Lee Bieber AF6VN
> wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



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


Re: Parse a Wireshark pcap file

2013-01-23 Thread John Evans
It looks like there was some very recent reorganization of the scapy
packaging on macports, see
http://lists.macosforge.org/pipermail/macports-dev/2013-January/021620.html

Did you have an updated port tree when you installed?  If not, I'd suggest
uninstalling whatever port you installed, resync with "port selfupdate",
then install the scapy port again.  You should see not only the libdnet
port installed, but also py27-libdnet, which is the missing glue you need
for interfacing with libdnet.


On Wed, Jan 23, 2013 at 9:01 AM, Kevin Holleran  wrote:

>
> On Wed, Jan 23, 2013 at 7:25 AM, John Evans wrote:
>
>> The import "from scapy.all import *" does work for me with macports and
>> 10.6.8  When I installed the scapy port, I did see that macports installed
>> the py27-libdnet package as well.
>>
>>
>> 
>>
>>
>> On Wed, Jan 23, 2013 at 1:24 AM, Dennis Lee Bieber > > wrote:
>>
>>> On Tue, 22 Jan 2013 22:43:24 -0500, Kevin Holleran 
>>> declaimed the following in gmane.comp.python.general:
>>>
>>> >
>>> > Mac OS 10.8.2
>>> > Python v.2.7
>>> > I downloaded from the sourceforge site, then tried to install with
>>> MacPorts
>>> > when some dependencies were failing.  I then downloaded & installed
>>> > pcapy-0.10.6 when that dependency still failed.  That solved that but I
>>> > received the dnet error:
>>> >
>>> > from scapy.all import conf
>>> >   File "/Library/Python/2.7/site-packages/scapy/all.py", line 16, in
>>> > 
>>> > from arch import *
>>> >   File "/Library/Python/2.7/site-packages/scapy/arch/__init__.py",
>>> line 75,
>>> > in 
>>> > from bsd import *
>>> >   File "/Library/Python/2.7/site-packages/scapy/arch/bsd.py", line 12,
>>> in
>>> > 
>>> > from unix import *
>>> >   File "/Library/Python/2.7/site-packages/scapy/arch/unix.py", line
>>> 20, in
>>> > 
>>> > from pcapdnet import *
>>> >   File "/Library/Python/2.7/site-packages/scapy/arch/pcapdnet.py", line
>>> > 160, in 
>>> > import dnet
>>> > ImportError: No module named dnet
>>> >
>>> > So I downloaded and compiled libdnet-1.11 with a:
>>> >  $ sudo ./configure && make
>>> >
>>> > I see it compile fine & the libraries have been installed to:
>>> > /usr/local/sbin/dnet
>>> >
>>> > However, python can't find it... I am not clear on how to point Python
>>> > there...
>>> >
>>> "libdnet" is likely a shared object binary... What I /think/ you
>>> are
>>> missing is the Python library that interfaces with that binary...
>>>
>>> Could http://pypi.python.org/pypi/dnet answer the question?
>>> --
>>> Wulfraed Dennis Lee Bieber AF6VN
>>> wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/
>>>
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>>
>>
>>
>>
>> --
>> John Evans
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
>
> I downloaded scapy manually since for some reason, after using macports,
> it wouldn't find the package at all.
>
> I am also trying to install libdnet manually as mentioned above, so after
> ./configure && make I go into the python directory & do a  python setup.py
> install, which generates a bunch of warnings & the following two errors:
>
> /dnet.c:2729:4: error: assignment to cast is illegal, lvalue casts are not
> supported
>   ((PyObject*)__pyx_v_next) = Py_None;
> Py_INCREF(((PyObject*)__pyx_v_next));
>   ~^~~~ ~
> ./dnet.c:2741:6: error: assignment to cast is illegal, lvalue casts are
> not supported
> ((PyObject *)__pyx_v_next) = __pyx_3;
> ~^ ~
>
>
> Thanks again for any help.  Need to get all this working for this
> mini-project and also because I am starting a SANS class that leverages
> scapy quite a bit...
>
> Kevin
>
>


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


builtin max() and weak ordering

2011-03-03 Thread Stephen Evans
The CPython builtins min() and max() both return the first satisfactory object 
found. This behaviour is undocumented. Examining the source in bltinmodule.c 
shows that min() and max() both result in a call to min_max() with Py_LT and 
Py_GT passed respectively.

The behaviour of min() is correct. But with weak orderings of equivalent 
objects, surely max() should be using Py_GE ? (the converse of Py_LT). Should I 
be reporting a bug, submitting a patch, making feature request or suggesting a 
documentation update ?

For a more mathematical consideration (not casual reading):

Stepanov, Alexander and Paul McJones. 2009. Elements of Programming. Addison 
Wesley. Pages 52-53

The code below demonstrates the issue. Using the total key gives the correct 
result. Using the weak key returns the "incorrect" result. Tested with Python 
2.7.1 and 3.1.2 (applies to 3.2)

Stephen Evans



from __future__ import print_function
from operator import attrgetter

class Pair():
def __init__(self, m0, m1):
self.m0, self.m1 = m0, m1

# rich comparisons are not used
def __lt__(self, other): raise NotImplementedError
def __le__(self, other): raise NotImplementedError
def __eq__(self, other): raise NotImplementedError
def __ne__(self, other): raise NotImplementedError
def __gt__(self, other): raise NotImplementedError
def __ge__(self, other): raise NotImplementedError

def __repr__(self):
"""repr() as a tuple"""
return repr((self.m0, self.m1))

@property
def total(self):
return (self.m0, self.m1)

@property
def weak(self):
return self.m0


def test():
"""
demonstrate the failure of the builtin max() to respect the original order
of equivalent objects.
"""
r = [ (0, 1), (0, 2) ]
r = [ Pair(*p) for p in r ]

# verify total and weak ordering
assert r == sorted(r, key=attrgetter('weak')) == sorted(r, 
key=attrgetter('total'))
print(r)

# from the sorted list
print(r[0], r[-1])

# using total ordering
print(min(r, key=attrgetter('total')), max(r, key=attrgetter('total')))

# using weak ordering, builtin_min and builtin_max functions in 
bltinmodule.c
#   min works as expected using Py_LT
#   max uses Py_GT rather than the converse of Py_LT (which would be Py_GE)
print(min(r, key=attrgetter('weak')), max(r, key=attrgetter('weak')))

test()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Aborting Python from C code

2011-04-30 Thread Dylan Evans
I think i see what you are trying to do but it depends on the environment
and your goals.

Generally i think you need to separate your code by forking (or perhaps you
have already done that?),
then you can run a check to see if the process died as expected. I don't
know though, this not much
information to go on, but if you are running untrusted code then you need to
be able to isolate and kill it.

On Sat, Apr 30, 2011 at 6:17 PM, Chris Angelico  wrote:

> On Sat, Apr 30, 2011 at 6:08 PM, Miki Tebeka 
> wrote:
> >> In our sandboxed Python environment, I would like to be able to
> >> trigger an abort of the currently-running Python script (from a signal
> >> handler or another thread).
> > There's os.abort
>
> That core dumps the process; what I want is to force the
> PyRun_StringFlags to return. Normally PyErr_SetInterrupt will do
> exactly this (within a few instructions is fine), but the Python
> script is able to prevent that from happening, which I don't like.
>
> Chris Angelico
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://dylan-evans.github.com

"The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python enabled gdb on Windows and relocation

2011-05-13 Thread Doug Evans
On Thu, May 12, 2011 at 9:19 AM, Ruben Van Boxem
 wrote:
> (now in plain-text as required by gdb mailing list)
>
> Hi,
>
> I am currently trying to integrate Python support into my toolchain
> build (including GDB of course). It is a sysrooted
> binutils+GCC+GDB+mingw-w64 toolchain.
>
> I currently have the basic setup working: I can link gdb with my
> manually generated import lib to the python dll from the official
> Windows install. If there is anything I am missing or a very easy
> solution to the problems decsribed below, please just say so. I am
> only suggesting what I would like to happen.
>
> Now on to the problems I'd like to discuss:
>
> 1. gdb.exe won't start without me having set PYTHONPATH manually.

In a properly configured/built gdb on linux this isn't necessary, even
if python is installed in some random place.
I'm not sure about windows though.
Did you specify --with-python when you configured gdb, and if so did
you specify a value?
e.g., --with-python=SOME_VALUE

> I understand the need for this, but as gdb requires Python 2, and users
> of my toolchain may have installed Python 3 or a 32-bit version python
> they want to use from the same environment (without changing their own
> PYTHONPATH), there is no way to run python-enabled gdb.
> [...]

Yeah.
There is a proposal to add GDB_PYTHONPATH (or some such IIRC) and have
gdb use that instead of PYTHONPATH if it exists, but there's been
resistance to it.
I think(!) what would happen is that gdb would set $PYTHONPATH to the
value of $GDB_PYTHONPATH.
[Inferiors started by gdb should still get the original value of
PYTHONPATH though.]

> 2. With PYTHONPATH set as a temporary workaround, gdb starts, but
> spits out a traceback:
> Traceback (most recent call last):
>   File "", line 35, in 
>   File "m:\development\mingw64\share\gdb/python/gdb/__init__.py", line
> 18, in 
>     gdb.command.pretty_printers.register_pretty_printer_commands()
>   File 
> "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py",
> line 368, in register_pretty_printer_commands
>     InfoPrettyPrinter()
>   File 
> "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py",
> line 100, in __init__
>     gdb.COMMAND_DATA)
> RuntimeError: Could not find command prefix info.
>
> This is a minor problem I think, as "python import time" "python print
> time.clock()" works as expected. What is wrong?

I'm not sure.
The error message is complaining that the "info" command prefix doesn't exist.
I don't see how that can happen as python is initialized long after
the info command is created.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python enabled gdb on Windows and relocation

2011-05-14 Thread Doug Evans
On Sat, May 14, 2011 at 2:09 AM, Ruben Van Boxem
 wrote:
> 2011/5/14 Doug Evans :
>> On Thu, May 12, 2011 at 9:19 AM, Ruben Van Boxem
>>  wrote:
>>> (now in plain-text as required by gdb mailing list)
>>>
>>> Hi,
>>>
>>> I am currently trying to integrate Python support into my toolchain
>>> build (including GDB of course). It is a sysrooted
>>> binutils+GCC+GDB+mingw-w64 toolchain.
>>>
>>> I currently have the basic setup working: I can link gdb with my
>>> manually generated import lib to the python dll from the official
>>> Windows install. If there is anything I am missing or a very easy
>>> solution to the problems decsribed below, please just say so. I am
>>> only suggesting what I would like to happen.
>>>
>>> Now on to the problems I'd like to discuss:
>>>
>>> 1. gdb.exe won't start without me having set PYTHONPATH manually.
>>
>> In a properly configured/built gdb on linux this isn't necessary, even
>> if python is installed in some random place.
>> I'm not sure about windows though.
>> Did you specify --with-python when you configured gdb, and if so did
>> you specify a value?
>> e.g., --with-python=SOME_VALUE
>
> I was cross-compiling a mingw toolchain+gdb from Linux, so I used
> --with-python without a value (because gdb configure tries to find the
> Python executabe), and I added -I"/path/to/python/includes" to CFLAGS
> and -L"/path/to/pythondll/importlib" to LDFLAGS, which built as it
> should. This is hacky though, and gdb configure should provide
> --with-python-libs and --with-python-include to make it more
> streamlined with any other build prerequisite (like
> gmp/mpfr/mpc/cloog/ppl in GCC for example).

Ah.
Cross-compiling gdb with python is in need of improvement.
Alas python hasn't been designed with cross-compilation in mind (e.g.
build on linux, run on windows).
AIUI, the way to get the parameters required for compiling with
libpython is to get them from python's "distutils": kinda hard to do
in a cross-compile.  Done correctly there's no need to run python.

I haven't done anything more to support python in gdb's configure.ac
because it's not clear to me what the right thing to do is: distutils
provides more than just --libs and --includes (btw, we don't use
--libs though, we use --ldflags which includes all of: the directory
in which to find libpython, the -l for libpython, and the -l's for all
the other libraries python needs). [Which isn't to say that someone
else isn't free to tackle this.]

In the meantime, what I've been doing is a hack: write a script that
responds to:
--includes
--ldflags
--exec-prefix
and pass that as --with-python.

E.g.
bash$ cat $HOME/my-python-for-config
#! /bin/sh

if [ $# -ne 2 ]
then
echo "Bad # args.  Blech!" >&2
exit 1
fi

# The first argument is the path to python-config.py, ignore it.

case "$2" in
--includes) echo "-I/usr/include/python2.6 -I/usr/include/python2.6" ;;
--ldflags) echo "-L/usr/lib/python2.6/config -lpthread -ldl -lutil -lm
-lpython2.6" ;;
--exec-prefix) echo "/usr" ;;
*) echo "Bad arg $2.  Blech!" >&2 ; exit 1 ;;
esac

exit 0
bash$ ./configure --with-python=$HOME/my-python-for-config [...]
[...]


Note that --exec-prefix is the runtime location of python.
GCC uses this to tell libpython where to find its support files.
[grep for Py_SetProgramName in gdb/python/python.c]

>>> I understand the need for this, but as gdb requires Python 2, and users
>>> of my toolchain may have installed Python 3 or a 32-bit version python
>>> they want to use from the same environment (without changing their own
>>> PYTHONPATH), there is no way to run python-enabled gdb.
>>> [...]
>>
>> Yeah.
>> There is a proposal to add GDB_PYTHONPATH (or some such IIRC) and have
>> gdb use that instead of PYTHONPATH if it exists, but there's been
>> resistance to it.
>> I think(!) what would happen is that gdb would set $PYTHONPATH to the
>> value of $GDB_PYTHONPATH.
>> [Inferiors started by gdb should still get the original value of
>> PYTHONPATH though.]
>
> That way would be almost ideal, but a hardcoded *relative* path to the
> python scripts (that is standardized within gdb) wouldn't hurt.

See above re: --exec-prefix.

> An
> extra environment variable would require a lot of explaining for
> Windows, and is not "plug-and-play", like the rest of a sysrooted
> toolchain is supposed to be like. I think this should work on all
> setups:
>
> 1. Check hardcoded path; my suggestion would 

Re: Python enabled gdb on Windows and relocation

2011-05-14 Thread Doug Evans
On Sat, May 14, 2011 at 2:29 AM, Eli Zaretskii  wrote:
>> Date: Sat, 14 May 2011 11:09:13 +0200
>> From: Ruben Van Boxem 
>> Cc: g...@sourceware.org, python-list@python.org
>>
>> 1. Check hardcoded path; my suggestion would be "> executable>/../lib/python27"
>> 2. If this fails to find the necessary files/scripts, find it like you
>> described above in Linux, without PYTHONPATH set.
>> 3. Check PYTHONPATH.
>>
>> I would think only number one would change, and perhaps be only
>> enabled with a special configure option. Nothing else would have to
>> change, and Windows users would rejoice :)
>
> The problem, I think, is that it's not so easy on Unix to get the
> place where the GDB executable leaves.  There isn't a system call to
> do that (similar to what Windows gives you).
>
> So I think on Posix platforms, number 2 would be used most of the
> time.

For reference sake, gdb is "relocatable".
[meaning, if you take a gdb installation and move it, it should
continue to work fine]
And if gdb's python lives inside the gdb tree, that too should
continue to work fine if moved with gdb (the value to pass to
Py_SetProgramName is appropriately (re-)computed when gdb is run).
[For completeness sake, IIRC the calculation of a path being
"relocatable" isn't bulletproof, but it works in practice.]

It's not impossible for gdb to find where it lives, but you're right
it can be moderately difficult (basically, if argv[0] isn't an
absolute path then scan $PATH for it).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python enabled gdb on Windows and relocation

2011-05-14 Thread Doug Evans
On Sat, May 14, 2011 at 11:30 AM, Doug Evans  wrote:
> Note that --exec-prefix is the runtime location of python.
> GCC uses this to tell libpython where to find its support files.
> [grep for Py_SetProgramName in gdb/python/python.c]

Oops.  s/GCC/GDB/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python enabled gdb on Windows and relocation

2011-05-17 Thread Doug Evans
On Sun, May 15, 2011 at 6:26 AM, Ruben Van Boxem
 wrote:
> Wow, I think I have a partial solution. Delving into the Python docs,
> for example here:
> http://docs.python.org/using/windows.html#finding-modules, you can see
> that PYTHONPATH is used first, then the Windows registry, then
> PYTHONHOME, then some default relative paths. I placed the python
> scripts all in the directory structure like so:
>
> /bin/gdb
> /bin/Lib/
> /bin/python27.dll
>
> This works, even without any manual PYTHONPATH intervention. Problem
> is though, that as soon as someone has a PYTHONPATH environment
> variable from a (incompatible) Python installation (think different
> bitness or version 3.x instead of 2.7.1), I cannot predict what will
> go wrong. This problem originates in Python's way of filling in the
> search path (sys.path). A true solution in the GDB case to prevent
> this collision of an incompatible PYTHONPATH would be that GDB sets an
> internal PYTHONPATH as directed by configure, uses that to load its
> Python internals, and allows the GDB child processes (apps being
> debugged) to use the environment PYTHONPATH. For now, I have a
> functional installation, but it will break as soon as someone installs
> Python on their system.

What if the user *wants* gdb's python to use $PYTHONPATH from his/her
environment?
To handle *this* case, *and* the case of an incompatible python
installation using $PYTHONPATH, there is the $GDB_PYTHONPATH proposal
(see earlier email for details).  It feels problematic to decide at
configure time whether there will or will not be an incompatible
python at runtime.

[I realize you have subsequent messages.
Just replying in sequence.]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python enabled gdb on Windows and relocation

2011-05-17 Thread Doug Evans
On Sun, May 15, 2011 at 9:11 AM, Ruben Van Boxem
 wrote:
> I am sorry for the repeated messages that no one cares about, but I
> may have discovered GDB in its current form already allows what I
> want: I tried to figure out what exact paths the snake in gdb was
> using to search for its modules, and came up with this:
> (gdb) python import sys
> (gdb) python print sys.path
> ['m:\\development\\mingw64\\share\\gdb/python',
> 'M:\\Development\\mingw64\\bin\\python27.zip',
> 'M:\\Development\\mingw64\\bin\\DLLs',
> 'M:\\Development\\mingw64\\bin\\lib',
> 'M:\\Development\\mingw64\\bin\\lib\\plat-win',
> 'M:\\Development\\mingw64\\bin\\lib\\lib-tk',
> 'M:\\Development\\mingw64\\bin',
> 'M:\\Development\\mingw64\\bin\\lib\\site-packages']
>
> This means that every python command within gdb searches
> /share/gdb/python FIRST (even before an environment's
> PYTHONPATH), alleviating any concerns or problems I or anyone would
> have with another python installation, as this apparently built-in
> path comes up first. All I, or anyone interested in doing this kind of
> thing, have to do is copy all the python scripts from the Windows
> installation's Lib directory to the /share/gdb/python
> directory.
>
> I don't know where this path comes from, but it is quite handy, and
> makes this whole discussion  moot for Python people. Only "issue" that
> I'll have to work around is the --with-python-includes and
> --with-python-libs that are missing, using either manual
> CFLAGS/LDFLAGS or a variant of your script.

IMO *if* gdb wanted to support people adding files to *its*
/share/gdb directory, more thought is needed - e.g. maybe
document a "site" directory for such files.  Dunno.  IMO we certainly
don't want to formally allow folks to willy-nilly put anything there -
no guarantees a future release might add something that collides with
something the user put there.
If and until then, you're probably pretty safe if you put everything
in a subdirectory with a unique enough name, if you really wanted to
go this route.

Btw, there is the system.gdbinit file which sites *are* free to customize.

E.g., configure --with-system-gdbinit=/share/gdb/system.gdbinit.

You can put whatever you want in that file.
E.g., you could add a directory to python's sys.path.

[Technically speaking, the path /share/gdb/system.gdbinit
goes against what I just said, but IMO this name is safe.]
-- 
http://mail.python.org/mailman/listinfo/python-list


Installation Problems with Python 3.7.3

2019-05-20 Thread Carolyn Evans
I am having trouble with re-installing python 3.7.3.

I keep getting the following message:

Modify
Repair
Remove

I have tried all three numerous times and can not complete the setup

I am working on a Windows 8 system,  64 bit OS,  4GB ram.

How can this be fixed?

Thanks

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


Re: Installation Problems with Python 3.7.3

2019-05-23 Thread Carolyn Evans
I got it working.

Thanks

On Mon, May 20, 2019 at 3:17 PM Igor Korot  wrote:

> Hi,
>
> On Mon, May 20, 2019 at 1:53 PM Carolyn Evans  wrote:
> >
> > I am having trouble with re-installing python 3.7.3.
>
> Why do you need to reinstall?
> What seems to be the problem?
>
> Thank you.
>
> >
> > I keep getting the following message:
> >
> > Modify
> > Repair
> > Remove
> >
> > I have tried all three numerous times and can not complete the setup
> >
> > I am working on a Windows 8 system,  64 bit OS,  4GB ram.
> >
> > How can this be fixed?
> >
> > Thanks
> >
> > C. Evans
> > --
> > https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: stderr writting before stdout

2020-05-24 Thread Dylan Evans
Hi,
This data is being line buffered, so either a newline or flush is required
to get it to actually write to the terminal / file.

On Sun, May 24, 2020 at 2:34 PM Souvik Dutta 
wrote:

> Also this code maintains order i.e. writting is displayed before no errors.
> Why is that?
>
> import sys
> sys.stdout.write("Writting \n")
> sys.stderr.write("No errors \n")
>
> On Sun, 24 May, 2020, 9:57 am Souvik Dutta, 
> wrote:
>
> > Hi,
> > Is there any precedence or priority order by which sys.stderr.write() and
> > sys.stdout.write() works. Because when running the below code...
> >
> > import sys
> > sys.stdout.write("Writting")
> > sys.stderr.write("No errors \n")
> >
> > No errors is written (displayed) first and writting is written later. Why
> > does this happen?
> >
> >
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


some pointers for a newbie

2004-12-04 Thread John Evans
Hi, I have decided to play around with python, for the simple reason 
there appears nothing better to do at 2am on a sunday morning ;)

Anyway I am familiar with languages similar to PHP, javaa script, and 
also languages which have similarities on the surface to python such as 
Lingo (macromedia Director). so python is looking fairly straight 
forward, but what i am noticing is a complete lack of basic starter 
knowledge from myself - to be expected one would think :D

So what i ask is, for someone who wants to dip his toe in the pond and 
runs a powerbook with os x what tools, resources should I look into as 
being the most useful?

Also is it best to use an IDE like the one which comes from installing 
macPython, or is it best to use a basic text editor, or perhaps even 
xcode could be recommended (esp if I wanted to build some simple UI 
using interface builder?)

Any and all responses greatly received.
cheers
john
--
http://mail.python.org/mailman/listinfo/python-list


Organising data within a program

2004-12-13 Thread Nick Evans
Hey all,
I am currently working on a simple program (small group membership database)
just to get to grips with the language (bit of a newbie here :-)) and am
wondering about the best way of organising the data within the program.

>From my understanding I would have something like person1
=("name","address","phone","subs-due")
Then you would putmembershipdatabase = (person1, person2, personX)
etc
Now is this the best way of organising this data within the program or is
there a better "known" way?

Also I want to just store this info to a standard txt file. Probably CSV or
something. Is there any particular way I should be saving this data to file?


Thanks in advance

Nick


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


Installing Parsers/Tree Builders to, and accessing these packages from Python2.7

2014-11-01 Thread Simon Evans
Hi Programmers, 
I have downloaded, installed, and can access the LXMLTreeBuilder/lxml, from 
Python2.7. 
however I have also downloaded HTMLTreeBuilder/html5lib but cannot get console 
to recognize the download, even using the code the download site suggests. I 
did put it in the Python2.7 directory, but unlike the HTML one, it doesn't 
recognize it, so the import statement returns an error. 
Can anyone tell me how I might proceed so's these TreeBuilders/ Parsers will 
work on my Python console ? 
I also will have to install HTMLParserTreeBuilder/html.parser and 
LXMLTreeBuilderForXML/lxml but best to cross that bridge when gotten to, as 
they say. 
Thank you for reading.I look forward to hearing from you.
Yours 
Simon Evans
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Installing Parsers/Tree Builders to, and accessing these packages from Python2.7

2014-11-02 Thread Simon Evans
Dear Terry Reedy 
I am using operating system Windows 7. 
I put the HTML TreeBuilder / htm5 library into the Python2.7 folder. 
I read that the LXML Treebuilder /lmxl installs itself automatically to the 
Python2.7 installation, so that is why I am not having difficulty with that 
installation. 
I don't think it really matters where the lxml download ended up necessarily, 
all I want is to know how I can install it so it works, I cannot get any 
feedback because it isn't working, all I get is the automated inbuilt response 
about 'Do I want a treebuilder/ parser that is appropriate to the input' or 
words to that effect. What I want to know is how to get this lxml 
treebuilder/parser to run, ie: what is the protocol for running the lxml 
download so's it'll run, or what sort of code to I put to my python console in 
order to get it to run, seeing as the input suggested by the download site does 
not get it to run.  Maybe I should rephrase my question : how do I install 
LXMLTreeBuilder/lxml, and how do I download and install HTMLParserTreeBuilder 
and LXMLTreeBuilderForXML to my Python2.7, please ? I can post the Traceback 
but all it says is that it doesn't recognise any input with 'html5lib' in it. I 
will post the console response if it is important, but I can't see how it is 
relevan
 t to my request - which is how do I get these 'treebuilder/ parsers' to 
install and run.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Installing Parsers/Tree Builders to, and accessing these packages from Python2.7

2014-11-02 Thread Simon Evans
I have proceeded to click on the 'setup.py' in the html5-0.999 lib and got a 
python console for a few seconds, this may have been the installation of the 
HTML5 parser/ treebuilder - I will have to put the code that did not work to it 
previously to it again, hopefully it will. 

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


Re: Installing Parsers/Tree Builders to, and accessing these packages from Python2.7

2014-11-02 Thread Simon Evans
Dear Mark Lawrence, 
I have tried inputting the code in the first link, re:
>>> import lxml
>>> import lxml.etree
>>> import bs4.builder.htmlparser
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named htmlparser
>>> import bs4.builder._lxml
>>> import bs4.builder.html5lib
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named html5lib
>>>

which tells me lxml is installed, but that neither html nor html5 is installed. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Installing Parsers/Tree Builders to, and accessing these packages from Python2.7

2014-11-02 Thread Simon Evans
I have got the html5lib-0.999.tar.gz

and the HTMLParser-0.0.2.tar.gz files in my Downloads the problem is how I

install them to Python2.7. 

The lxml-3.3.3.win32-py2.7 is an exe file, which upon clicking will install 

but obviously the html and the html5 installations  are not so 

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


Re: Installing Parsers/Tree Builders to, and accessing these packages from Python2.7

2014-11-02 Thread Simon Evans

Oh I don't mind quoting console output, I just thought I'd be sparing you 

unnecessary detail. 

output was going nicely as I input text from my 'Getting Started with 

Beautiful Soup' even when the author reckoned things would go wrong - due to

lxml not being installed, things went right, because I had already installed

it, re:

page 17

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.
>>> import urllib2
>>> from bs4 import BeautifulSoup
>>> url = "http://www.packtpub.com/books";
>>> page = urllib2.urlopen(url)
>>> soup_packtpage = BeautifulSoup(page)
>>> with open("foo.html","r") as foo_file:
... soup_foo = Soup(foo_file)
  File "", line 2
soup_foo = Soup(foo_file)
   ^
IndentationError: expected an indented block
>>> soup_foo= BeautifulSoup("foo.html")

page 18

>>> print(soup_foo)
foo.html
>>> soup_url = BeautifulSoup("http://www.packtpub.com/books";)
>>> print(soup_url)
http://www.packtpub.com/books
>>> helloworld = "Hello World"
>>> soup_string = BeautifulSoup(helloworld)
>>> print(soup_string)
Hello World

page 19: no code in text on this page

page 20

>>> soup_xml = BeautifulSoup(helloworld,features= "xml")
>>> soup_xml = BeautifulSoup(helloworld,"xml")
>>> print(soup_xml)

Hello World
>>> soup_xml = BeautifulSoup(helloworld,features = "xml")
>>> print(soup_xml)

Hello World
>>>

Then on bottom of page 20 it says 'we should install the required parsers using 
easy-install,pip or setup.py install' but as I can't get the downloads of html 
or html5 parsers, text code halfway down returns statutory response regarding 
requisite parser needing to be installed, re: 

page 21

>>> invalid_html = '>> soup_invalid_html = BeautifulSoup(invalid_html,'lxml')
>>> print(soup_invalid_html)

>>> soup_invalid_html = BeautifulSoup(invalid_html,'html5lib')
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python27\lib\site-packages\bs4\__init__.py", line 155, in __init__
% ",".join(features))
ValueError: Couldn't find a tree builder with the features you requested: 
html5lib. Do you need to install a parser library?
>>>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Installing Parsers/Tree Builders to, and accessing these packages from Python2.7

2014-11-02 Thread Simon Evans
What I meant to say was I can't get the html5 or the html parsers to install, I 
have got their downloads in their respective directories in the downloads 
directory. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Installing Parsers/Tree Builders to, and accessing these packages from Python2.7

2014-11-03 Thread Simon Evans
I input 'pip install html5lib' to the Python 2.7 console and got :

>>> pip install html5lib
  File "", line 1
pip install html5lib
  ^
SyntaxError: invalid syntax
>>>

I am not sure what you mean about 'single line paragraphs'. I put my text 

into double line spacing in my last missive, I left the code input/ output 

in single line spacing as that is how it reads from the console, after all 

who am I to alter it? Regarding 'context' if you are referring to the text 

I am using, it is from 'Getting Started in Beautiful Soup' by Vineeth G.

Nair. 

For what its worth some of the subsequent code in the book runs, but not 

all, and I think this may be due to the parser installation factor, and I 

wanted to work through the book (112 pages) without any errors being 

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


Re: Installing Parsers/Tree Builders to, and accessing these packages from Python2.7

2014-11-03 Thread Simon Evans
I input to the cmd console  'pip install html5lib' but again got an error 
return. I thought one of the participants was unhappy about single line spacing 
(re: single line paragraphs') Okay I will go back to single line spacing, I 
don't think it is all that important, really.
Anyway this is my console's response:- 


Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Intel Atom>pip install html5lib
'pip' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Intel Atom>  
 
-- 
https://mail.python.org/mailman/listinfo/python-list


How do you download and install HTML5TreeBuilder ?

2014-11-18 Thread Simon Evans
Dear Programmers,
I have installed the HTMLParserTreebuilder and LXMLTreeBuilder downloads to my 
Python2.7 console, using the Windows Console 'pip install' procedure.

I downloaded HTML5 files and installed them to my Python2.7 directory, and went 
through the 'pip install' procedure, but this did not work. 

I do not know whether it is because different procedure must be followed for 
HTML5, or that I downloaded the wrong files, the files I downloaded and 
attempted to install were the following three :- 

html5lib-0.999(1).tar.gz

html5lib-0.999.tar.gz

HTMLParser-0.0.2.tar.gz

The  Windows 7.0 Console returned the following in response :- 
 
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Intel Atom>pip install HTML5
Downloading/unpacking HTML5
  Could not find any downloads that satisfy the requirement HTML5
Cleaning up...
No distributions at all found for HTML5
Storing debug log for failure in c:\users\intela~1\appdata\local\temp\tmp4pxazz

C:\Users\Intel Atom>pip install HTML5
Downloading/unpacking HTML5
  Could not find any downloads that satisfy the requirement HTML5
Cleaning up...
No distributions at all found for HTML5
Storing debug log for failure in c:\users\intela~1\appdata\local\temp\tmp81fbka

C:\Users\Intel Atom>pip install HTML5
Downloading/unpacking HTML5
  Could not find any downloads that satisfy the requirement HTML5
Cleaning up...
No distributions at all found for HTML5
Storing debug log for failure in c:\users\intela~1\appdata\local\temp\tmphaw01m

C:\Users\Intel Atom>

I suppose my main conundrum is from where can I download a version of the 
HTML5 Treebuilder that will install using pip. It doesn't help that HTML5 also 
happens to be the name of some video editing software. 
Thank you for reading.
PS: If anyone is upset about 'one line paragraphs' and other such petulancies, 
then please decline to respond, seeing as far as I'm concerned such 
trivialities are besides the point, and are of no help, so vent your ire 
elsewhere. 
YOurs Simon Evans. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you download and install HTML5TreeBuilder ?

2014-11-18 Thread Simon Evans
re: 

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Intel Atom>pip install html5lib
Downloading/unpacking html5lib
  Running setup.py (path:c:\users\intela~1\appdata\local\temp\pip_build_Intel At
om\html5lib\setup.py) egg_info for package html5lib

Downloading/unpacking six (from html5lib)
  Downloading six-1.8.0-py2.py3-none-any.whl
Installing collected packages: html5lib, six
  Running setup.py install for html5lib

Successfully installed html5lib six
Cleaning up...

C:\Users\Intel Atom>


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


Tag objects in Beautiful Soup

2014-11-20 Thread Simon Evans
Re:'Accessing the Tag object from Beautiful Soup' (page 22-25 - Getting Started 
with Beautiful Soup)
So far the code to python27 runs as given in the book, re: - 

>>> html_atag = """Test html a tag example
... http://www.packtpub.com'>Home
... >> soup = BeautifulSoup(html_atag,'lxml')
>>> atag = soup.a
>>> print(atag)
http://www.packtpub.com'>Home</a>
<a href=" http="">

>>> type(atag)

>>>
>>> tagname = atag.name
>>> print tagname
a
>>> atag.name = 'p'
>>> print (soup)
Test html a tag example
http://www.packtpub.com'>Home</a>
<a href=" http="">



then under the next Sub heading : 'Attributes of a Tag object'
text reads : 
atag = soup_atag.a
print (atag['href'])

#output
http://www.packtpub.com

however when I put this code to the console I get error returns at the first 
line re:- 

>>> atag = soup_atag.a
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'soup_atag' is not defined
>>>
----
Can anyone tell me where I am going wrong or where the text is wrong ? 
So far the given code has run okay, I have put to the console everything the 
text tells you to. 
Thank you for reading.
Simon Evans
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python 2.7 and unicode (one more time)

2014-12-02 Thread Simon Evans

Hi Peter Otten
re:

There is no assignment 

soup_atag = whatever 

but there is one to atag. The whole session should when you omit the 
offending line 

> atag = soup_atag.a 

or insert 

soup_atag = soup 

before it. 

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.
>>> import urllib2
>>> from bs4 import BeautifulSoup
>>> html_atag = """Test html a tag example
... http://www.packtpub.com'>Home
... >> soup = BeautifulSoup(html_atag,'lxml')
>>> atag = soup.aprint(atag)
>>> atag = soup.a
>>> print(atag)
http://www.packtpub.com'>Home


>>> type(atag)

>>> tagname = atag.name
>>> print tagname
a
>>> atag.name = 'p'
>>> print (soup)
Test html a tag example
http://www.packtpub.com'>Home



>>> atag.name = 'p'
>>> print(soup)
Test html a tag example
http://www.packtpub.com'>Home



>>> atag.name = 'a'
>>> print(soup)
Test html a tag example
http://www.packtpub.com'>Home



>>> soup_atag = soup
>>> atag = soup_atag.a
>>> print (atag['href'])
http://www.packtpub.com'>Home
>>

Thank you.
Yours
Simon.

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


Text Code(from 'Getting Started in Beautiful Soup' re: cd Soup , returns 'Syntax Error, invalid syntax'

2014-12-11 Thread Simon Evans
At the start of Chapter 3 of 'Getting Started in Beautiful Soup' it has said to 
create a html file, 'ecological 

pyramid.html' - which I have already done re:







plants
10


algae
10




deer
1000

deer
1000


rabbit
2000




fox
100


bear
100




lion
80


tiger
50





and ran it okay in 'Explorer', and text then says to save it to a folder named 
'Soup' which I have done. 
On the next page (30) it says to navigate to that folder with the following  
code to the python console :-
 
cd Soup

however console rejects that code with the following return: - 

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.
>>> cd Soup
  File "", line 1
cd Soup
  ^
SyntaxError: invalid syntax
>>>
----
Thank you for reading, hope you can help.
Yours
Simon Evans
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Text Code(from 'Getting Started in Beautiful Soup' re: cd Soup , returns 'Syntax Error, invalid syntax'

2014-12-14 Thread Simon Evans
Thanks Guys 
This book keeps swapping from the Python console to the Windows - without 
telling you, but it is the only book out there on 'Beautiful Soup' so I have 
got to put up with it. There's more problems with it, but I will start a new 
thread in regard of, I don't know if its related to the above or not. 
Yours 
Simon.
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2014-12-14 Thread Simon Evans
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 "", line 1, in 
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


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

2014-12-14 Thread Simon Evans
I had another attempt at inputting the code perhaps with the right indentation, 
I still get an error return, but not one that indicates that the code has not 
been read, as you suggested. re:- 


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")
  File "", line 3
producer_entries = soup.find("ul")
   ^
SyntaxError: invalid syntax
>>>  from bs4 import BeautifulSoup
  File "", line 1
from bs4 import BeautifulSoup

If, as you suggest I left a free line after the "with open( etc" line, console 
returns an error, if I leave a free line after the "soup = etc" line which 
comes after, again I get an error return, my only point is that with the above 
input, console return does not seem to infer that soup has not been defined. 
You recommend that I put all the code into a file then run it - how do I do 
that ? I am new to Python, as you might have gathered. 
Thank you for your help.
Yours Simon
-- 
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 Simon Evans
Dear Jussi, and Billy
I have changed the input in accordance with your advice, re:
--
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 = next(ecological_pyramid,"lxml")
...  producer_entries = soup.find("ul")
...  print(producer_entries.li.div.string)
... print(producer_entries.li.div.string)
  File "", line 5
print(producer_entries.li.div.string)
^
SyntaxError: invalid syntax
>>> print (producer_entries.li.div.string)
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'producer_entries' is not defined
>>> from bs4 import BeautifulSoup
>>> with open("ecologicalpyramid.html","r") as ecological_pyramid:
...  soup = next(ecological_pyramid,"lxml")
...  producer_entries = soup.find("ul")
...  print(producer_entries.li.div.string)
...

As no doubt you can see, the last line, indented as it is, does not provide the 
output that the book's text says it will return - ie the word 'plants'
If I do not indent it, it returns an 'invalid syntax error' stating that 
'producer_entries' is not defined. Though code in the previous line is meant to 
do just that - isn't it ? 
-- 
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-18 Thread Simon Evans
@Steven D'Aprano,
I input the following to Python 2.7, which got the following:- 

>>> from bs4 import BeautifulSoup
>>> with open("ecologicalpyramid.html","r") as ecological_pyramid:
...  soup= next(ecological_pyramid,"lxml")
...  producer_entries = soup.find("ul")
...
Traceback (most recent call last):
  File "", line 1, in 
IOError: [Errno 2] No such file or directory: 'ecologicalpyramid.html'
>>>

- I kept to your instructions to input the 'Enter' after the fourth line and 
then before the fifth line, ie between the indented block and the unindented 
one, which as above, doesn't give me a chance to actually input the fifth line. 
If I do it both ways, ie: pressing enter after the fourth and before the fifth 
or just pressing enter after the fourth and then after the fifth line of input, 
which again it won't actually let me input because before I do, I still get an 
error return.
-- 
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

2015-01-04 Thread Simon Evans
Dear Michael Torrie,
Thanks for pointing that out to me re: it not being a syntax problem.
The thing is there is a file called 'EcologicalPyramid.html'. I put it in a 
folder called 'Soup' as the text advised on page 28. For what its worth I also 
shifted the Windows Command Prompt to that folder (re: cd Soup)as instructed on 
page 30, and put a duplicate file of 'EcologicalPyramid.html' in the python 2.8 
directory. 
I therefore am wondering where I ought put this html file where the Python 
console will recognize it ? 
Thank you for your attention,
Yours 
Simon  

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


How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-10 Thread Simon Evans
I am new to Python, but my main interest is to use it to Webscrape. I have 
downloaded Beautiful Soup, and have followed the instruction in the 'Getting 
Started with Beautiful Soup' book, but my Python installations keep returning 
errors, so I can't get started. I have unzipped Beautiful Soup to a folder of 
the same name on my C drive, in accordance with the first two steps of page 12 
of the aforementioned publication, but proceeding to navigate to the program as 
in step three, re: "Open up the command line prompt and navigate to the folder 
where you have unzipped the folder as follows:
cd Beautiful Soup
python setup python install "

This returns on my Python 27 :
>>> cd Beautiful Soup
File "",line 1
cd Beautiful Soup
   ^
SyntaxError: invalid syntax
>>>

also I get:
>>> cd Beautiful Soup
SyntaxError: invalid syntax
>>>

to my IDLE Python 2.7 version, same goes for the Python 3.4 installations. 
Hope someone can help. 
Thanks in advance.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-11 Thread Simon Evans

Thank you everyone who replied, for your help. Using the command prompt 
console, it accepts the first line of code, but doesn't seem to accept the 
second line. I have altered it a little, but it is not having any of it, I 
quote my console input and output here, as it can probably explain things 
better than I :- 


Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Intel Atom>cd"c:\Beautiful Soup"
The filename, directory name, or volume label syntax is incorrect.

C:\Users\Intel Atom>cd "c:\Beautiful Soup"

c:\Beautiful Soup>python setup.py install.
  File "setup.py", line 22
print "Unit tests have failed!"
  ^
SyntaxError: invalid syntax

c:\Beautiful Soup>python setup.py install"
  File "setup.py", line 22
print "Unit tests have failed!"
  ^
SyntaxError: invalid syntax

c:\Beautiful Soup>

I have tried writing "python setup.py install" 
ie putting the statement in inverted commas, but the console still seems to 
reject it  re:- 

c:\Beautiful Soup>"python setup. py install"
'"python setup. py install"' is not recognized as an internal or external comman
d,
operable program or batch file.

c:\Beautiful Soup>


Again I hope you python practitioners can help. I am only on page 12, and have 
another 99 pages to go, so can only hope it gets easier.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-11 Thread Simon Evans
Dear Chris Angelico,
Yes, you are right, I did install Python 3.4 as well as 2.7. I have removed 
Python 3.4, and input the code you suggested and it looks like it has installed 
properly, returning the following code:- 

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Intel Atom>cd "c:\Beautiful Soup"

c:\Beautiful Soup>c:\Python27\python setup.py install
running install
running build
running build_py
creating build
creating build\lib
copying BeautifulSoup.py -> build\lib
copying BeautifulSoupTests.py -> build\lib
running install_lib
copying build\lib\BeautifulSoup.py -> c:\Python27\Lib\site-packages
copying build\lib\BeautifulSoupTests.py -> c:\Python27\Lib\site-packages
byte-compiling c:\Python27\Lib\site-packages\BeautifulSoup.py to BeautifulSoup.p
yc
byte-compiling c:\Python27\Lib\site-packages\BeautifulSoupTests.py to BeautifulS
oupTests.pyc
running install_egg_info
Writing c:\Python27\Lib\site-packages\BeautifulSoup-3.2.1-py2.7.egg-info

c:\Beautiful Soup>

Would that things were as straightforward as they are in the books, but anyway 
thank you much for your assistance, I'd still be typing the zillionth variation 
on the first line without your help. I don't doubt though that I will be coming 
unstuck in the not distant future. Until then, again thank you for your 
selfless help.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-11 Thread Simon Evans
I have downloaded Beautiful Soup 3, I am using Python 2.7. I understand from 
your message that I ought to use Python 2.6 or Python 3.4 with Beautiful Soup 
4, the book I am using 'Getting Started with Beautiful Soup' is for Beautiful 
Soup 4. Therefore I gather I must re-download Beautiful Soup and get the 4 
version, dispose of my Python 2.7 and reinstall Python 3.4. I am sure I can do 
this, but doesn't the above information suggest that the only Python grade left 
that might work with Beautiful Soup 3 would by Python 2.7 - which is the 
configuration I have at present, though I am not perfectly happy, as it is not 
taking code in the book (meant for BS4) such as the following on page 16 :

helloworld = "Hello World"

re:- 

c:\Beautiful Soup>helloworld = "Hello World"
'helloworld' is not recognized as an internal or external command,
operable program or batch file.

I take it that this response is due to using code meant for BS4 with Python 
2.6/ 3.4, rather than BS3 with Python 2.7 which is what I am currently using. 
If so I will change the configurations.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-11 Thread Simon Evans
Yeah well at no point does the book say to start inputting the code mentioned 
in Python command prompt rather than the Windows command prompt, but thank you 
for your guidance anyway. 
I have downloaded the latest version of Beautiful Soup 4, but am again facing 
problems with the second line of code, re:-
--- 
 Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Intel Atom>cd "c:\Beautiful Soup"

c:\Beautiful Soup>c:\Python27\python setup.py install
c:\Python27\python: can't open file 'setup.py': [Errno 2] No such file or direct
ory

though that was the code I used before which installed okay see above). Can 
anyone tell me where I am going wrong ? Thanks.  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-11 Thread Simon Evans
On Monday, May 12, 2014 12:19:24 AM UTC+1, Simon Evans wrote:
> Yeah well at no point does the book say to start inputting the code mentioned 
> in Python command prompt rather than the Windows command prompt, but thank 
> you for your guidance anyway. 
> 
> I have downloaded the latest version of Beautiful Soup 4, but am again facing 
> problems with the second line of code, re:-
> 
> ---
>  
> 
>  Microsoft Windows [Version 6.1.7601]
> 
> Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
> 
> 
> 
> C:\Users\Intel Atom>cd "c:\Beautiful Soup"
> 
> 
> 
> c:\Beautiful Soup>c:\Python27\python setup.py install
> 
> c:\Python27\python: can't open file 'setup.py': [Errno 2] No such file or 
> direct
> 
> ory
> 
> 
> 
> though that was the code I used before which installed okay see above). Can 
> anyone tell me where I am going wrong ? Thanks.
Oh I think I see - I should be using Python 3.4 now, with BS4 ?  

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


Re: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-11 Thread Simon Evans
- but wait a moment 'BeautifulSoup4 works with 2.6+ and 3.x'(Terry Reedy) - 
doesn't 2.6 + = 2.7, which is what I'm using with BeautifulSoup4.  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-12 Thread Simon Evans
Hi Ian, thank you for your help. 
Yes that is the book by Vineeth J Nair.
At the top of page 12, at step 1 it says :

1.Download the latest tarball from 
https://pypi.python.org/packages/source/b/beautifulsoup4/.

So yes, the version the book is dealing with is beautiful soup 4. 
I am using Pyhon 2.7, I have removed Python 3.4.
Also on the bottom of page 10, Mr Nair states:

Pick the path variagble and add the following section to the Path variable:

;C:\PythonXY for example C:\Python27

Which tells me that the Python version cited in the book must be 2.7

I downloaded beautiful soup 4 last night. I unzipped it with 'Just unzip it' to 
a folder I called Beautiful Soup, the same as I did with the previous beautiful 
soup download. The console return is as below, showing that I am now facing the 
same conundrum as yesterday, before changing my version of Beautiful Soup. re:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Intel Atom>cd "c:\Beautiful Soup"

c:\Beautiful Soup>Beautiful Soup>c:\Python27\python setup.py install
'Beautiful' is not recognized as an internal or external command,
operable program or batch file.

c:\Beautiful Soup>


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


Re: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-12 Thread Simon Evans
The version of Python the book seems to be referring to is 2.7, re: bottom of 
page 10-
'Pick the Path variable and add the following section to the Path variable: 
;C:\PythonXY for example C:\Python 27'

The version of Beautiful Soup seems to be Beautiful Soup 4 as at the top of 
page 12 it states:
'1.Download the latest tarball from 
https://pypi.python.org/packages/source/b/beautifulsoup4/.'

I have downloaded and unzipped to a folder called 'Beautiful Soup' on the C 
drive the Beautiful Soup 4 version. I am using the Python 2.7 console and IDLE, 
I have removed the 3.4 version. 

All the same I seem to be having difficulties again as console wont accept the 
code it did when it was the previous version of BS that I used yesterday. I 
realise I would not be having this problem if I proceeded to input the 'Hello 
World' code on the Python console, but as said, the text never specifically 
said 'change to Python 2.7 console'. I thought the problem was with the BS 
version and so changed it, but now can't even get as far as I had before 
changing it. Anyhow be that as it may, this is the console response to my input:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Intel Atom>cd "c:\Beautiful Soup"

c:\Beautiful Soup>Beautiful Soup>c:\Python27\python setup.py install
'Beautiful' is not recognized as an internal or external command,
operable program or batch file.

c:\Beautiful Soup>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-12 Thread Simon Evans
Thank you for your advice. I did buy a book on Python, 'Hello Python' but the 
code in it wouldn't run, so I returned it to the shop for a refund. I am going 
to visit the local library to see if they have any books on Python. I am 
familiar with Java and Pascal, and looking at a few You tubes on the subject, 
thought it was not much different, and shares many of the oop concepts 
(variables, initializing, expressions, methods, and so on, but I realize there 
is no point in walking backwards in new territory.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-12 Thread Simon Evans
Dear Ian, 
The book does recommend to use Python 2.7 (see bottom line of page 10).
The book also recommends to use Beautiful Soup 4. 
You are right that in that I have placed the unzipped BS4 folder within a 
folder, and I therefore removed the contents of the inner folder and 
transferred them to the outer folder. 
The console now can access the contents of the Beautiful Soup folder, but it is 
still having problems with it as the last output to my console demonstrates :


Microsoft Windows [Version 6.1.7601]

Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Intel Atom>cd "c:\Beautiful Soup"

c:\Beautiful Soup>c:\Python27\python setup.py install
running install
running build
running build_py
error: package directory 'bs4' does not exist

c:\Beautiful Soup>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-12 Thread Simon Evans
I did download the latest version of Beautiful Soup 4 from the download site, 
as the book suggested. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-13 Thread Simon Evans
I have removed the original Beautiful Soup 4 download, that I had unzipped to 
my Beautiful Soup directory on the C drive. 
I downloaded the latest version of Beautiful Soup 4 from the Crummy site. 
I unzipped it, and removed the contents of the unzipped directory and placed 
contents in my Beautiful Soup directory, and again had the same output to my 
console re: 

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Intel Atom>cd "c:\Beautiful Soup"

c:\Beautiful Soup>c:\Python27\python setup.py install

c:\Beautiful Soup>
---
I have made a note of all the contents of the downloaded and unzipped BS4,ie 
the contents of my Beautiful Soup folder on the C drive, which is as follows:
---
running install
running build
running build_py
error: package directory 'bs4' does not existinit
_html5lib
_htmlparser
_lxml
6.1
AUTHORS
conf
COPYING
dammit
demonstration_markup
element
index.rst
Makefile
NEWS
PGK-INFO
README
setup
test_builder_registry
test_docs
test_html5lib
test_htmlparser
text_lxml
test_soup
test_tree
testing
TODO

I can see no bs4 folder within the contents.
 I can not see any setup.py file either, but this is how I downloaded it.
I am only following instructions as suggested.
I do not understand why it is not working.
I hope someone can direct me in the right direction, as I seem to be stuck, and 
I don't think it has much bearing on my fluency or lack of it with Python. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-13 Thread Simon Evans
Dear Ian,  and other programmers, thank you for your advice. 
I am resending the last message because this twattish cut and paste facility on 
my computer has a knack of chopping off ones original message, I will try to 
convey the right message this time :  

I have removed the original Beautiful Soup 4 download, that I had unzipped to 
my Beautiful Soup directory on the C drive. 
I downloaded the latest version of Beautiful Soup 4 from the Crummy site. 
I unzipped it, and removed the contents of the unzipped directory and placed 
contents in my Beautiful Soup directory, and again had the same output to my 
console re: 

 

Microsoft Windows [Version 6.1.7601] 
Copyright (c) 2009 Microsoft Corporation.  All rights reserved. 

C:\Users\Intel Atom>cd "c:\Beautiful Soup" 

c:\Beautiful Soup>c:\Python27\python setup.py install 

running install
running build
running build_py
error: package directory 'bs4' does not exist


c:\Beautiful Soup> 
--- 
I have made a note of all the contents of the downloaded and unzipped BS4,ie 
the contents of my Beautiful Soup folder on the C drive, which is as follows: 
--- 

running install 
running build 
running build_py 

error: package directory 'bs4' does not existinit 
_html5lib 
_htmlparser 
_lxml 
6.1 
AUTHORS 
conf 
COPYING 
dammit 
demonstration_markup 
element 
index.rst 
Makefile 
NEWS 
PGK-INFO 
README 
setup 
test_builder_registry 
test_docs 
test_html5lib 
test_htmlparser 
text_lxml 
test_soup 
test_tree 
testing 
TODO 

 
I can see no bs4 folder within the contents. 
 I can not see any setup.py file either, but this is how I downloaded it. 
I am only following instructions as suggested. 
I do not understand why it is not working. 
I hope someone can direct me in the right direction, as I seem to be stuck, and 
I don't think it has much bearing on my fluency or lack of it with Python. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-14 Thread Simon Evans
I downloaded the get-pip.py file. I installed it to the same folder on my C 
drive as the Beautiful Soup one in which the Beautiful Soup 4 downloads was 
unzipped to. I changed directory to the folder on the Command Prompt, as you 
instructed in step 2. I input the code to the console you gave on step 3), that 
returned some code, as quoted below. I then input the code you gave on step 4) 
but Console seems to reject or not recognise 'pip' as a term. I am sure quoting 
the actual prompt response can explain things better than I :
---
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.


C:\Users\Intel Atom>cd "c:\Beautiful Soup"

c:\Beautiful Soup>python get-pip.py
Downloading/unpacking pip from https://pypi.python.org/packages/py2.py3/p/pip/pi
p-1.5.5-py2.py3-none-any.whl#md5=03a932d6f82a3887d8de1cdb837c87ed
Installing collected packages: pip
  Found existing installation: pip 1.5.4
Uninstalling pip:
  Successfully uninstalled pip
Successfully installed pip
Cleaning up...

c:\Beautiful Soup>pip install beautifulsoup4
'pip' is not recognized as an internal or external command,
operable program or batch file.

c:\Beautiful Soup>

Perhaps I oughtn't have downloaded the pip file to the same directory as the 
Beautiful Soup ? I will have a try at transferring the file to another folder
and running the code you gave again. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-14 Thread Simon Evans
I have input the above code by copy and pasting to the Idle python console, as 
the python 2.7 command prompt is fussy about the indentation on the eleventh 
line down, if I then indent it, it replies that the indentation is unnecessary 
of unexpected, and if I don't it says an indentation is expected. 
However when I get to the next lines of code - in the Idle prompt re:

C:\Users\Intel Atom>cd "c:\Beautiful Soup"

c:\Beautiful Soup>c:\Python27\python setup.py install

Again it does not recognise 'bs4'. I think having used 'Just unzip it' instead 
of 'WinZip' may have caused this problem, in the first place ,as when I looked 
at the WinZip version at a local net café, it did have a folder hierarchy, 
however I wanted, and still want to skimp the £25 fee for WinZip, which 
nowadays you can't seem to be able to do. I never asked for the darn files to 
be zipped, so why ought I pay to have them unzipped, being my contention.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-15 Thread Simon Evans
Dear Programmers,
I downloaded Peazip, which doesn't remove file/ folder hierarchy. I unzipped it 
and input the same code to the console and it installed Beautiful Soup 4 okay 
re:- 
-
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Intel Atom>cd "c:\Beautiful Soup"

c:\Beautiful Soup>c:\Python27\python setup.py install
running install
running build
running build_py
creating build
creating build\lib
creating build\lib\bs4
copying bs4\dammit.py -> build\lib\bs4
copying bs4\element.py -> build\lib\bs4
copying bs4\testing.py -> build\lib\bs4
copying bs4\__init__.py -> build\lib\bs4
creating build\lib\bs4\builder
copying bs4\builder\_html5lib.py -> build\lib\bs4\builder
copying bs4\builder\_htmlparser.py -> build\lib\bs4\builder
copying bs4\builder\_lxml.py -> build\lib\bs4\builder
copying bs4\builder\__init__.py -> build\lib\bs4\builder
creating build\lib\bs4\tests
copying bs4\tests\test_builder_registry.py -> build\lib\bs4\tests
copying bs4\tests\test_docs.py -> build\lib\bs4\tests
copying bs4\tests\test_html5lib.py -> build\lib\bs4\tests
copying bs4\tests\test_htmlparser.py -> build\lib\bs4\tests
copying bs4\tests\test_lxml.py -> build\lib\bs4\tests
copying bs4\tests\test_soup.py -> build\lib\bs4\tests
copying bs4\tests\test_tree.py -> build\lib\bs4\tests
copying bs4\tests\__init__.py -> build\lib\bs4\tests
running install_lib
creating c:\Python27\Lib\site-packages\bs4
creating c:\Python27\Lib\site-packages\bs4\builder
copying build\lib\bs4\builder\_html5lib.py -> c:\Python27\Lib\site-packages\bs4\
builder
copying build\lib\bs4\builder\_htmlparser.py -> c:\Python27\Lib\site-packages\bs
4\builder
copying build\lib\bs4\builder\_lxml.py -> c:\Python27\Lib\site-packages\bs4\buil
der
copying build\lib\bs4\builder\__init__.py -> c:\Python27\Lib\site-packages\bs4\b
uilder
copying build\lib\bs4\dammit.py -> c:\Python27\Lib\site-packages\bs4
copying build\lib\bs4\element.py -> c:\Python27\Lib\site-packages\bs4
copying build\lib\bs4\testing.py -> c:\Python27\Lib\site-packages\bs4
creating c:\Python27\Lib\site-packages\bs4\tests
copying build\lib\bs4\tests\test_builder_registry.py -> c:\Python27\Lib\site-pac
kages\bs4\tests
copying build\lib\bs4\tests\test_docs.py -> c:\Python27\Lib\site-packages\bs4\te
sts
copying build\lib\bs4\tests\test_html5lib.py -> c:\Python27\Lib\site-packages\bs
4\tests
copying build\lib\bs4\tests\test_htmlparser.py -> c:\Python27\Lib\site-packages\
bs4\tests
copying build\lib\bs4\tests\test_lxml.py -> c:\Python27\Lib\site-packages\bs4\te
sts
copying build\lib\bs4\tests\test_soup.py -> c:\Python27\Lib\site-packages\bs4\te
sts
copying build\lib\bs4\tests\test_tree.py -> c:\Python27\Lib\site-packages\bs4\te
sts
copying build\lib\bs4\tests\__init__.py -> c:\Python27\Lib\site-packages\bs4\tes
ts
copying build\lib\bs4\__init__.py -> c:\Python27\Lib\site-packages\bs4
byte-compiling c:\Python27\Lib\site-packages\bs4\builder\_html5lib.py to _html5l
ib.pyc
byte-compiling c:\Python27\Lib\site-packages\bs4\builder\_htmlparser.py to _html
parser.pyc
byte-compiling c:\Python27\Lib\site-packages\bs4\builder\_lxml.py to _lxml.pyc
byte-compiling c:\Python27\Lib\site-packages\bs4\builder\__init__.py to __init__
.pyc
byte-compiling c:\Python27\Lib\site-packages\bs4\dammit.py to dammit.pyc
byte-compiling c:\Python27\Lib\site-packages\bs4\element.py to element.pyc
byte-compiling c:\Python27\Lib\site-packages\bs4\testing.py to testing.pyc
byte-compiling c:\Python27\Lib\site-packages\bs4\tests\test_builder_registry.py
to test_builder_registry.pyc
byte-compiling c:\Python27\Lib\site-packages\bs4\tests\test_docs.py to test_docs
.pyc
byte-compiling c:\Python27\Lib\site-packages\bs4\tests\test_html5lib.py to test_
html5lib.pyc
byte-compiling c:\Python27\Lib\site-packages\bs4\tests\test_htmlparser.py to tes
t_htmlparser.pyc
byte-compiling c:\Python27\Lib\site-packages\bs4\tests\test_lxml.py to test_lxml
.pyc
byte-compiling c:\Python27\Lib\site-packages\bs4\tests\test_soup.py to test_soup
.pyc
byte-compiling c:\Python27\Lib\site-packages\bs4\tests\test_tree.py to test_tree
.pyc
byte-compiling c:\Python27\Lib\site-packages\bs4\tests\__init__.py to __init__.p
yc
byte-compiling c:\Python27\Lib\site-packages\bs4\__init__.py to __init__.pyc
running install_egg_info
Writing c:\Python27\Lib\site-packages\beautifulsoup4-4.1.0-py2.7.egg-info

c:\Beautiful Soup>

Thank you for your thoughtful help, I am sure I will be needing more though, in 
the not too distant future. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-15 Thread Simon Evans


Dear Programmers,
As anticipated, it has not been to long before I have encountered further 

difficulty. At the top of page 16 of 'Getting Started with Beautiful Soup" it 

gives code to be input, whether to the Python or Windows command prompt I am 
not 

sure, but both seem to be resistant to it. I quote the response to the code 
below, 

the code input being :- 

helloworld = "Hello World"
soup_string = BeautifulSoup(helloworld)

to Windows Command prompt this gives :- 
--
SyntaxError: invalid syntax
>>> helloworld = "HelloWorld"
>>> soup_string = BeautifulSoup(helloworld)
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'BeautifulSoup' is not defined
--
I have been told by one of the programmers, that I ought be inputting this to 
the 

Python command prompt (the book doesn't spacify), but that doesn't take either 

re:-
--
>>>helloworld = HelloWorld"
>>>soup_string = BeautifulSoup(helloworld)
Traceback (most recent call last):
File "", line 1, in 
NameError: name 'BeautifulSoup' is not defined
>>>
--
Looking at the bottom of page 16, there is more code for the inputting of, that 

again does not take to the Windows Command Prompt or the Python command prompt,
re:  import urllib2
 from bs4 import BeautifulSoup
 url = "http://www.packtpub.com/books";
 page = urllib2.urlopen(url)
 soup_packtpage = BeautifulSoup(page)

returns to the Windows Command prompt:- 
--
>>>import urllib2
Traceback (most recent call last):
  File "", line1, in 
ImportError: No module named 'urllib2'
>>>

--
returns to the Python command prompt :- 
--
>>> import urllib2
>>> from bs4 import BeautifulSoup
>>> url = "http://www.packtpub.com/books";
>>> page = urllib2.urlopen(url)
Traceback (most recent call last):
File "C\Python27\lib\urllib2.py",line 127, in urlopen
  return_opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py",line 410, in open
response = meth(req, response)
File "C:\Pyton27\lib\urllib2.py", oine 523, in http_response
'http', request, response, code, msg, hdrs)
File"C:\Python27\lib\urllib2.py", line 448, in error
return self._call_chain(*args)
File "C:/Python27/lib/urllib2.py",line 382, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, masg, hdrs, fp)
urllib2.HTTPError: HTTP Error 403: Forbidden
-
Anway I hope you can tell me what is amiss, there is no point in my proceeding 

with the book (about 111 pages all told) until I find out why it won't take. 
I realise I have been told to learn python in order to make things less 
painful, 

but I don't see why code written in the book does not take. 
Thank you for reading.





I thought I might as well include, so's you might be able to see where things 
are 

going astray. The Windows command prompt :- 



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


Re: How do I access 'Beautiful Soup' on python 2.7 or 3.4 , console or idle versions.

2014-05-15 Thread Simon Evans
Dear Programmers, I noticed a couple of typos in my previous message, so have 
now altered them thus :- 

Dear Programmers,
As anticipated, it has not been to long before I have encountered further 

difficulty. At the top of page 16 of 'Getting Started with Beautiful Soup" it 

gives code to be input, whether to the Python or Windows command prompt I am 
not 

sure, but both seem to be resistant to it. I quote the response to the code 
below, 

the code input being :- 

helloworld = "Hello World"
soup_string = BeautifulSoup(helloworld)

to Windows Command prompt this gives :- 
--
SyntaxError: invalid syntax
>>> helloworld = "HelloWorld"
>>> soup_string = BeautifulSoup(helloworld)
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'BeautifulSoup' is not defined
--
I have been told by one of the programmers, that I ought be inputting this to 
the 

Python command prompt (the book doesn't spacify), but that doesn't take either 

re:-
--
>>>helloworld = HelloWorld"
>>>soup_string = BeautifulSoup(helloworld)
Traceback (most recent call last):
File "", line 1, in 
NameError: name 'BeautifulSoup' is not defined
>>>
--
Looking at the bottom of page 16, there is more code for the inputting of, that 

again does not take to the Windows Command Prompt or the Python command prompt,
re:  import urllib2
 from bs4 import BeautifulSoup
 url = "http://www.packtpub.com/books";
 page = urllib2.urlopen(url)
 soup_packtpage = BeautifulSoup(page)

returns to the Windows Command prompt:- 
--
>>>import urllib2
Traceback (most recent call last):
  File "", line1, in 
ImportError: No module named 'urllib2'
>>>

--
returns to the Python command prompt :- 
--
>>> import urllib2
>>> from bs4 import BeautifulSoup
>>> url = "http://www.packtpub.com/books";
>>> page = urllib2.urlopen(url)
Traceback (most recent call last):
File "C\Python27\lib\urllib2.py",line 127, in urlopen
  return_opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py",line 410, in open
response = meth(req, response)
File "C:\Python27\lib\urllib2.py", oine 523, in http_response
'http', request, response, code, msg, hdrs)
File"C:\Python27\lib\urllib2.py", line 448, in error
return self._call_chain(*args)
File "C:/Python27/lib/urllib2.py",line 382, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, masg, hdrs, fp)
urllib2.HTTPError: HTTP Error 403: Forbidden
-
Anway I hope you can tell me what is amiss, there is no point in my proceeding 

with the book (about 111 pages all told) until I find out why it won't take. 
I realise I have been told to learn python in order to make things less 
painful, 

but I don't see why code written in the book does not take. 
Thank you for reading.








 


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


Re: Is it possible to deliver different source distributions for different Python versions?

2015-04-06 Thread Dylan Evans
> I would like to distribute a python package with different code for 
> Python 2.* than for Python 3.*. (Mostly this is because of different 
> unicode string handling). 

> There is nothing in to setuptools or PyPi that directly supports 
> this scenario. 
The 2to3 utility will handle the unicode differences. You can set the keyword 
argument use_2to3 to True in setup.py dependent on the version number like so:



extra = {}

if sys.version_info >= (3, ):

    extra['use_2to3'] = True



and then put **extra in setup.py. This will run 2to3 on the code when it 
installs it. I don’t know whether this is good style but it does work. I got it 
from the feedparser source code. 


-- 
Dylan Evans

On 6 April 2015 at 11:05:47, python-list-requ...@python.org 
(python-list-requ...@python.org) wrote:

Send Python-list mailing list submissions to  
python-list@python.org  

To subscribe or unsubscribe via the World Wide Web, visit  
https://mail.python.org/mailman/listinfo/python-list  
or, via email, send a message with subject or body 'help' to  
python-list-requ...@python.org  

You can reach the person managing the list at  
python-list-ow...@python.org  

When replying, please edit your Subject line so it is more specific  
than "Re: Contents of Python-list digest..."  
Today's Topics:  

1. Permission denied when opening a file that was created  
concurrently by os.rename (Windows) (Alexey Izbyshev)  
2. Re: Permission denied when opening a file that was created  
concurrently by os.rename (Windows) (Chris Angelico)  
3. Re: Permission denied when opening a file that was created  
concurrently by os.rename (Windows) (Alexey Izbyshev)  
4. Re: Permission denied when opening a file that was created  
concurrently by os.rename (Windows) (Dave Angel)  
5. Help with pipes, buffering and pseudoterminals (Daniel Ellis)  
6. Re: Permission denied when opening a file that was created  
concurrently by os.rename (Windows) (Terry Reedy)  
7. Is it possible to deliver different source distributions for  
different Python versions? (Dave Hein)  
8. ANN: polynice 0.7 - a nice(1) like utility for throttling  
processes (garabik-news-2005...@kassiopeia.juls.savba.sk)  
9. Re: Help with pipes, buffering and pseudoterminals (Nobody)  
10. Re: Help with pipes, buffering and pseudoterminals  
(Cameron Simpson)  
11. Re: Is it possible to deliver different source distributions  
for different Python versions? (Steven D'Aprano)  
12. XML Parsing (Sepideh Ghanavati)  
13. Re: XML Parsing (Ben Finney)  
14. Re: Is it possible to deliver different source distributions  
for different Python versions? (Mark Lawrence)  
15. Re: Is it possible to deliver different source distributions  
for different Python versions? (Stefan Behnel)  
16. Re: XML Parsing (Stefan Behnel)  
17. Re: OOP for System Administrator (pankaj sharma)  
18. implementing pyshark (Michael S.)  
Hello!  

I've hit a strange problem that I reduced to the following test case:  
* Run several python processes in parallel that spin in the following  
loop:  
while True:  
if os.path.isfile(fname):  
with open(fname, 'rb') as f:  
f.read()  
break  
* Then, run another process that creates a temporary file and then  
renames it to the name than other processes are expecting  
* Now, some of the reading processes occasionally fail with "Permission  
denied" OSError  

I was able to reproduce it on two Windows 7 64-bit machines. It seems  
when the file appears on the filesystem it is still unavailable to  
reading, but I have no idea how it can happen. Both source and  
destination files are in the same directory, and the destination doesn't  
exist before calling os.rename. Everything I could find indicates that  
os.rename should be atomic under this conditions even on Windows, so  
nobody should be able to observe the destination in unaccessible state.  

I know that I can workaround this problem by removing useless  
os.path.isfile() check and wrapping open() with try-except, but I'd like  
to know the root cause of the problem. Please share you thoughts.  

The test case is attached, the main file is test.bat. Python is  
expected to be in PATH. Stderr of readers is redirected to *.log. You  
may need to run several times to hit the issue.  

Alexey Izbyshev,  
research assistant,  
ISP RAS  


On Mon, Apr 6, 2015 at 3:45 AM, Alexey Izbyshev  wrote:  
> The test case is attached, the main file is test.bat. Python is expected to  
> be in PATH. Stderr of readers is redirected to *.log. You may need to run  
> several times to hit the issue.  

You have an interesting-looking problem, but the attachment didn't  
arrive. Is it short enough to include in-line as text in your email?  

ChrisA  

On 2015-04-05 20:45, Alexey Izbyshev wrote:  
> Hello!  
>  
> I've hit a strange problem that I reduced to the follow

Re: Python-list Digest, Vol 139, Issue 7

2015-04-06 Thread Dylan Evans
On Mon, Apr 6, 2015 at 5:52 AM, Steven D’Aprano  wrote:
> I understand that Gmail is a pig about these sorts of things, and makes it
> really hard to avoid breaking list etiquette. We appreciate whatever you
> can do, and while a few of us may bark occasionally, we don't bite.

Oh my days, I’m really sorry about that! It didn’t cross my mind that I was 
using the rich text composer, and I cursed myself for leaving the whole email 
on the end.

I use an email client called Airmail, so I’ve just set plain text as the 
default. It shouldn’t affect me at all.

Thank you for being understanding and my apologies once again. I hope my 
attempt at help was at least readable.

(Also sorry if I’m committing another faux pas by clogging up the list but I 
had to apologise!)

—

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


Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ?

2015-07-11 Thread Simon Evans
Dear Programmers, 
Thank you for your advice regarding giving the console a current address in the 
code for it to access the html file. 

The console seems to accept the code to that extent, but when I input the two 
lines of code intended to access the location of a required word, the console 
rejects it re :

AttributeError:'NoneType' object has no attribute 'li' 

However the document 'EcologicalPyramid.html' does contain the words 'li' and 
'ul', in its text. I am not sure as to how the input is arranged to output 
'plants' which is also in the documents text, but that is the word the code is 
meant to elicit. 

I enclose the pertinent code as input and output from the console, and the html 
code for the document 'EcologicalPyramid.html'

Thank you in advance for your help. 

-
>>> with open("C:\Beautiful Soup\ecologicalpyramid.html","r") as 
>>> ecological_pyramid:
soup = BeautifulSoup("C:\Beautiful Soup\ecological_pyramid.html","lxml")
... producer_entries = soup.find("ul")
  File "", line 2
producer_entries = soup.find("ul")
   ^
SyntaxError: invalid syntax
>>> producer_entries = soup.find("ul")
>>> print (producer_entries.li.div.string)
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'NoneType' object has no attribute 'li'
--
prin





plants
10


algae
10




deer
1000

deer
1000


rabbit
2000




fox
100


bear
100




lion
80


tiger
50




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


Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ?

2015-07-12 Thread Simon Evans
Dear Mark Lawrence, thank you for your advice. 
I take it that I use the input you suggest for the line :

soup = BeautifulSoup("C:\Beautiful Soup\ecological_pyramid.html",lxml")

seeing as I have to give the file's full address I therefore have to modify 
your :

soup = BeautifulSoup(ecological_pyramid,"lxml")

to :

soup = BeautifulSoup("C:\Beautiful Soup\ecological_pyramid," "lxml")

otherwise I get :


>>> with open("C:\Beautiful Soup\ecologicalpyramid.html"."r")as 
>>> ecological_pyramid:
>>> soup = BeautifulSoup(ecological_pyramid,"lxml")
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'ecological_pyramid' is not defined


so anyway with the input therefore as:

>>> with open("C:\Beautiful Soup\ecologicalpyramid.html"."r")as 
>>> ecological_pyramid: 
>>> soup = BeautifulSoup("C:\Beautiful Soup\ecological_pyramid,","lxml")
>>> producer_entries = soup.find("ul")
>>> print(producer_entries.li.div.string)

I still get the following output from the console:

Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'NoneType' object has no attribute 'li'
>>>

As is probably evident, what is the problem Python has with finding the 
required html code within the 'ecologicalpyramid' html file, or more 
specifically why does it respond that the html file has no such attribute as 
'li' ?
Incidentally I have installed all the xml, lxml, html, and html5 TreeBuilders/ 
Parsers. I am using lxml as that is the format specified in the text. 

I may as well quote the text on the page in question in 'Getting Started with 
Beautiful Soup':

'Since producers come as the first entry for the tag, we can use the find() 
method, which normally searches fo ronly the first occurrance of a particular 
tag in a BeautifulSoup object. We store this in producer_entries. The next line 
prints the name of the first producer. From the previous HTML diagram we can 
understand that the first producer is stored inside the first  tag of the 
first  tag that immediately follows the first  tag , as shown inthe 
following code: 



plants
10



So after running the preceding code, we will get plants, which is the first 
producer, as the output.'

(page 30)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ?

2015-07-12 Thread Simon Evans
Dear Peter Otten, thank you for your reply that I have not gone very far into 
the detail of which, as it seems Python console cannot recognise the name 'f' 
as given it, re output below :


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("C:\Beautiful Soup\ecologicalpyramid.html","r")as f:
>>> soup = BeautifulSoup(f, "lxml")
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'f' is not defined
>>>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ?

2015-07-12 Thread Simon Evans
Dear Peter Otten,
Incidentally, you have discovered a fault in that there is an erroneous 
difference in my code of 'ecologicalpyramid.html' and that given in the text, 
in the first few lines re: 

 
 
 
 
 
 
plants 
10 
 
 
algae 
10 
 
 






plants
10


algae
10



I have removed the line  to the right html code of the 
lower 

version. Now there is a string ("plants") between the <"li class producerlist"> 
and 
Sorry about that.
However as you said, the input code as quoted in the text, still won't return 
'plants' 

re:

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
>>> soup = BeautifulSoup("C:\Beautiful Soup\ecological_pyramid,","lxml")
>>> producer_entries = soup.find("ul")
>>> print(producer_entries.li.div.string)
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'NoneType' object has no attribute 'li'
>>> 

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


Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ?

2015-07-12 Thread Simon Evans
Dear Peter Otten, 
Yes, I have been copying and pasting, as it saves typing. I do get 'indented 
block' error responses as a small price to pay for the time and energy thus 
saved. Also Console seems to reject for 'indented block' reasons better known 
to itself, copy and pasted lines that it accepts and  are exactly the same on 
the following line of input. Maybe it is an inbuilt feature of Python's to 
discourage copy and pasting.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ?

2015-07-12 Thread Simon Evans

Dear Peter Otten, 
I typed in (and did not copy and paste) the code as you suggested just now 
(6.28 pm, Sunday 12th July 2015), this is the result I got: 

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("C:\Beautiful Soup\ecologicalpyramid.html","r")as f:
... soup = BeautifulSoup(f,"lxml")
  File "", line 2
soup = BeautifulSoup(f,"lxml")
   ^
IndentationError: expected an indented block
>>> soup = BeautifulSoup(f,"lxml")
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'f' is not defined
>>>

The first time I typed in the second line, I got the 
"Indentation error" 
the second time I typed in exactly the same code, I got the: 
"NameError:name 'f' is not defined"
-- 
https://mail.python.org/mailman/listinfo/python-list


Suitable Python code to scrape specific details from web pages.

2014-08-12 Thread Simon Evans
Dear Programmers,
I have been looking at the You tube 'Web Scraping Tutorials' of Chris Reeves. I 
have tried a few of his python programs in the Python27 command prompt, but 
altered them from accessing data using links say from the Dow Jones index, to 
accessing the details I would be interested in accessing from the 'Racing Post' 
on a daily basis. Anyhow, the code it returns is not in the example I am going 
to give, is not the information I am seeking, instead of returning the given 
odds on a horse, it only returns a [], which isn't much use. 
I would be glad if you could tell me where I am going wrong. 
Yours faithfully
Simon Evans.

>>>import urllib
>>>import re
>>>htmlfile = urllib.urlopen("http://www.racingpost.com/horses2/cards/card.sd?

race_id=600048r_date=2014-05-08#raceTabs=sc_")
htmltext = htmlfile.read()
regex = '1http://www.racingpost.com/horses/horse_home.sd?

horse_id=758752"onclick="scorecards.send("horse_name":):return 
Html.popup(this,

{width:695,height:800})"title="Full details about this HORSE">Lively 

Baron9/4F'
>>>pattern = re.compile(regex)
>>>odds=re.findall(pattern,htmltext)
>>>print odds
[]
>>>

>>>import urllib
>>>import re
>>>htmlfile = urllib.urlopen("http://www.racingpost.com/horses2/cards/card.sd?

>>>race_id=600048r_date=2014-05-08#raceTabs=sc_")
>>>htmltext = htmlfile.read()
>>>regex = ''
>>>pattern = re.compile(regex)
>>>odds=re.findall(pattern,htmltext)
>>>print odds
[]
>>>
---
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suitable Python code to scrape specific details from web pages.

2014-08-12 Thread Simon Evans
On Tuesday, August 12, 2014 9:00:30 PM UTC+1, Simon Evans wrote:
> Dear Programmers,
> 
> I have been looking at the You tube 'Web Scraping Tutorials' of Chris Reeves. 
> I have tried a few of his python programs in the Python27 command prompt, but 
> altered them from accessing data using links say from the Dow Jones index, to 
> accessing the details I would be interested in accessing from the 'Racing 
> Post' on a daily basis. Anyhow, the code it returns is not in the example I 
> am going to give, is not the information I am seeking, instead of returning 
> the given odds on a horse, it only returns a [], which isn't much use. 
> 
> I would be glad if you could tell me where I am going wrong. 
> 
> Yours faithfully
> 
> Simon Evans.
> 
> 
> 
> >>>import urllib
> 
> >>>import re
> 
> >>>htmlfile = urllib.urlopen("http://www.racingpost.com/horses2/cards/card.sd?
> 
> 
> 
> race_id=600048r_date=2014-05-08#raceTabs=sc_")
> 
> htmltext = htmlfile.read()
> 
> regex = '1http://www.racingpost.com/horses/horse_home.sd?
> 
> 
> 
> horse_id=758752"onclick="scorecards.send("horse_name":):return 
> Html.popup(this,
> 
> 
> 
> {width:695,height:800})"title="Full details about this HORSE">Lively 
> 
> 
> 
> Baron9/4F'
> 
> >>>pattern = re.compile(regex)
> 
> >>>odds=re.findall(pattern,htmltext)
> 
> >>>print odds
> 
> []
> 
> >>>
> 
> 
> 
> >>>import urllib
> 
> >>>import re
> 
> >>>htmlfile = urllib.urlopen("http://www.racingpost.com/horses2/cards/card.sd?
> 
> 
> 
> >>>race_id=600048r_date=2014-05-08#raceTabs=sc_")
> 
> >>>htmltext = htmlfile.read()
> 
> >>>regex = ''
> 
> >>>pattern = re.compile(regex)
> 
> >>>odds=re.findall(pattern,htmltext)
> 
> >>>print odds
> 
> []
> 
> >>>
> 
> ---
Dear Programmers, Thank you for your responses. I have installed 'Beautiful 
Soup' and I have the 'Getting Started in Beautiful Soup' book, but can't seem 
to make  any progress with it, I am too thick to make much use of it. I was 
hoping I could scrape specified stuff off Web pages without using it. I have 
installed 'Requests' also, is there any code I can use that you can suggest 
that can access the sort of Web page values that I have referred to ?  such as 
odds, names of runners, stuff like that off the 'inspect element' or 'source' 
htaml pages, on www.Racingpost.com. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Code to Python 27 prompt to access a html file stored on C drive

2014-08-14 Thread Simon Evans
Dear Programmers,  I want to access a html file on my C drive, in the 

Python 27 prompt, all the examples I come across seem to require for 

access for the html file be on a server, rather than on the same 

computer's C drive. I want to do this as a prerequisite to writing 

webscraping code,  surmising that if I can get the Python 27 

prompt (inclusive of 'Beautiful Soup''Urllib' 'Requests' downloads ) to 

output pertinent html code from a html document, then I can proceed to use 

similar code to ouput html code from URL addresses, such as 

'RacingPost.com' 'SportingLife.com''Oddschecker.com' and 

'Bestbetting.com' which is what I am interested in working on.

Hope you can help. 

Yours Simon Evans.
-- 
https://mail.python.org/mailman/listinfo/python-list


Dynamically Cause A Function To Return

2011-09-19 Thread Jordan Evans
I want dynamically place the 'return' statement in a function via user input
or achieve the same through some other means.  If some other means, the user
must be able initiate this at runtime during a raw_input().  This is what I
have so far, this would be an awesome command line debugging tool if I can
get it to work.

def b(label="", *args):
"""Used to create breaks for debugging.  Will break the function or
continue the function it is place within based on user input.  Has as a
input loop for querying variables and executing code before a break or a
continue."""
print label+":",
for arg in args:
print str(arg),
if len(args):
print
x = ""
while x != ".":
command = raw_input()
try:
exec command
except:
pass
-- 
http://mail.python.org/mailman/listinfo/python-list


Announcing Mii (My) Chat

2011-11-19 Thread Andrew Evans
Hello I wish to inform the list of a Python Application I am writing
entitled Mii Chat.

What is Mii Chat you ask? It is an IP to IP or IP to Multiple IP
text/voice/video chat client written in Python

Currently the GUI is written in PyQT and could use a complete overhaul (in
progress)

There are a few bugs: Like I couldn't figure out the Threading for the
Video so I am using QTimer.

and the Audio could be improved. But overall it works as expected! I am
happy about it cause I am not the best programmer. I have never been to
school for Comp Science Programming or any university/college for that
matter. I am self taught and consider myself a hobbyist programmer.

It would be great if some one could suggest a library for TCP Nat Traversal.

As  well I am open to any and all suggestions! I appreciate any feedback
*cheers

Andrew Evans

Here is the link

http://code.google.com/p/mii-chat/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: error in except

2013-02-04 Thread John Evans
Should it not be "try-except-else' instead of 'if-except-else'?

try:
if delay > 2.0:
raise RuntimeError('I think the server is down')
except:
raise
else:
break


On Mon, Feb 4, 2013 at 5:21 PM, Steven D'Aprano <
steve+comp.lang.pyt...@pearwood.info> wrote:

> Rodrick Brown wrote:
>
> > For the life of me I cant figure out why this exception is being thrown.
> > How could I use pdb to debug this?
> >
> > $ python udp_local2.py server
> >   File "udp_local2.py", line 36
> > except:
> >  ^
> > SyntaxError: invalid syntax
>
> You can't use pdb to debug it, because you can't run the code until you fix
> the syntax error. You use your text editor to debug it.
>
> Sometimes if you have a missing bracket (round, square or curly), Python
> reports the syntax error on the line *after* where it expected the closing
> bracket.
>
> I've also seen unexpected syntax errors if the source code contains binary
> characters such as DOS end-of-file ^Z. Try opening the file in a hex editor
> and looking for anything that shouldn't be there.
>
> But the most likely problem is that you are mixing tabs and spaces, and
> consequently have inadvertently become confused about the indent level. You
> think that the "except" clause is indented level with a try, but it
> actually is indented level with something else. Using spaces for indents is
> good; using tabs for indents is also good; using both at the same time is a
> nightmare. (Python 3 prohibits this.)
>
> I recommend running TabNanny over the file:
>
> python -m tabnanny 
>
>
> A couple of comments on your code:
>
> > try:
> > data = s.recv(MAX)
> > except socket.timeout:
> > delay *= 2
> > if delay > 2.0:
> > raise RuntimeError('I think the server is down')
>
> Five attempts and a total of 3.1 seconds (0.1 + 0.2 + 0.4 + 0.8 + 1.6) is
> rather short to conclude that a server is down, although it depends on what
> sort of server and where it is. I would have thought 30 seconds is more
> appropriate. (By default, wget doesn't time out for 3 minutes, which is
> possibly overkill.)
>
> But either way, I don't think RuntimeError is the right exception to use. I
> expect that a socket error would be more relevant.
>
> > except:
> > raise
>
> What this does is:
>
> "Unconditionally catch anything. Then raise it again."
>
> Don't do this. The right thing to do here is, just delete it and don't
> catch
> it at all.
>
>
>
>
> --
> Steven
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



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


Re: HTTPserver: how to access variables of a higher class?

2013-04-05 Thread Dylan Evans
On 05/04/2013 9:09 PM, "Tom P"  wrote:
>
> First, here's a sample test program:
> 
> import sys
> from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
>
> class MyRequestHandler(BaseHTTPRequestHandler, object):
> def do_GET(self):
> top_self = super(MyRequestHandler, self) # try to access
MyWebServer instance
> self.send_response(200)
> self.send_header('Content-type','text/html')
> self.end_headers()
> self.wfile.write("thanks for trying, but I'd like to get at
self.foo and self.bar")
> return
>
> class MyWebServer(object):
> def __init__(self):
> self.foo = "foo"  # these are what I want to access from inside
do_GET
> self.bar = "bar"
> self.httpd = HTTPServer(('127.0.0.1', 8000), MyRequestHandler)
> sa = self.httpd.socket.getsockname()
> print "Serving HTTP on", sa[0], "port", sa[1], "..."
>
> def runIt(self):
> self.httpd.serve_forever()
>
> server = MyWebServer()
> server.runIt()
>
> 
>
> I want to access the foo and bar variables from do_GET, but I can't
figure out how. I suppose this is something to do with new-style vs.
old-style classes, but I lost for a solution.

Consider inheriting HTTPServer in MyWebServer which is passed to the
request handler.

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


Re: Run python script with ./

2013-04-05 Thread Dylan Evans
On Sat, Apr 6, 2013 at 1:04 AM, LubanWorks  wrote:
>
>
>
> My question is:
>
> Why  when I use #!/home/luban/Linux/Python/2.7.3/bin/python at the
> beginning of myscript.py, *./*myscript.py can work,
>
> but if I use the wrapper #!/home/luban/bin/python in my python script, use
> *./*  to run the script, it cannot not work?
>

Your shell will be trying to run your python script. The reason being that
when you do #!/bin/sh in the wrapper the shell tries to execute $0 which in
this case is the name of your python script.


>
>
> I had many scripts used #!/home/luban/bin/python when I only installed
> python  under #!/home/luban/ for Linux, they can run with ./, I don't want
> to change them,
>
> so, how to let ./ run the python script If I want to *KEEP* wrapper
> #!/home/luban/bin/python as the shebang line?
>
>
Probably easier to use a symlink, or just use #!python and adjust your
$PATH.


>
> Best Regards,
> Luban
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
"The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trying to understand working with dicts

2013-04-05 Thread Dylan Evans
On Fri, Apr 5, 2013 at 10:34 PM, inshu chauhan wrote:

> Hello everyone,
>
> Here in my part of the code where cc is a dictionary. I want to understand
> what actually cc.iterkeys() and cc[k] actually doing.
> I am already reading
> http://docs.python.org/2/library/stdtypes.html#dict.items
> and http://www.tutorialspoint.com/python/python_dictionary.htm but still
> not very clear.
>
> cc = Computesegclass(segimage, refimage)
> for k in sorted(cc.iterkeys()):
> i = argmax(cc[k])
> print >> f, i+1
>
>
Not sure what Computesegclass is but i am guessing that it is a class which
implements __getitem__ and __setitem__, which allows the use of the square
bracket notation cc[k], you could also write cc.__getitem__(k) , if you
really wanted to.
See http://docs.python.org/2/reference/datamodel.html#object.__getitem__

iterkeys returns an iterator over the dictionary keys, which is an object
with a next method which returns each key in the dictionary until there are
no more, then it raises StopIteration.


> Thanks in Advance
>
>
--
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
"The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I hate you all

2013-04-05 Thread Dylan Evans
On Sat, Apr 6, 2013 at 7:41 AM,  wrote:

> Hello
>
> I just tried python 3.3 with some simple script meant for unit test.
>
> How can python authors be so arrogant to impose their tabs and spaces
> options on me ? It should be my choice if I want to use tabs or not !
>
>
Don't like it? Use ruby.



> I know people have all goten into this frenzy of using either tabs, either
> spaces for indentation, but using a hard-tab of 8 spaces and a soft tab of
> 4 spaces has worked fine long before python 3 showed up.
>
> And if they decided to throw a TabError, they should have at least created
> an option to specify tab size, so I can work around that.
>
> I am aware that so many editors use a tab stop of 4 spaces instead of 8
> (which by the way started as a cheap way to work around their initial lack
> of a "soft tab stop" option, and then was kept at 4 for "compatibility").
> But the rest of us who always use a tab stop of 8 should not be forced to
> change preferences because python reached version 3.
>
> Timothy Madden
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
"The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HTTPserver: how to access variables of a higher class?

2013-04-06 Thread Dylan Evans
On Sun, Apr 7, 2013 at 1:05 AM, Tom P  wrote:

> On 04/05/2013 02:27 PM, Dylan Evans wrote:
>
>> On 05/04/2013 9:09 PM, "Tom P"  wrote:
>>
>>>
>>> First, here's a sample test program:
>>> 
>>> import sys
>>> from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
>>>
>>> class MyRequestHandler(**BaseHTTPRequestHandler, object):
>>>  def do_GET(self):
>>>  top_self = super(MyRequestHandler, self) # try to access
>>>
>> MyWebServer instance
>>
>>>  self.send_response(200)
>>>  self.send_header('Content-**type','text/html')
>>>  self.end_headers()
>>>  self.wfile.write("thanks for trying, but I'd like to get at
>>>
>> self.foo and self.bar")
>>
>>>  return
>>>
>>> class MyWebServer(object):
>>>  def __init__(self):
>>>  self.foo = "foo"  # these are what I want to access from inside
>>>
>> do_GET
>>
>>>  self.bar = "bar"
>>>  self.httpd = HTTPServer(('127.0.0.1', 8000), MyRequestHandler)
>>>  sa = self.httpd.socket.getsockname(**)
>>>  print "Serving HTTP on", sa[0], "port", sa[1], "..."
>>>
>>>  def runIt(self):
>>>  self.httpd.serve_forever()
>>>
>>> server = MyWebServer()
>>> server.runIt()
>>>
>>> 
>>>
>>> I want to access the foo and bar variables from do_GET, but I can't
>>>
>> figure out how. I suppose this is something to do with new-style vs.
>> old-style classes, but I lost for a solution.
>>
>> Consider inheriting HTTPServer in MyWebServer which is passed to the
>> request handler.
>>
>>  --
>>> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>>>
>>
>>
> I keep getting the same problem - if inherit from any of these classes in
> BaseHTTPServer and try to use super(class, self) to initiate the higher
> class, I get the error "TypeError: must be type, not classobj" - in other
> words, these are old-style classes.
> That means that in this call -
> self.httpd = MyHTTPServer(('127.0.0.1', 8000), MyRequestHandler)
>
> there doesn't seem to be a way to define a
>  class MyHTTPServer(HTTPServer)
>
>
>
You can call the __init__ method on the class as a workaround for it being
old style. This works on 2.7


from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler

class MyRequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write('Got foo? %s' % self.server.foo)


class MyWebServer(HTTPServer):
def __init__(self):
self.foo = 'foo'
HTTPServer.__init__(self, ('127.0.0.1', 8000), MyRequestHandler)
sa = self.socket.getsockname()
print "Serving HTTP on", sa[0], "port", sa[1]

def runit(self):
self.serve_forever()

server = MyWebServer()
server.runit()


>
>
>
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>



-- 
"The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I hate you all

2013-04-06 Thread Dylan Evans
Then you see my point, unless you are being told what to use by a boss then
there are plenty of other languages you can choose from. Python is rigid
about it's format, that's just what it is and a lot of people like it but
if it's not your thing then some other language will probably suit you
better. However, if you are working for a company, or OSS project, you are
probably going to have your style dictated whatever language you use, for
example the 2 space indents (*shudder*) that google uses in c++
http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Spaces_vs._Tabs#Spaces_vs._Tabs
(Interestingly
google use 4 space indents in python for compatibility with PEP-8
http://google-styleguide.googlecode.com/svn/trunk/pyguide.html?showone=Indentation#Indentation
)

You probably won't like everything in a project style but it's not about
being tyrannical, and it's not a bad thing to have restrictions at the
language level.

I work for a company with a load of lagacy c formatted as follows:

int many_many_globals;
int func(int iFoo,int iBar)
{
int var = 10;
if(iBar>1)
{
var=iFoo+many_many_globals;
}
return var;
}

So i am pretty happy to adopt a language which defines a sane style.

This is a nice flame war you have stirred up.



On Sat, Apr 6, 2013 at 3:13 PM,  wrote:

> On Saturday, April 6, 2013 7:28:55 AM UTC+3, Dylan Evans wrote:
> > On Sat, Apr 6, 2013 at 7:41 AM,   wrote:
> >
> > Hello
> >
> >
> > I just tried python 3.3 with some simple script meant for unit test.
> >
> > How can python authors be so arrogant to impose their tabs and spaces
> options on me ? It should be my choice if I want to use tabs or not !
> >
> >
> > Don't like it? Use ruby.
>
>
> Actually next on my list is perl. I know ruby is sexy, but taming the wild
> beast is what makes me feel like the real cowboy.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
"The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: parse the file

2013-04-07 Thread Dylan Evans
You can read the fantastic manual at
http://docs.python.org/2/library/xml.etree.elementtree.html or i'm sure
someone will do it for a modest fee.


On Sat, Apr 6, 2013 at 3:11 PM, 水静流深 <1248283...@qq.com> wrote:

> I have an xml file . http://s.yunio.com/bmCS5h
>
> It is the list of my files in Google-blogger, how can I parse it in python
> to get every article?please give me the right code,which can get exact
> result.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
"The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess question re waiting

2013-04-08 Thread Dylan Evans
On Mon, Apr 8, 2013 at 9:48 PM, Alain Ketterlin  wrote:

> loial  writes:
>
> > I want to call a child process to run a shell script and wait for that
> > script to finish. Will the code below wait for the script to finish?
> > If not then how do I make it wait?
> [...]
> > process = subprocess.Popen(command,
> stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE,
> close_fds=True, shell=True)
>
> process.wait()
>

Or use subprocess.call instead which does what you want.


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



-- 
"The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can anyone please help me in resolving the error => AttributeError: Array instance has no attribute '__trunc__'

2013-04-08 Thread Dylan Evans
On Mon, Apr 8, 2013 at 8:07 PM,  wrote:

> I am trying to create 2D arrays without using advanced features like
> numpy, for this I have created 2 separate modules arrays.py and array2D.py.
> Here's the code for that:
>
> arrays.py module:
> ==
> import ctypes
>
> class Array:
>
> #Creates an array with size elements.
> def __init__( self, size ):
> assert size > 0, "Array size must be > 0"
> self._size = size
> print "sixe is %s" %self._size
>
>  # Create the array structure using the ctypes module.
> PyArrayType = ctypes.c_int * size
> self._elements = PyArrayType()
> print "type is e", type(self._elements)
> #self._elements = ctypes.c_int * size
>
> print "Elements are self.element %s" % self._elements
> # Initialize each element.
> #for i in range(self._size):
> #   self.clear( i )
>
>
> # Returns the size of the array.
> def __len__( self ):
> return self._size
>
> # Gets the contents of the index element.
> def __getitem__( self, index ):
> assert index >= 0 and index < len(self), "Array subscript out of
> range"
> return self._elements[ index ]
>
> # Puts the value in the array element at index position.
> def __setitem__( self, index, value ):
> assert index >= 0 and index < len(self), "Array subscript out of
> range"
> print "Type is ", type(index)
> self._elements[ index ] = value
>
> # Clears the array by setting each element to the given value.
> def clear( self, value ):
> for i in range( len(self) ) :
> self._elements[i] = value
>
> # Printing the arrays:
> def __str__(self):
> return self._elements
>
>
>
> array2D.py module
> ==
>
>
> import arrays
>
> class Array2D :
> # Creates a 2-D array of size numRows x numCols.
> def __init__( self, numRows, numCols ):
> # Create a 1-D array to store an array reference for each row.
>
> self._theRows = arrays.Array( numRows )
> # Create the 1-D arrays for each row of the 2-D array.
> print "Num of Cloumns is", numCols
>
> for i in range( numRows ) :
> self._theRows[i] = arrays.Array( numCols )
>
> # Returns the number of rows in the 2-D array.
> def numRows( self ):
> return len( self._theRows )
>
> # Returns the number of columns in the 2-D array.
> def numCols( self ):
> return len( self._theRows[0] )
>
> # Clears the array by setting every element to the given value.
> def clear( self, value ):
> for row in range( self.numRows() ):
> row.clear( value )
>
> # Gets the contents of the element at position [i, j]
> def __getitem__( self, ndxTuple ):
> assert len(ndxTuple) == 2, "Invalid number of array subscripts."
> row = ndxTuple[0]
> col = ndxTuple[1]
> assert row >= 0 and row < self.numRows() \
> and col >= 0 and col < self.numCols(), \
> "Array subscript out of range."
> the1dArray = self._theRows[row]
> return the1dArray[col]
>
> # Sets the contents of the element at position [i,j] to value.
> def __setitem__( self, ndxTuple, value ):
> #assert len(ndxTuple) == 3, "Invalid number of array subscripts."
> row = ndxTuple[0]
> col = ndxTuple[1]
> assert row >= 0 and row < self.numRows() \
> and col >= 0 and col < self.numCols(), \
> "Array subscript out of range."
> the1dArray = self._theRows[row]
> the1dArray[col] = value
>
>
> arr = Array2D(2,4)
>
> print "arr is %s" %arr
>
>
> Traceback is :
>
> sixe is 2
> type is e 
> Elements are self.element 
> Cols in 4
> Num of Cloumns is 4
> !! i is 0
> sixe is 4
> type is e 
> Elements are self.element 
> Type is  
> Traceback (most recent call last):
>   File "C:\Python27\Lib\array2D.py", line 53, in 
> arr = Array2D(2,4)
>   File "C:\Python27\Lib\array2D.py", line 16, in __init__
> self._theRows[i] = arrays.Array( numCols )
>   File "C:\Python27\Lib\arrays.py", line 36, in __setitem__
> self._elements[ index ] = value
> AttributeError: Array instance has no attribute '__trunc__'
> --
> http://mail.python.org/mailman/listinfo/python-list
>


Not sure about the __trunc__ problem but i can suggest this alternative
which is a bit simpler

def array2D(x, y, val=None):
return [[val for col in xrange(x)] for row in xrange(y)]


-- 
"The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess question re waiting

2013-04-08 Thread Dylan Evans
On Mon, Apr 8, 2013 at 10:22 PM, Dave Angel  wrote:

> On 04/08/2013 08:01 AM, Dylan Evans wrote:
>
>> On Mon, Apr 8, 2013 at 9:48 PM, Alain Ketterlin <
>> al...@dpt-info.u-strasbg.fr
>>
>>> wrote:
>>>
>>
>>  loial  writes:
>>>
>>>  I want to call a child process to run a shell script and wait for that
>>>> script to finish. Will the code below wait for the script to finish?
>>>> If not then how do I make it wait?
>>>>
>>> [...]
>>>
>>>> process = subprocess.Popen(command,
>>>>
>>> stdin=subprocess.PIPE,stdout=**subprocess.PIPE, stderr=subprocess.PIPE,
>>> close_fds=True, shell=True)
>>>
>>> process.wait()
>>>
>>>
>> Or use subprocess.call instead which does what you want.
>>
>>
Actually after having a look through the manual i like check_output for
this since it simplifies the code, but some extra exception handling would
be required if the output is still required when the script exits with a
non zero value, so it's a bit of a trade off.


>  -- Alain.
>>> --
>>> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>>>
>>>
>>
> http://docs.python.org/2/**library/subprocess.html#popen-**objects<http://docs.python.org/2/library/subprocess.html#popen-objects>
>
> or use communicate(), which is what the OP had in the first place.
>
>
> --
> DaveA
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>



-- 
"The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is "_io.py" missing from 2.7.4 ?

2013-04-08 Thread Dylan Evans
On Mon, Apr 8, 2013 at 11:12 PM, dbv  wrote:

> In 2.7.4, io.py shows:
>
> import _io
> import abc
>
> from _io import (DEFAULT_BUFFER_SIZE, BlockingIOError,
> UnsupportedOperation,
>  open, FileIO, BytesIO, StringIO, BufferedReader,
>  BufferedWriter, BufferedRWPair, BufferedRandom,
>  IncrementalNewlineDecoder, TextIOWrapper)
>
> but, cannot find _io.py, though there is the old _pyio.py in the
> //Python27//Lib folder.
>
> >>> _io.__file__
'/usr/lib/python2.7/lib-dynload/_io.so'

Looks like it's implemented in C.



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



-- 
"The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: USBLock : lock/unlock your computer with a USB key

2013-04-11 Thread Dylan Evans
This looks cool, would actual be pretty useful. I see you did it as a usb
project but probably bluetooth would be better so you could just pair it to
your phone and know that your PC will lock when you walk away.



On Tue, Apr 9, 2013 at 1:21 AM, Sven  wrote:

> I've been working on a little project and have a working Linux
> implementation so far. Basically it allows a user to use any USB stick as a
> key to lock and unlock their computer. More info in the repo or PyPi
> https://pypi.python.org/pypi/USBLock
>
> Basically run the program with -a to add a device (added once you insert
> it), then run it without any arguments. Insert the key again, and when you
> remove it your computer will lock. Insert the key again and it will unlock.
> It's not intended to provide military grade security, it's more of a
> convenience tool to launch built in screen locking software.
>
> Currently it locks a Linux box with xlock, pending a better solution.
>
> I wrote it as an exercise in playing around with USB media and events, and
> also because I needed a use for these old USB keys I have lying around :)
>
> Always looking for contributions, suggestions and improvements. Especially
> OS X and Win support.
>
> Repo:
> https://github.com/Svenito/usblock
>
> Thanks for your time.
>
> --
> ./Sven
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
"The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: USBLock : lock/unlock your computer with a USB key

2013-04-12 Thread Dylan Evans
On Fri, Apr 12, 2013 at 6:16 AM, Ian Kelly  wrote:

> On Thu, Apr 11, 2013 at 9:23 AM, Ethan Furman  wrote:
> > On 04/11/2013 04:13 AM, Sven wrote:
> >>
> >> Yes, I had the idea to add bluetooth too, removes the whole plugging and
> >> unplugging spiel. I might start work on that,
> >> and if anyone else wants to dive in and help, feel free. I will probably
> >> need to refactor the Listener a little, or
> >> create a USB and BT listener class.
> >
> >
> > Doesn't BlueTooth have a 30 foot range?  For locking I'd rather be at 10
> or
> > even 5 feet away.
>
>
I guess it depends on your needs, I'd want it locked when i wander out of
the office.


> Pair it with a Google Glass and have it lock after you've stopped
> looking at the screen for 30 seconds.
>

That would be awesome.


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



-- 
"The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum
-- 
http://mail.python.org/mailman/listinfo/python-list


Linking to Python for Windows CE

2006-01-16 Thread Martin Evans
I've just been tasked with porting our desktop embedded Python support 
onto our existing CE offering. I've managed to compile the Python 
sources and have produced an armdbg420\python23.lib file.

When I come to link to the Python library though from our one of our 
DLLs, I am getting the following unresolved externals:

---
embedded.obj : error LNK2019: unresolved external symbol
"__declspec(dllimport) int __cdecl WinCE_fclose(void *)"
(__imp_?WinCE_fclose@@[EMAIL PROTECTED]) referenced in function "unsigned long
__cdecl PythonThread(void *)" (?PythonThread@@[EMAIL PROTECTED])

embedded.obj : error LNK2019: unresolved external symbol __imp_LoadLibraryU
referenced in function "unsigned long __cdecl PythonThread(void *)"
(?PythonThread@@[EMAIL PROTECTED])

embedded.obj : error LNK2019: unresolved external symbol
"__declspec(dllimport) void * __cdecl WinCE_fopen(char const *,char const
*)" (__imp_?WinCE_fopen@@[EMAIL PROTECTED]) referenced in function "void * 
__cdecl
OpenScriptFile(unsigned short *)" (?OpenScriptFile@@[EMAIL PROTECTED])

---

python23.lib does have entries for WinCE_fopen (part of 
wince-compatibility.c) when looking at the lib file using dumpbin (all 
are undecorated). Have I missed some vital step in producing it?


Just to clarify my environment, I am producing a PocketPC 2003 
application that embeds Python, scripts are launched within our 
application with script output displayed in our own output window. We 
also provide our own Python extension library. All works on ok on the 
desktop version.

Any help would gratefully appreciated. Thanks.

Martin

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


Re: Linking to Python for Windows CE

2006-01-16 Thread Martin Evans
Sorry, false alarm.  It turned out one of my own files was using 
fopen/fclose and this was upseting things. After removing those it 
linked fine.

Martin Evans wrote:

> I've just been tasked with porting our desktop embedded Python support 
> onto our existing CE offering. I've managed to compile the Python 
> sources and have produced an armdbg420\python23.lib file.
> 
> When I come to link to the Python library though from our one of our 
> DLLs, I am getting the following unresolved externals:
> 
> ---
> embedded.obj : error LNK2019: unresolved external symbol
> "__declspec(dllimport) int __cdecl WinCE_fclose(void *)"
> (__imp_?WinCE_fclose@@[EMAIL PROTECTED]) referenced in function "unsigned long
> __cdecl PythonThread(void *)" (?PythonThread@@[EMAIL PROTECTED])
> 
> embedded.obj : error LNK2019: unresolved external symbol __imp_LoadLibraryU
> referenced in function "unsigned long __cdecl PythonThread(void *)"
> (?PythonThread@@[EMAIL PROTECTED])
> 
> embedded.obj : error LNK2019: unresolved external symbol
> "__declspec(dllimport) void * __cdecl WinCE_fopen(char const *,char const
> *)" (__imp_?WinCE_fopen@@[EMAIL PROTECTED]) referenced in function "void * 
> __cdecl
> OpenScriptFile(unsigned short *)" (?OpenScriptFile@@[EMAIL PROTECTED])
> 
> ---
> 
> python23.lib does have entries for WinCE_fopen (part of 
> wince-compatibility.c) when looking at the lib file using dumpbin (all 
> are undecorated). Have I missed some vital step in producing it?
> 
> 
> Just to clarify my environment, I am producing a PocketPC 2003 
> application that embeds Python, scripts are launched within our 
> application with script output displayed in our own output window. We 
> also provide our own Python extension library. All works on ok on the 
> desktop version.
> 
> Any help would gratefully appreciated. Thanks.
> 
> Martin
> 

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


Adding private tags to a tiff file.

2006-08-11 Thread O Evans
Hi there,

I'm manipualating tiff images captured by a program that insists on
using annoying private tags. I want to be able to import an image that
I have created into the program but I cannot get PIL to save the
private tag. Here is a simplified version of the code I am using:

import Image
original = Image.open(r"test.tif")
original.tag[34118] = "life"
print "Before saving" , original.tag[34118]
original.save("test2.tif")
altered = Image.open(r"test2.tif")
if altered.tag.tagdata.has_key(34118):
print "It worked!"

Is there a way of getting this to work? I have tried looking at
TiffTags and TiffImageFile, but I cannot understand why the tags are
not preserved. Or should I be looking at a different library?

Many thanks.

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


Newbie: datetime conversion question

2006-10-17 Thread kevin evans
Hi,
I'm trying to convert some code from Ruby to Python, specifically..

timestamp = "%08x" % Time.now.to_i

Make a hex version of the current timestamp. Any ideas how best to do
this in python gratefully received..

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


Re: Newbie: datetime conversion question

2006-10-17 Thread kevin evans
Great stuff - many thanks


hg wrote:
> Carsten Haese wrote:
> > On Tue, 2006-10-17 at 08:49, hg wrote:
> >> import time
> >> "%08X"% (int)(time.mktime(time.localtime()))
> >
> > Have you not had your coffee yet or are you trying to win an obfuscated
> > python programming competition? ;)
> > 
> > -Carsten
> > 
> > 
> Just one cup
> 
> hg

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


Python 2.5 Core Dump on Solaris 8

2006-11-10 Thread Melissa Evans

Hi.  I'm new to Python. :)

I've modified grappy.py, 
http://www.stacken.kth.se/~mattiasa/projects/grappy/, a postfix policy 
daemon for greylisting. to use LDAP as a backend instead of SQL (with 
python-ldap.)  The daemon runs fine when testing but when I put it under 
load it core dumps quickly.  What little analysis I know how to do shows 
similar information every time.  Any advice on where to go from here?

Thanks!
Melissa


Python 2.5 on Solaris 8:

truss:

   write(1, " g r e y l i s t e d :  ".., 82)  = 82
   Action:defer_if_permit Temporary failure
   write(1, " A c t i o n : d e f e r".., 41)  = 41
   Incurred fault #5, FLTACCESS  %pc = 0xFF142794
 siginfo: SIGBUS BUS_ADRALN addr=0x000F
   Received signal #10, SIGBUS [default]
 siginfo: SIGBUS BUS_ADRALN addr=0x000F
   *** process killed ***

pflags:

core './core' of 12227: python grappy-ldap.py
 data model = _ILP32  flags = PR_RLC
   flttrace = 0xfbff
   sigtrace = 0xfeff 0x
   entryset = 0x0401 0x0400 0x 0x0028
  0x8000 0x 0x 0x
   exitset  = 0xfffe 0x 0x 0xffd7
  0x7fff 0x 0x 0x
   /16:  flags = PR_PCINVAL
   sigmask = 0xbefc,0x1fff  cursig = SIGBUS
   /17:  flags = PR_STOPPED
   why = PR_SUSPENDED
   /18:  flags = PR_STOPPED
   why = PR_SUSPENDED
   /19:  flags = PR_STOPPED
   why = PR_SUSPENDED
   /20:  flags = PR_STOPPED
   why = PR_SUSPENDED
   /21:  flags = PR_STOPPED
   why = PR_SUSPENDED
   /1:   flags = PR_STOPPED
   why = PR_SUSPENDED
   /2:   flags = PR_STOPPED|PR_ASLWP
   why = PR_SUSPENDED
   sigmask = 0xffbffeff,0x1fff
   /3:   flags = PR_STOPPED
   why = PR_SUSPENDED
   /4:   flags = PR_STOPPED
   why = PR_SUSPENDED
   /5:   flags = PR_STOPPED
   why = PR_SUSPENDED
   /6:   flags = PR_STOPPED
   why = PR_SUSPENDED
   /7:   flags = PR_STOPPED
   why = PR_SUSPENDED
   /8:   flags = PR_STOPPED
   why = PR_SUSPENDED
   /9:   flags = PR_STOPPED
   why = PR_SUSPENDED
   /10:  flags = PR_STOPPED
   why = PR_SUSPENDED
   /11:  flags = PR_STOPPED
   why = PR_SUSPENDED
   /12:  flags = PR_STOPPED
   why = PR_SUSPENDED
   /13:  flags = PR_STOPPED
   why = PR_SUSPENDED
   /14:  flags = PR_STOPPED
   why = PR_SUSPENDED
   /15:  flags = PR_STOPPED
   why = PR_SUSPENDED

pstack for the suspicious thread:

core './core' of 12227: python grappy-ldap.py
-  lwp# 16 / thread# 13  
  ff142794 t_delete (, 15df78, fffd, 1590f0, 3c4cf0, 4e80) + 
c
  ff14240c realfree (, ff1c2858, ff1bc008, 1590f0, 4e83, 1590f8) 
+ d0
  ff142cb0 cleanfree (0, ff1bc008, ff1c27cc, ff1c284c, ff1c281c, 0) + 58
  ff141de4 _malloc_unlocked (10, 0, ff1bc008, 10, 1, 0) + f0
  ff141fec realloc  (ff1c0608, 10, ff1bc008, 4cd80, 10, 0) + 5c
  00040278 app1 (26c788, 264610, 1292ec, 0, 25ddd0, 25dddc) + a4
  00044324 listappend (26c788, 264610, 1291c4, 8, ff1bfc78, 106418) + 8
  0008f1f8 call_function (fe1086a0, 1, 8cc30, 4cd80, 6, 15c45c) + 594
  0008cc38 PyEval_EvalFrameEx (2c9668, 1, 0, 2c9668, 1, 1b00f0) + 2be0
  0008f73c fast_function (1daaf0, 3d7240, 2, 2c9668, 1b00f0, 2639c0) + c4
  0008f5ec call_function (fe108868, 2, 8cc30, 4cd80, 5, 21191c) + 988
  0008cc38 PyEval_EvalFrameEx (3d70e8, 1, 0, 3d70e8, 1, 1b00f0) + 2be0
  0008f73c fast_function (268c30, 2c8dc4, 1, 3d70e8, 1b00f0, 1b00f0) + c4
  0008f5ec call_function (fe108a30, 1, 8cc30, 0, 4, 156ac4) + 988
  0008cc38 PyEval_EvalFrameEx (2c8c78, 0, 0, 2c8c78, 1, 1b00f0) + 2be0
  0008e03c PyEval_EvalCodeEx (1d4a88, 1cc4b0, 0, 2639cc, 4, 0) + 838
  000e2010 function_call (1e0130, 2639c0, 0, e1ed0, 146a98, 14c8e4) + 140
  00025c28 PyObject_Call (1e0130, 2639c0, 0, 2639dc, 3, 2639c0) + 20
  0002e2ac instancemethod_call (1e0130, 2639c0, 0, 2e09c, 1249f8, 26a9ad) 
+ 210
  00025c28 PyObject_Call (26c3a0, 269a58, 0, e2730, 2, 156a5c) + 20
  0008ec2c PyEval_CallObjectWithKeywords (26c3a0, 269a58, 0, 332420, 1, 
1b00f0) + f4
  000290a4 PyInstance_New (269580, 269a58, 0, 28f88, 12462c, 14c8e4) + 
11c
  00025c28 PyObject_Call (2632d0, 269a58, 0, 0, 269a58, 269a64) + 20
  00091ba0 do_call  (2632d0, fe1091a0, , 0, 26976c, 269760) + 94
  0008f604 call_function (fe1091a0, 3, 8cc30, 4, 3, 265754) + 9a0
  0008cc38 PyEval_EvalFrameEx (330f98, 3, 0, 330f98, 1, 1b00f0) + 2be0
  0008f73c fast_function (1da1b0, 332570, 3, 330f98, 1b00f0, 332108) + c4
  0008f5ec call_function (fe109368, 3, 8cc30, 0, 2, 156a5c) + 988
  0008cc38 PyEval_EvalFrameEx (332420, 2, 0, 332420, 1, 1b00f0) + 2be0
  0008e03c PyEval_EvalCodeEx (1d4728, 1cc4b0, 0, 26976c, 3, 2c0510) + 838
  000e2010 function_call (1e00b0, 269760, 26ddb0, e1ed0, 146a98, 14c8e4) 
+ 140
  00025c28 PyObject_Call (1e00b0, 269760, 26ddb0, 0, 26976c, 269760) + 20
  0008fe8c ext_do_call (1e00b0, fe109604, 3, , 0, 23d4b4) + 3ec
  0008cd30 PyEval_EvalFrameEx (3, 3323d4, 0, 332298, 1, 1b00f0) + 2cd8
  0008f73c fast_function (242f

RegEx conditional search and replace

2006-07-05 Thread Martin Evans
Sorry, yet another REGEX question.  I've been struggling with trying to get 
a regular expression to do the following example in Python:

Search and replace all instances of "sleeping" with "dead".

This parrot is sleeping. Really, it is sleeping.
to
This parrot is dead. Really, it is dead.


But not if part of a link or inside a link:

This parrot is sleeping. Really, it 
is sleeping.
to
This parrot is sleeping. Really, it 
is dead.


This is the full extent of the "html" that would be seen in the text, the 
rest of the page has already been processed. Luckily I can rely on the 
formating always being consistent with the above example (the url will 
normally by much longer in reality though). There may though be more than 
one link present.

I'm hoping to use this to implement the automatic addition of links to other 
areas of a website based on keywords found in the text.

I'm guessing this is a bit too much to ask for regex. If this is the case, 
I'll add some more manual Python parsing to the string, but was hoping to 
use it to learn more about regex.

Any pointers would be appreciated.

Martin



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


Re: RegEx conditional search and replace

2006-07-06 Thread Martin Evans
"Juho Schultz" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Martin Evans wrote:
>> Sorry, yet another REGEX question.  I've been struggling with trying to 
>> get
>> a regular expression to do the following example in Python:
>>
>> Search and replace all instances of "sleeping" with "dead".
>>
>> This parrot is sleeping. Really, it is sleeping.
>> to
>> This parrot is dead. Really, it is dead.
>>
>>
>> But not if part of a link or inside a link:
>>
>> This parrot is sleeping. Really, 
>> it
>> is sleeping.
>> to
>> This parrot is sleeping. Really, 
>> it
>> is dead.
>>
>>
>> This is the full extent of the "html" that would be seen in the text, the
>> rest of the page has already been processed. Luckily I can rely on the
>> formating always being consistent with the above example (the url will
>> normally by much longer in reality though). There may though be more than
>> one link present.
>>
>> I'm hoping to use this to implement the automatic addition of links to 
>> other
>> areas of a website based on keywords found in the text.
>>
>> I'm guessing this is a bit too much to ask for regex. If this is the 
>> case,
>> I'll add some more manual Python parsing to the string, but was hoping to
>> use it to learn more about regex.
>>
>> Any pointers would be appreciated.
>>
>> Martin
>
> What you want is:
>
> re.sub(regex, replacement, instring)
> The replacement can be a function. So use a function.
>
> def sleeping_to_dead(inmatch):
>  instr = inmatch.group(0)
>  if needsfixing(instr):
>return instr.replace('sleeping','dead')
>  else:
>return instr
>
> as for the regex, something like
> (]*()?
> could be a start. It is probaly better to use the regex to recognize
> the links as you might have something like
> sleeping.sleeping/sleeping/sleeping.html in your urls. Also you
> probably want to do many fixes, so you can put them all within the same
> replacer function.

Many thanks for that, the function method looks very useful. My first 
working attempt had been to use the regex to locate all links. I then looped 
through replacing each with a numbered dummy entry. Then safely do the 
find/replaces and then replace the dummy entries with the original links. It 
just seems overly inefficient.



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


Re: RegEx conditional search and replace

2006-07-06 Thread Martin Evans
"mbstevens" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Thu, 06 Jul 2006 08:32:46 +0100, Martin Evans wrote:
>
>> "Juho Schultz" <[EMAIL PROTECTED]> wrote in message
>> news:[EMAIL PROTECTED]
>>> Martin Evans wrote:
>>>> Sorry, yet another REGEX question.  I've been struggling with trying to
>>>> get
>>>> a regular expression to do the following example in Python:
>>>>
>>>> Search and replace all instances of "sleeping" with "dead".
>>>>
>>>> This parrot is sleeping. Really, it is sleeping.
>>>> to
>>>> This parrot is dead. Really, it is dead.
>>>>
>>>>
>>>> But not if part of a link or inside a link:
>>>>
>>>> This parrot is sleeping. 
>>>> Really,
>>>> it
>>>> is sleeping.
>>>> to
>>>> This parrot is sleeping. 
>>>> Really,
>>>> it
>>>> is dead.
>>>>
>>>>
>>>> This is the full extent of the "html" that would be seen in the text, 
>>>> the
>>>> rest of the page has already been processed. Luckily I can rely on the
>>>> formating always being consistent with the above example (the url will
>>>> normally by much longer in reality though). There may though be more 
>>>> than
>>>> one link present.
>>>>
>>>> I'm hoping to use this to implement the automatic addition of links to
>>>> other
>>>> areas of a website based on keywords found in the text.
>>>>
>>>> I'm guessing this is a bit too much to ask for regex. If this is the
>>>> case,
>>>> I'll add some more manual Python parsing to the string, but was hoping 
>>>> to
>>>> use it to learn more about regex.
>>>>
>>>> Any pointers would be appreciated.
>>>>
>>>> Martin
>>>
>>> What you want is:
>>>
>>> re.sub(regex, replacement, instring)
>>> The replacement can be a function. So use a function.
>>>
>>> def sleeping_to_dead(inmatch):
>>>  instr = inmatch.group(0)
>>>  if needsfixing(instr):
>>>return instr.replace('sleeping','dead')
>>>  else:
>>>return instr
>>>
>>> as for the regex, something like
>>> (]*()?
>>> could be a start. It is probaly better to use the regex to recognize
>>> the links as you might have something like
>>> sleeping.sleeping/sleeping/sleeping.html in your urls. Also you
>>> probably want to do many fixes, so you can put them all within the same
>>> replacer function.
>>
>> ... My first
>> working attempt had been to use the regex to locate all links. I then 
>> looped
>> through replacing each with a numbered dummy entry. Then safely do the
>> find/replaces and then replace the dummy entries with the original links. 
>> It
>> just seems overly inefficient.
>
> Someone may have made use of
> multiline links:
>
> _
> This parrot
>  href="sleeping.htm"
> target="new"   >
> is sleeping
> .
> Really, it is sleeping.
> _
>
>
> In such a case you may need to make the page
> into one string to search if you don't want to use some complex
> method of tracking state with variables as you move from
> string to string.  You'll also have to make it possible
> for non-printing characters to have been inserted in all sorts
> of ways around the '>' and '<' and 'a' or 'A'
> characters using ' *' here and there in he regex.

I agree, but luckily in this case the HREF will always be formated the same 
as it happens to be inserted by another automated system, not a user. Ok it 
be changed by the server but AFAIK it hasn't for the last 6 years. The text 
in question apart from the links should be plain (not even  is allowed I 
think).

I'd read about back and forward regex matching and thought it might somehow 
be of use here ie back search for the "" 
but of course this would easily match in between two links.



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


Invalid thread state for this thread

2007-05-24 Thread Martin Evans
I know this has been seen before but it is not making too much sense (after 
reading many posts). It all appears to work fine but then dies after about 
40 invocations.

My app has Python embedded, it is embedded as part of a dll which 
initializes python and finalizes on load and unload (see below). When a 
script needs to be run, I create a new thread, let the script complete and 
close the thread.

The thread contains the following type arrangement:

PythonThread()
{
  hScriptFile = OpenScriptFile(m_szActiveScript);
  PyEval_AcquireLock();
  pInterpreter = Py_NewInterpreter();
  Py_SetProgramName(szModuleFileName);
  PyRun_SimpleFile(hScriptFile,m_szActiveScript);
  PyErr_Clear();
  Py_EndInterpreter(pInterpreter);
  PyEval_ReleaseLock();
}

This appears to work fine accept that after around 30-40 invocations I 
always get the "Invalid thread state for this thread". ie the app and dll 
stay loaded and I click my "run" button manually about 40 times. In this 
test it is a simple "hello world" type script. The size of the script does 
not appear to matter.

The dll is coded something like this:

DllLoad()
{
  Py_Initialize();
  PyEval_InitThreads();
  m_mainThreadState = PyThreadState_Get();
  PyEval_ReleaseLock();
}

DllUnload() (not called as part of this test)
{
  PyEval_AcquireLock();
  PyThreadState_Swap(m_mainThreadState);
  Py_Finalize();
}

The app has been designed to allow a second interpreter to run independently 
(thus the need for multiple thread support) and this also appears to work 
fine, but for this test only this one thread was used. I have a compiled 
version of 2.4.2.

Any ideas would be appreciated.

Martin 


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


Re: Invalid thread state for this thread

2007-05-25 Thread Martin Evans
Just in case anyone else has seen this problem, after upgrading to 2.4.4 the 
problem appears to have resolved itself.

>I know this has been seen before but it is not making too much sense (after 
>reading many posts). It all appears to work fine but then dies after about 
>40 invocations.
>
> My app has Python embedded, it is embedded as part of a dll which 
> initializes python and finalizes on load and unload (see below). When a 
> script needs to be run, I create a new thread, let the script complete and 
> close the thread.
>
> The thread contains the following type arrangement:
>
> PythonThread()
> {
>  hScriptFile = OpenScriptFile(m_szActiveScript);
>  PyEval_AcquireLock();
>  pInterpreter = Py_NewInterpreter();
>  Py_SetProgramName(szModuleFileName);
>  PyRun_SimpleFile(hScriptFile,m_szActiveScript);
>  PyErr_Clear();
>  Py_EndInterpreter(pInterpreter);
>  PyEval_ReleaseLock();
> }
>
> This appears to work fine accept that after around 30-40 invocations I 
> always get the "Invalid thread state for this thread". ie the app and dll 
> stay loaded and I click my "run" button manually about 40 times. In this 
> test it is a simple "hello world" type script. The size of the script does 
> not appear to matter.
>
> The dll is coded something like this:
>
> DllLoad()
> {
>  Py_Initialize();
>  PyEval_InitThreads();
>  m_mainThreadState = PyThreadState_Get();
>  PyEval_ReleaseLock();
> }
>
> DllUnload() (not called as part of this test)
> {
>  PyEval_AcquireLock();
>  PyThreadState_Swap(m_mainThreadState);
>  Py_Finalize();
> }
>
> The app has been designed to allow a second interpreter to run 
> independently (thus the need for multiple thread support) and this also 
> appears to work fine, but for this test only this one thread was used. I 
> have a compiled version of 2.4.2.
>
> Any ideas would be appreciated.
>
> Martin 


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


Re: Parser Generator?

2007-08-22 Thread Jason Evans
On Aug 18, 3:22 pm, "Jack" <[EMAIL PROTECTED]> wrote:
> Hi all, I need to do syntax parsing of simple naturual languages,
> for example, "weather of London" or "what is the time", simple
> things like these, with Unicode support in the syntax.
>
> In Java, there are JavaCC, Antlr, etc. I wonder what people use
> in Python? Antlr also has Python support but I'm not sure how good
> it is. Comments/hints are welcome.

I use Parsing.py.  I like it a lot, probably because I wrote it.

http://www.canonware.com/Parsing/

Jason

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


Re: Parser Generator?

2007-08-26 Thread Jason Evans
On Aug 24, 1:21 pm, "Jack" <[EMAIL PROTECTED]> wrote:
> "Jason Evans" <[EMAIL PROTECTED]> wrote in message
> >http://www.canonware.com/Parsing/
>
> Thanks Jason. Does Parsing.py support Unicode characters (especially CJK)?
> I'll take a look.

Parsers typically deal with tokens rather than individual characters,
so the scanner that creates the tokens is the main thing that Unicode
matters to.  I have written Unicode-aware scanners for use with
Parsing-based parsers, with no problems.  This is pretty easy to do,
since Python has built-in support for Unicode strings.

Jason

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


py2exe, library.zip and python.exe

2007-02-28 Thread Martin Evans
I have converted a Python script using py2exe and have it set to not bundle 
or compress. The result is my exe and all the support files including 
library.zip (exactly as planned - nice job py2exe).

Question:  My py2exe application needs to be able to execute extra copies of 
python.exe. I have placed python.exe in the same directory. It obviously 
picks up the main python24.dll but how can I configure things so that it 
would use the same library.zip for all the library files?  This would save 
me having two sets of files.

(The py2exe application happens to be a twisted server app running as a 
service which has the ability to launch python scripts as a logged on user)

Thanks,  Martin.


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


Re: py2exe, library.zip and python.exe

2007-02-28 Thread Martin Evans
"Thomas Heller" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Martin Evans schrieb:
>> I have converted a Python script using py2exe and have it set to not 
>> bundle
>> or compress. The result is my exe and all the support files including
>> library.zip (exactly as planned - nice job py2exe).
>>
>> Question:  My py2exe application needs to be able to execute extra copies 
>> of
>> python.exe. I have placed python.exe in the same directory. It obviously
>> picks up the main python24.dll but how can I configure things so that it
>> would use the same library.zip for all the library files?  This would 
>> save
>> me having two sets of files.
>>
>> (The py2exe application happens to be a twisted server app running as a
>> service which has the ability to launch python scripts as a logged on 
>> user)
>>
>> Thanks,  Martin.
>>
>>
> You have to put library.zip on sys.path.  Maybe you could create a site.py 
> file
> in that directory which can do this, I assume the python.exe will try to 
> load that.
>
> There may be other possibilities as well.
>
> Thomas
>

Many thanks for the tip, it got me thinking. When python.exe is loaded, 
sys.path already had python24.zip in it so changing the specified library in 
py2exe from the default libary.zip to python24.zip solved it!

Martin


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


Cast to a method pointer in ctypes

2011-01-31 Thread Andrew Evans
How can I cast to a method pointer in ctypes. for example this in C

int (*func)();
func = (int (*)()) expl;
(int)(*func)();

How can I do this in ctypes using Python? I couldn't find the info I needed
to be able to do this

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


Striving for PEP-8 compliance

2010-04-07 Thread Tom Evans
[ Please keep me cc'ed, I'm not subscribed ]

Hi all

I've written a bunch of internal libraries for my company, and they
all use two space indents, and I'd like to be more consistent and
conform to PEP-8 as much as I can.

My problem is I would like to be certain that any changes do not alter
the logic of the libraries. When doing this in C, I would simply
compile each module to an object file, calculate the MD5 of the object
file, then make the whitespace changes, recompile the object file and
compare the checksums. If the checksums match, then the files are
equivalent.

Is there any way to do something semantically the same as this with python?

Cheers

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


  1   2   >