Re: Help needed - - running into issues with python and its tools

2024-08-06 Thread o1bigtenor via Python-list
On Tue, Aug 6, 2024 at 10:53 AM Bill Deegan 
wrote:

> I’m not looking through all the packages you have installed
>
> (Ctrl-F is your friend - - - )


> What version of python is installed on your system?
>
> There are actually 3 versions installed - - - which is why the whole list
was posted.
Your question was really not clear given the context.

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


Re: Help needed - - running into issues with python and its tools

2024-08-06 Thread Bill Deegan via Python-list
I’m not looking through all the packages you have installed

What version of python is installed on your system?


On Tue, Aug 6, 2024 at 5:24 AM o1bigtenor  wrote:

>
>
> On Mon, Aug 5, 2024 at 10:36 PM Bill Deegan 
> wrote:
>
>> why reply to me instead of to the list?
>> It's generally considered bad form to do so.
>>
>
> Got it - - - except this list wants only reply all the next one wants only
> reply and
> keeping straight which is which isn't always happening. I did apologize
> and asked
> you to advise in the next one whether you even wanted to be included
> (which you haven't
> responded to).
>
>>
>>
>> Do you have any python 3 installed on your system?
>> Or python 2.7?
>> If not, can you install such via system package?
>>
>
>
>  # dpkg -l | grep python*
> ii  2to3   3.11.2-1
>   all  2to3 binary using python3
> ii  idle-python3.113.11.2-6+deb12u2
>   all  IDE for Python (v3.11) using Tkinter
> ii  ipython3   8.5.0-4
>  all  Enhanced interactive Python 3 shell
> ii  libboost-python1.74.0  1.74.0+ds1-21
>  amd64Boost.Python Library
> ii  libpython3-all-dev:amd64   3.11.2-1+b1
>  amd64package depending on all supported Python 3
> development packages
> ii  libpython3-dev:amd64   3.11.2-1+b1
>  amd64header files and a static library for Python
> (default)
> ii  libpython3-stdlib:amd643.11.2-1+b1
>  amd64interactive high-level object-oriented language
> (default python3 version)
> rc  libpython3.10-minimal:amd643.10.9-1
>   amd64Minimal subset of the Python language (version
> 3.10)
> ii  libpython3.11:amd643.11.2-6+deb12u2
>   amd64Shared Python runtime library (version 3.11)
> ii  libpython3.11-dev:amd643.11.2-6+deb12u2
>   amd64Header files and a static library for Python
> (v3.11)
> ii  libpython3.11-minimal:amd643.11.2-6+deb12u2
>   amd64Minimal subset of the Python language (version
> 3.11)
> ii  libpython3.11-stdlib:amd64 3.11.2-6+deb12u2
>   amd64Interactive high-level object-oriented language
> (standard library, version 3.11)
> ii  libpython3.11-testsuite3.11.2-6+deb12u2
>   all  Testsuite for the Python standard library (v3.11)
> ii  libpython3.9-minimal:amd64 3.9.13-1
>   amd64Minimal subset of the Python language (version
> 3.9)
> ii  libpython3.9-stdlib:amd64  3.9.13-1
>   amd64Interactive high-level object-oriented language
> (standard library, version 3.9)
> ii  python-apsw-doc3.40.0.0-2
>   all  documentation for python-apsw
> ii  python-apt-common  2.6.0
>  all  Python interface to libapt-pkg (locales)
> ii  python-apt-common-devuan   2.5.3devuan2
>   all  Templates for aptitude
> ii  python-attr-doc22.2.0-1
>   all  documentation for the attrs Python library
> ii  python-babel-localedata2.10.3-1
>   all  tools for internationalizing Python applications
> - locale data files
> ii  python-cryptography-doc38.0.4-3
>   all  Python library exposing cryptographic recipes
> and primitives (documentation)
> ii  python-cycler-doc  0.11.0-1
>   all  composable kwarg iterator (documentation)
> ii  python-gmpy2-common2.1.2-2
>  all  common files for python3-gmpy2
> ii  python-ipython-doc 8.5.0-4
>  all  Enhanced interactive Python shell (documentation)
> ii  python-markdown-doc3.4.1-2
>  all  text-to-HTML conversion library/tool
> (documentation)
> ii  python-matplotlib-data 3.6.3-1
>  all  Python based plotting system (data package)
> ii  python-matplotlib-doc  3.5.2-4
>  all  Python based plotting system (documentation
> package)
> ii  python-mpmath-doc  1.2.1-2
>  all  library for arbitrary-precision floating-point
> arithmetic - Documentation
> ii  python-numpy-doc   1:1.23.5-2
>   all  NumPy documentation
> ii  python-pexpect-doc 4.8.0-4
>  al

Re: Help needed - - running into issues with python and its tools

2024-08-06 Thread o1bigtenor via Python-list
On Mon, Aug 5, 2024 at 10:36 PM Bill Deegan 
wrote:

> why reply to me instead of to the list?
> It's generally considered bad form to do so.
>

Got it - - - except this list wants only reply all the next one wants only
reply and
keeping straight which is which isn't always happening. I did apologize and
asked
you to advise in the next one whether you even wanted to be included (which
you haven't
responded to).

>
>
> Do you have any python 3 installed on your system?
> Or python 2.7?
> If not, can you install such via system package?
>


 # dpkg -l | grep python*
ii  2to3   3.11.2-1
all  2to3 binary using python3
ii  idle-python3.113.11.2-6+deb12u2
all  IDE for Python (v3.11) using Tkinter
ii  ipython3   8.5.0-4
 all  Enhanced interactive Python 3 shell
ii  libboost-python1.74.0  1.74.0+ds1-21
 amd64Boost.Python Library
ii  libpython3-all-dev:amd64   3.11.2-1+b1
 amd64package depending on all supported Python 3
development packages
ii  libpython3-dev:amd64   3.11.2-1+b1
 amd64header files and a static library for Python
(default)
ii  libpython3-stdlib:amd643.11.2-1+b1
 amd64interactive high-level object-oriented language
(default python3 version)
rc  libpython3.10-minimal:amd643.10.9-1
amd64Minimal subset of the Python language (version
3.10)
ii  libpython3.11:amd643.11.2-6+deb12u2
amd64Shared Python runtime library (version 3.11)
ii  libpython3.11-dev:amd643.11.2-6+deb12u2
amd64Header files and a static library for Python
(v3.11)
ii  libpython3.11-minimal:amd643.11.2-6+deb12u2
amd64Minimal subset of the Python language (version
3.11)
ii  libpython3.11-stdlib:amd64 3.11.2-6+deb12u2
amd64Interactive high-level object-oriented language
(standard library, version 3.11)
ii  libpython3.11-testsuite3.11.2-6+deb12u2
all  Testsuite for the Python standard library (v3.11)
ii  libpython3.9-minimal:amd64 3.9.13-1
amd64Minimal subset of the Python language (version 3.9)
ii  libpython3.9-stdlib:amd64  3.9.13-1
amd64Interactive high-level object-oriented language
(standard library, version 3.9)
ii  python-apsw-doc3.40.0.0-2
all  documentation for python-apsw
ii  python-apt-common  2.6.0
 all  Python interface to libapt-pkg (locales)
ii  python-apt-common-devuan   2.5.3devuan2
all  Templates for aptitude
ii  python-attr-doc22.2.0-1
all  documentation for the attrs Python library
ii  python-babel-localedata2.10.3-1
all  tools for internationalizing Python applications -
locale data files
ii  python-cryptography-doc38.0.4-3
all  Python library exposing cryptographic recipes and
primitives (documentation)
ii  python-cycler-doc  0.11.0-1
all  composable kwarg iterator (documentation)
ii  python-gmpy2-common2.1.2-2
 all  common files for python3-gmpy2
ii  python-ipython-doc 8.5.0-4
 all  Enhanced interactive Python shell (documentation)
ii  python-markdown-doc3.4.1-2
 all  text-to-HTML conversion library/tool
(documentation)
ii  python-matplotlib-data 3.6.3-1
 all  Python based plotting system (data package)
ii  python-matplotlib-doc  3.5.2-4
 all  Python based plotting system (documentation
package)
ii  python-mpmath-doc  1.2.1-2
 all  library for arbitrary-precision floating-point
arithmetic - Documentation
ii  python-numpy-doc   1:1.23.5-2
all  NumPy documentation
ii  python-pexpect-doc 4.8.0-4
 all  Python module for automating interactive
applications (documentation)
ii  python-pil-doc 9.4.0-1.1+deb12u1
 all  Examples for the Python Imaging Library
ii  python-pygments-doc2.14.0+dfsg-1
 all  documentation for the Pygments
ii  python-scipy-doc

Re: Help needed - - running into issues with python and its tools

2024-08-05 Thread Bill Deegan via Python-list
why reply to me instead of to the list?
It's generally considered bad form to do so.


Do you have any python 3 installed on your system?
Or python 2.7?
If not, can you install such via system package?

-Bill



On Mon, Aug 5, 2024 at 6:06 PM o1bigtenor  wrote:

>
>
> On Mon, Aug 5, 2024 at 5:28 PM Bill Deegan via Python-list <
> python-list@python.org> wrote:
>
>> Did Mats suggestion of:
>> python3.13 -m venv new_venv
>> $ new_venv/bin/python --version
>> Python 3.13.0b4
>> $ source new_venv/bin/activate
>>
>> Not work?
>> That should work on any system, with any system installl python.
>> It's not trying to modify the system installed python in anyway...
>>
>> If not, please paste the error output you're getting.
>>
>
>  # python3.13 -m venv new_venv
> -bash: python3.13: command not found
>
> $ python3.13 -m venv new_venv
> bash: python3.13: command not found
>
> There you have it - - - the first one run as superuser and the second as
> usr.
>
> Regards
>
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help needed - - running into issues with python and its tools

2024-08-05 Thread Bill Deegan via Python-list
Did Mats suggestion of:
python3.13 -m venv new_venv
$ new_venv/bin/python --version
Python 3.13.0b4
$ source new_venv/bin/activate

Not work?
That should work on any system, with any system installl python.
It's not trying to modify the system installed python in anyway...

If not, please paste the error output you're getting.


On Mon, Aug 5, 2024 at 3:13 PM Mats Wichmann via Python-list <
python-list@python.org> wrote:

> On 8/5/24 15:17, o1bigtenor via Python-list wrote:
>
> >> That's something like
> >>
> >> pyenv install 3.12.4
> >>
> >
> > $ pyenv install 3.12.4
> > bash: pyenv: command not found
> >
>
> > pyenv is not a 'global' package
> >
> > there is a mountain of /root/.pyenv  files though
> > there is also quite a number of /root/.pyenv/plugins/pyenv-virtualenv/
> > files
> >
> > when looking in the /root/.pyenv files I can find options for all the
> older
> > version of python
> > but none for anything newer than what is on my system
> >
> > is there something else to install to achieve this 'version freedom' that
> > pyenv promises?
>
> It has to go somewhere your shell can find it.  Mine is a shell
> function, but it was set up so many years ago I don't remember details.
> It's presumably the pyenv installation instructions...
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help needed - - running into issues with python and its tools

2024-08-05 Thread Mats Wichmann via Python-list

On 8/5/24 15:17, o1bigtenor via Python-list wrote:


That's something like

pyenv install 3.12.4



$ pyenv install 3.12.4
bash: pyenv: command not found




pyenv is not a 'global' package

there is a mountain of /root/.pyenv  files though
there is also quite a number of /root/.pyenv/plugins/pyenv-virtualenv/
files

when looking in the /root/.pyenv files I can find options for all the older
version of python
but none for anything newer than what is on my system

is there something else to install to achieve this 'version freedom' that
pyenv promises?


It has to go somewhere your shell can find it.  Mine is a shell 
function, but it was set up so many years ago I don't remember details. 
It's presumably the pyenv installation instructions...




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


Re: Help needed - - running into issues with python and its tools

2024-08-05 Thread o1bigtenor via Python-list
On Mon, Aug 5, 2024 at 3:56 PM Mats Wichmann  wrote:

>
> > On Mon, Aug 5, 2024 at 8:51 AM Mats Wichmann  > > wrote:
> >
> > On 8/5/24 06:48, o1bigtenor via Python-list wrote:
> >  > On Sun, Aug 4, 2024 at 8:49 AM Mats Wichmann via Python-list <
> >  > python-list@python.org > wrote:
> >  >
> >  >> On 8/3/24 20:03, o1bigtenor via Python-list wrote:
> >  >>
> >  >>> My question was, is and will be (and the doc absolutely doesn't
> > cover it)
> >  >>> how do I install a different version in the venv so that python
> > 3.11.x on
> >  >>> the
> >  >>> system is not discombobulated by the python 3.12.x in the venv.
> >  >>> That python 3.12 would let me run the tools needed.
> >  >>> (Its the how to install the next version of python that I just
> > haven't
> >  >> been
> >  >>> able to find information on - - - and I would be looking for
> > information
> >  >>> on how to install on a *nix.)
> >  >>
> >  >> To get a different Python "in" the venv, you use the version you
> > want in
> >  >> the construction of the venv. For example:
> >  >>
> >  >>
> >  >> $ python3.13 -m venv new_venv
> >  >> $ new_venv/bin/python --version
> >  >> Python 3.13.0b4
> >  >> $ source new_venv/bin/activate
> >  >>
> >  >>
> >  >   "https://peps.python.org/pep-0668/
> >  PEP 668, which prevents pip from
> >  > interacting with the OS installed python. This change has been
> > done in red
> >  > hat and other distros too . . . "
> >  >
> >  > similarly your first command produces and error code for the same
> > reason.
> >  >
> >  > Sorry - - - not my policy - - -
> >
> > What? Yes, the *system* pip should have some restrictions, if it's a
> > system mainly managed by a package manager.
> >
> > Setting up a venv is the *expected* approach to such situations, and
> > creating one doesn't cause any problems. You end up with a pip in the
> > activated venv that's going to install to a different path (the one
> in
> > the venv), and will not be marked as externally managed, as the
> package
> > manager has no control over that path.
> >
> > That's the whole point.  What error are you getting?  The venv
> > module is
> > not the pip module so restrictions on the system pip have nothing to
> do
> > with it.
> >
> > set up pyenv
> > activated a venv
> > trying to install python3.12 into it
> >
> > 1. download of python3.12 (blahblahblahetc).deb will not install
> > 2. download of python3.12.tar.xz similarly will not install
> >
> > (venv2) memyself@devuanbigbox:~$ pip install
> > /home/memyself/Downloads/Python-3.12.4.tar.xz
> > Processing ./Downloads/Python-3.12.4.tar.xz
> > ERROR: file:///home/memyself/Downloads/Python-3.12.4.tar.xz does not
> > appear to be a Python project: neither 'setup.py' nor 'pyproject.toml'
> > found.
> >
> > seems that I need a different version (installable as it were) of
> > python3.12
> > or my approach is all wrong!
>
>
> you can't install Python "into" a venv.
>
> you use a version of Python as the base when *creating* a venv, the venv
> will use the same binary as the base python (symlinks if possible, as in
> the Linux case), but with different paths.
>
> Since you've already got pyenv, use it to build the version you want to
> use - I think you said there wasn't a deb for 3.12 in your distro?
>

correct


> That's something like
>
> pyenv install 3.12.4
>

$ pyenv install 3.12.4
bash: pyenv: command not found


>
> that will use the build recipe it has... and hopefully work.  Distro
> Pythons sometimes have some strange setups that are hard to reproduce.
> Pyenv knows how to build micropython, too, should it ever come to that.
>
> If you indeed found a deb for the right Python, use apt to install it,
> and then use *that* Python to create your venv.
>
> If you have the pyenv-virtualenv plugin, you can ask it to make the
> virtualenv for you, if pyenv built the Python
>
>
pyenv is not a 'global' package

there is a mountain of /root/.pyenv  files though
there is also quite a number of /root/.pyenv/plugins/pyenv-virtualenv/
files

when looking in the /root/.pyenv files I can find options for all the older
version of python
but none for anything newer than what is on my system

is there something else to install to achieve this 'version freedom' that
pyenv promises?

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


Re: Help needed - - running into issues with python and its tools

2024-08-05 Thread o1bigtenor via Python-list
On Mon, Aug 5, 2024 at 3:55 PM Bill Deegan 
wrote:

> Your approach is wrong.
> You don't build python from source using pip.
>
> You don't install new versions of python into a venv either.
>
> Have you read the following?
> https://docs.micropython.org/en/latest/esp8266/tutorial/intro.html
>
> That seems to have instructions for what you want to do..
>

See item 1.4 - - - - that's where I'm at (and that's where the problems
are hidden at as well!)

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


Re: Help needed - - running into issues with python and its tools

2024-08-05 Thread Mats Wichmann via Python-list

On 8/5/24 14:39, o1bigtenor wrote:
Matt - if you would rather that you were not included in the address 
list - -

please advise.

On Mon, Aug 5, 2024 at 8:51 AM Mats Wichmann > wrote:


On 8/5/24 06:48, o1bigtenor via Python-list wrote:
 > On Sun, Aug 4, 2024 at 8:49 AM Mats Wichmann via Python-list <
 > python-list@python.org > wrote:
 >
 >> On 8/3/24 20:03, o1bigtenor via Python-list wrote:
 >>
 >>> My question was, is and will be (and the doc absolutely doesn't
cover it)
 >>> how do I install a different version in the venv so that python
3.11.x on
 >>> the
 >>> system is not discombobulated by the python 3.12.x in the venv.
 >>> That python 3.12 would let me run the tools needed.
 >>> (Its the how to install the next version of python that I just
haven't
 >> been
 >>> able to find information on - - - and I would be looking for
information
 >>> on how to install on a *nix.)
 >>
 >> To get a different Python "in" the venv, you use the version you
want in
 >> the construction of the venv. For example:
 >>
 >>
 >> $ python3.13 -m venv new_venv
 >> $ new_venv/bin/python --version
 >> Python 3.13.0b4
 >> $ source new_venv/bin/activate
 >>
 >>
 >   "https://peps.python.org/pep-0668/
 PEP 668, which prevents pip from
 > interacting with the OS installed python. This change has been
done in red
 > hat and other distros too . . . "
 >
 > similarly your first command produces and error code for the same
reason.
 >
 > Sorry - - - not my policy - - -

What? Yes, the *system* pip should have some restrictions, if it's a
system mainly managed by a package manager.

Setting up a venv is the *expected* approach to such situations, and
creating one doesn't cause any problems. You end up with a pip in the
activated venv that's going to install to a different path (the one in
the venv), and will not be marked as externally managed, as the package
manager has no control over that path.

That's the whole point.  What error are you getting?  The venv
module is
not the pip module so restrictions on the system pip have nothing to do
with it.

set up pyenv
activated a venv
trying to install python3.12 into it

1. download of python3.12 (blahblahblahetc).deb will not install
2. download of python3.12.tar.xz similarly will not install

(venv2) memyself@devuanbigbox:~$ pip install 
/home/memyself/Downloads/Python-3.12.4.tar.xz

Processing ./Downloads/Python-3.12.4.tar.xz
ERROR: file:///home/memyself/Downloads/Python-3.12.4.tar.xz does not 
appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' 
found.


seems that I need a different version (installable as it were) of 
python3.12

or my approach is all wrong!



you can't install Python "into" a venv.

you use a version of Python as the base when *creating* a venv, the venv 
will use the same binary as the base python (symlinks if possible, as in 
the Linux case), but with different paths.


Since you've already got pyenv, use it to build the version you want to 
use - I think you said there wasn't a deb for 3.12 in your distro? 
That's something like


pyenv install 3.12.4

that will use the build recipe it has... and hopefully work.  Distro 
Pythons sometimes have some strange setups that are hard to reproduce. 
Pyenv knows how to build micropython, too, should it ever come to that.


If you indeed found a deb for the right Python, use apt to install it, 
and then use *that* Python to create your venv.


If you have the pyenv-virtualenv plugin, you can ask it to make the 
virtualenv for you, if pyenv built the Python





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


Re: Help needed - - running into issues with python and its tools

2024-08-05 Thread Bill Deegan via Python-list
Your approach is wrong.
You don't build python from source using pip.

You don't install new versions of python into a venv either.

Have you read the following?
https://docs.micropython.org/en/latest/esp8266/tutorial/intro.html

That seems to have instructions for what you want to do..

-Bill



On Mon, Aug 5, 2024 at 1:41 PM o1bigtenor via Python-list <
python-list@python.org> wrote:

> Matt - if you would rather that you were not included in the address list -
> -
> please advise.
>
> On Mon, Aug 5, 2024 at 8:51 AM Mats Wichmann  wrote:
>
> > On 8/5/24 06:48, o1bigtenor via Python-list wrote:
> > > On Sun, Aug 4, 2024 at 8:49 AM Mats Wichmann via Python-list <
> > > python-list@python.org> wrote:
> > >
> > >> On 8/3/24 20:03, o1bigtenor via Python-list wrote:
> > >>
> > >>> My question was, is and will be (and the doc absolutely doesn't cover
> > it)
> > >>> how do I install a different version in the venv so that python
> 3.11.x
> > on
> > >>> the
> > >>> system is not discombobulated by the python 3.12.x in the venv.
> > >>> That python 3.12 would let me run the tools needed.
> > >>> (Its the how to install the next version of python that I just
> haven't
> > >> been
> > >>> able to find information on - - - and I would be looking for
> > information
> > >>> on how to install on a *nix.)
> > >>
> > >> To get a different Python "in" the venv, you use the version you want
> in
> > >> the construction of the venv. For example:
> > >>
> > >>
> > >> $ python3.13 -m venv new_venv
> > >> $ new_venv/bin/python --version
> > >> Python 3.13.0b4
> > >> $ source new_venv/bin/activate
> > >>
> > >>
> > >   "https://peps.python.org/pep-0668/ PEP 668, which prevents pip from
> > > interacting with the OS installed python. This change has been done in
> > red
> > > hat and other distros too . . . "
> > >
> > > similarly your first command produces and error code for the same
> reason.
> > >
> > > Sorry - - - not my policy - - -
> >
> > What? Yes, the *system* pip should have some restrictions, if it's a
> > system mainly managed by a package manager.
> >
> > Setting up a venv is the *expected* approach to such situations, and
> > creating one doesn't cause any problems. You end up with a pip in the
> > activated venv that's going to install to a different path (the one in
> > the venv), and will not be marked as externally managed, as the package
> > manager has no control over that path.
> >
> > That's the whole point.  What error are you getting?  The venv module is
> > not the pip module so restrictions on the system pip have nothing to do
> > with it.
> >
> > set up pyenv
> activated a venv
> trying to install python3.12 into it
>
> 1. download of python3.12 (blahblahblahetc).deb will not install
> 2. download of python3.12.tar.xz similarly will not install
>
> (venv2) memyself@devuanbigbox:~$ pip install
> /home/memyself/Downloads/Python-3.12.4.tar.xz
> Processing ./Downloads/Python-3.12.4.tar.xz
> ERROR: file:///home/memyself/Downloads/Python-3.12.4.tar.xz does not appear
> to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.
>
> seems that I need a different version (installable as it were) of
> python3.12
> or my approach is all wrong!
>
> Please advise
>
> TIA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help needed - - running into issues with python and its tools

2024-08-05 Thread o1bigtenor via Python-list
Matt - if you would rather that you were not included in the address list -
-
please advise.

On Mon, Aug 5, 2024 at 8:51 AM Mats Wichmann  wrote:

> On 8/5/24 06:48, o1bigtenor via Python-list wrote:
> > On Sun, Aug 4, 2024 at 8:49 AM Mats Wichmann via Python-list <
> > python-list@python.org> wrote:
> >
> >> On 8/3/24 20:03, o1bigtenor via Python-list wrote:
> >>
> >>> My question was, is and will be (and the doc absolutely doesn't cover
> it)
> >>> how do I install a different version in the venv so that python 3.11.x
> on
> >>> the
> >>> system is not discombobulated by the python 3.12.x in the venv.
> >>> That python 3.12 would let me run the tools needed.
> >>> (Its the how to install the next version of python that I just haven't
> >> been
> >>> able to find information on - - - and I would be looking for
> information
> >>> on how to install on a *nix.)
> >>
> >> To get a different Python "in" the venv, you use the version you want in
> >> the construction of the venv. For example:
> >>
> >>
> >> $ python3.13 -m venv new_venv
> >> $ new_venv/bin/python --version
> >> Python 3.13.0b4
> >> $ source new_venv/bin/activate
> >>
> >>
> >   "https://peps.python.org/pep-0668/ PEP 668, which prevents pip from
> > interacting with the OS installed python. This change has been done in
> red
> > hat and other distros too . . . "
> >
> > similarly your first command produces and error code for the same reason.
> >
> > Sorry - - - not my policy - - -
>
> What? Yes, the *system* pip should have some restrictions, if it's a
> system mainly managed by a package manager.
>
> Setting up a venv is the *expected* approach to such situations, and
> creating one doesn't cause any problems. You end up with a pip in the
> activated venv that's going to install to a different path (the one in
> the venv), and will not be marked as externally managed, as the package
> manager has no control over that path.
>
> That's the whole point.  What error are you getting?  The venv module is
> not the pip module so restrictions on the system pip have nothing to do
> with it.
>
> set up pyenv
activated a venv
trying to install python3.12 into it

1. download of python3.12 (blahblahblahetc).deb will not install
2. download of python3.12.tar.xz similarly will not install

(venv2) memyself@devuanbigbox:~$ pip install
/home/memyself/Downloads/Python-3.12.4.tar.xz
Processing ./Downloads/Python-3.12.4.tar.xz
ERROR: file:///home/memyself/Downloads/Python-3.12.4.tar.xz does not appear
to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.

seems that I need a different version (installable as it were) of
python3.12
or my approach is all wrong!

Please advise

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


Re: Help needed - - running into issues with python and its tools

2024-08-05 Thread Mats Wichmann via Python-list

On 8/5/24 06:48, o1bigtenor via Python-list wrote:

On Sun, Aug 4, 2024 at 8:49 AM Mats Wichmann via Python-list <
python-list@python.org> wrote:


On 8/3/24 20:03, o1bigtenor via Python-list wrote:


My question was, is and will be (and the doc absolutely doesn't cover it)
how do I install a different version in the venv so that python 3.11.x on
the
system is not discombobulated by the python 3.12.x in the venv.
That python 3.12 would let me run the tools needed.
(Its the how to install the next version of python that I just haven't

been

able to find information on - - - and I would be looking for information
on how to install on a *nix.)


To get a different Python "in" the venv, you use the version you want in
the construction of the venv. For example:


$ python3.13 -m venv new_venv
$ new_venv/bin/python --version
Python 3.13.0b4
$ source new_venv/bin/activate



  "https://peps.python.org/pep-0668/ PEP 668, which prevents pip from
interacting with the OS installed python. This change has been done in red
hat and other distros too . . . "

similarly your first command produces and error code for the same reason.

Sorry - - - not my policy - - -


What? Yes, the *system* pip should have some restrictions, if it's a 
system mainly managed by a package manager.


Setting up a venv is the *expected* approach to such situations, and 
creating one doesn't cause any problems. You end up with a pip in the 
activated venv that's going to install to a different path (the one in 
the venv), and will not be marked as externally managed, as the package 
manager has no control over that path.


That's the whole point.  What error are you getting?  The venv module is 
not the pip module so restrictions on the system pip have nothing to do 
with it.




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


Re: Help needed - - running into issues with python and its tools

2024-08-05 Thread o1bigtenor via Python-list
On Sun, Aug 4, 2024 at 8:49 AM Mats Wichmann via Python-list <
python-list@python.org> wrote:

> On 8/3/24 20:03, o1bigtenor via Python-list wrote:
>
> > My question was, is and will be (and the doc absolutely doesn't cover it)
> > how do I install a different version in the venv so that python 3.11.x on
> > the
> > system is not discombobulated by the python 3.12.x in the venv.
> > That python 3.12 would let me run the tools needed.
> > (Its the how to install the next version of python that I just haven't
> been
> > able to find information on - - - and I would be looking for information
> > on how to install on a *nix.)
>
> To get a different Python "in" the venv, you use the version you want in
> the construction of the venv. For example:
>
>
> $ python3.13 -m venv new_venv
> $ new_venv/bin/python --version
> Python 3.13.0b4
> $ source new_venv/bin/activate
>
>
 "https://peps.python.org/pep-0668/ PEP 668, which prevents pip from
interacting with the OS installed python. This change has been done in red
hat and other distros too . . . "

similarly your first command produces and error code for the same reason.

Sorry - - - not my policy - - -

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


Re: Help needed - - running into issues with python and its tools

2024-08-05 Thread o1bigtenor via Python-list
On Sun, Aug 4, 2024 at 4:24 AM Peter J. Holzer via Python-list <
python-list@python.org> wrote:

> On 2024-08-03 15:17:11 -0500, o1bigtenor via Python-list wrote:
> > One of the tools I need to be able to use is esptools - -  well in the
> > devuan world you need to run that on either Devaun 3 or 5 - - - its just
> > not available on devuan 4.
>
> Couldn't you just upgrade to Devuan 5, then?
>

I like uptime and not measured in hours either so I'm presently not running
Devuan 5
or testing - - - although I used to. Just found that I didn't need the most
recent versions
of most of the tools I was using so find the stability (except for the
bloody browsers)
in stable version is to be appreciated.

>
>
> > Tried installing all the tools I need using downloads and .deb installs
> but
> > then I need to have python3.12 and that's also not part of Devuan4.
>
> It seems weird that something would work with the (presumably) older
> version of Python in Devuan 3 and the (presumably) newer version of
> Python in Devuan 5, but not with the version in Devuan 4.
>

Well - - - pstool was available in a version that worked in Devuan 3,
psytool is available in a version that works in Devuan 4 - - - beyond my
pay
grade as to why there isn't a version available for Devuan 4.

>
>
> > Not versed enough to set up a good venv (if that's possible) so that I
> > could work in that specific venv and have my cake (and get to eat it too
> > (grin!).
>
> You need to install Python first to create a venv. AFAIK there is no way
> to set up a venv first and then install Python into it.
>
> Does Devuan have a testing or unstable suite? You might be able to
> install a newer Python version from that. If not your best bet is to
> install Python from source.
>
>
First question answered earlier.
If I installed python 3.12 from source I would create a hung system for
myself.
(Been there and done that - - - got the T-shirt and it still stinks!)

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


Re: Help needed - - running into issues with python and its tools

2024-08-04 Thread Mats Wichmann via Python-list

On 8/3/24 20:03, o1bigtenor via Python-list wrote:


My question was, is and will be (and the doc absolutely doesn't cover it)
how do I install a different version in the venv so that python 3.11.x on
the
system is not discombobulated by the python 3.12.x in the venv.
That python 3.12 would let me run the tools needed.
(Its the how to install the next version of python that I just haven't been
able to find information on - - - and I would be looking for information
on how to install on a *nix.)


To get a different Python "in" the venv, you use the version you want in 
the construction of the venv. For example:



$ python3.13 -m venv new_venv
$ new_venv/bin/python --version
Python 3.13.0b4
$ source new_venv/bin/activate
...




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


Re: Help needed - - running into issues with python and its tools

2024-08-04 Thread Peter J. Holzer via Python-list
On 2024-08-03 15:17:11 -0500, o1bigtenor via Python-list wrote:
> One of the tools I need to be able to use is esptools - -  well in the
> devuan world you need to run that on either Devaun 3 or 5 - - - its just
> not available on devuan 4.

Couldn't you just upgrade to Devuan 5, then?


> Tried installing all the tools I need using downloads and .deb installs but
> then I need to have python3.12 and that's also not part of Devuan4.

It seems weird that something would work with the (presumably) older
version of Python in Devuan 3 and the (presumably) newer version of
Python in Devuan 5, but not with the version in Devuan 4.


> Not versed enough to set up a good venv (if that's possible) so that I
> could work in that specific venv and have my cake (and get to eat it too
> (grin!).

You need to install Python first to create a venv. AFAIK there is no way
to set up a venv first and then install Python into it.

Does Devuan have a testing or unstable suite? You might be able to
install a newer Python version from that. If not your best bet is to
install Python from source.

hp


-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help needed - - running into issues with python and its tools

2024-08-03 Thread o1bigtenor via Python-list
On Sat, Aug 3, 2024 at 7:11 PM dn via Python-list 
wrote:

> On 4/08/24 09:34, o1bigtenor via Python-list wrote:
> > On Sat, Aug 3, 2024 at 4:06 PM dn via Python-list <
> python-list@python.org>
> > wrote:
> >
> >> On 4/08/24 08:17, o1bigtenor via Python-list wrote:
> >>> Greetings
> >>>
> >>> Looking at ESP8266 and wanting to program it using micropython (really
> >>> don't want to have to learn C++ (not enough hours in the day as it
> >> is!!)).
> >>>
> >>> One of the tools I need to be able to use is esptools - -  well in the
> >>> devuan world you need to run that on either Devaun 3 or 5 - - - its
> just
> >>> not available on devuan 4.
> >>>
> >>> Tried installing all the tools I need using downloads and .deb installs
> >> but
> >>> then I need to have python3.12 and that's also not part of Devuan4.
> >>>
> >>> Not versed enough to set up a good venv (if that's possible) so that I
> >>> could work in that specific venv and have my cake (and get to eat it
> too
> >>> (grin!).
> >>>
> >>> Suggestions - - - ideas - - - please?
> >>
> >> Sorry if this offends, but this is a list of short-cuts and reasons why
> >> they don't work (immediately).
> >>
> >>
> >> Have just come from a discussion about 'how to start a project'. Amongst
> >> the questions to ask are: "what resources do we have (or can add) to
> >> achieve?".
> >>
> >
> > Fair question details interleaved - - -
> >
> >>
> >> In this case, if Python-skill is a "personnel-resource" (and C++ a
> >> "constraint"), will question the ESP over Raspberry Pi (say)?
> >>
> >
> > Well - - - RPi world technical specs is usable from -20 to 60 C (iirc on
> > the top number)
> > and for my project I absolutely need to have usability to at least -40 -
> -
> > could possibly do a bit less but -35 C is a hard requirement so the RPi
> > and Pico (which I would like to use) is out but ESP8266 runs in that -40
> to
> > 65 C
> > range.
>
> Interesting, but creates a mis-match of tools - battles for you to fight...
>

Not really - - - it takes a computer with psytool and about 5 or 6 other
python3.12
programs to load the microcontroller.
It is in writing the program for the microcontroller that micropython is
used not at
all in the loading.

>
>
> >> Why talking of Python 3.12 when the solution involves MicroPython?
> >>
> >
> > Because one uses psytool on one computer to transfer a program to the
> > MicroPython system.  In fact there are a set of tools that need
> Python3.12
> > to be able to do this and therefore the question.
> >
> >>
> >>
> >> Perhaps need to take a step back and look at 'options' - relate needs to
> >> resources, and evaluate the impact of each decision on later ones - as
> >> well as against your personal skills (modify objectives to limits, or
> >> accept that some learning/training will be necessary as pre-requisite to
> >> (being able to) attack the project).
> >>
> >> I have been investigating using a venv but am not finding clear
> directions
> > so
> > that I could set up Python3.12 inside (along with the other needed
> tools).
> > The
> > more I'm looking the less useful most of the information I'm finding is
> > becoming.
> > Therefore I thought I would go to the python gurus for information - - -
> > which I
> > have.
> >
> > So please - - - how do I set up a venv so that I can install and run
> python
> > 3.12
> > (and other needed programs related to 3.12) inside?
>
> If you mean venv itself, which "directions" have you reviewed?
> This one (https://python.land/virtual-environments/virtualenv) seems
> very straight-forward and shows "What's inside a venv?" to include
> python.exe. Given that venv is more-or-less the official/traditional
> solution, what are you doing differently - perhaps the question is
> lacking detail.
>
> Interesting - - - that's the doc I have been reading.

My question was, is and will be (and the doc absolutely doesn't cover it)
how do I install a different version in the venv so that python 3.11.x on
the
system is not discombobulated by the python 3.12.x in the venv.
That python 3.12 would let me run the tools needed.
(Its the how to install the next version of python that I just haven't been
able to find information on - - - and I would be looking for information
on how to install on a *nix.)


> Personally, I'm using Poetry (https://python-poetry.org) which seemed
> just as easy to pick-up; plus pyenv to maintain multiple versions of
> Python on one machine.
>
>
Will give python-poetry a look.

Have been looking at pyenv but that seems to be a whole rat's nest of other
stuff to install and its using a bunch of different tools to get there - -
- is it
necessary - - - yes or no (in the running of multiple python versions on
the
same machine).

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


Re: Help needed - - running into issues with python and its tools

2024-08-03 Thread o1bigtenor via Python-list
On Sat, Aug 3, 2024 at 6:20 PM Cameron Simpson via Python-list <
python-list@python.org> wrote:

> On 03Aug2024 16:34, o1bigtenor  wrote:
> >So please - - - how do I set up a venv so that I can install and run
> >python
> >3.12
> >(and other needed programs related to 3.12) inside?
>
> Maybe this github comment will help with this:
>
> https://github.com/orgs/micropython/discussions/10255#discussioncomment-671
>

Not really.

A computer that has psytool + about 5 or 6 other python 3.12 tools is
needed to load
the microcontroller so I don't see how having venv in the microcontroller
would help the
loading of software onto the microcontroller.

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


Re: Help needed - - running into issues with python and its tools

2024-08-03 Thread dn via Python-list

On 4/08/24 09:34, o1bigtenor via Python-list wrote:

On Sat, Aug 3, 2024 at 4:06 PM dn via Python-list 
wrote:


On 4/08/24 08:17, o1bigtenor via Python-list wrote:

Greetings

Looking at ESP8266 and wanting to program it using micropython (really
don't want to have to learn C++ (not enough hours in the day as it

is!!)).


One of the tools I need to be able to use is esptools - -  well in the
devuan world you need to run that on either Devaun 3 or 5 - - - its just
not available on devuan 4.

Tried installing all the tools I need using downloads and .deb installs

but

then I need to have python3.12 and that's also not part of Devuan4.

Not versed enough to set up a good venv (if that's possible) so that I
could work in that specific venv and have my cake (and get to eat it too
(grin!).

Suggestions - - - ideas - - - please?


Sorry if this offends, but this is a list of short-cuts and reasons why
they don't work (immediately).


Have just come from a discussion about 'how to start a project'. Amongst
the questions to ask are: "what resources do we have (or can add) to
achieve?".



Fair question details interleaved - - -



In this case, if Python-skill is a "personnel-resource" (and C++ a
"constraint"), will question the ESP over Raspberry Pi (say)?



Well - - - RPi world technical specs is usable from -20 to 60 C (iirc on
the top number)
and for my project I absolutely need to have usability to at least -40 - -
could possibly do a bit less but -35 C is a hard requirement so the RPi
and Pico (which I would like to use) is out but ESP8266 runs in that -40 to
65 C
range.


Interesting, but creates a mis-match of tools - battles for you to fight...



Why talking of Python 3.12 when the solution involves MicroPython?



Because one uses psytool on one computer to transfer a program to the
MicroPython system.  In fact there are a set of tools that need Python3.12
to be able to do this and therefore the question.




Perhaps need to take a step back and look at 'options' - relate needs to
resources, and evaluate the impact of each decision on later ones - as
well as against your personal skills (modify objectives to limits, or
accept that some learning/training will be necessary as pre-requisite to
(being able to) attack the project).

I have been investigating using a venv but am not finding clear directions

so
that I could set up Python3.12 inside (along with the other needed tools).
The
more I'm looking the less useful most of the information I'm finding is
becoming.
Therefore I thought I would go to the python gurus for information - - -
which I
have.

So please - - - how do I set up a venv so that I can install and run python
3.12
(and other needed programs related to 3.12) inside?


If you mean venv itself, which "directions" have you reviewed?
This one (https://python.land/virtual-environments/virtualenv) seems 
very straight-forward and shows "What's inside a venv?" to include 
python.exe. Given that venv is more-or-less the official/traditional 
solution, what are you doing differently - perhaps the question is 
lacking detail.

(see also @Cameron's take)

Personally, I'm using Poetry (https://python-poetry.org) which seemed 
just as easy to pick-up; plus pyenv to maintain multiple versions of 
Python on one machine.


--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Help needed - - running into issues with python and its tools

2024-08-03 Thread Cameron Simpson via Python-list

On 03Aug2024 16:34, o1bigtenor  wrote:
So please - - - how do I set up a venv so that I can install and run 
python

3.12
(and other needed programs related to 3.12) inside?


Maybe this github comment will help with this:
https://github.com/orgs/micropython/discussions/10255#discussioncomment-671
--
https://mail.python.org/mailman/listinfo/python-list


Re: Help needed - - running into issues with python and its tools

2024-08-03 Thread o1bigtenor via Python-list
On Sat, Aug 3, 2024 at 4:06 PM dn via Python-list 
wrote:

> On 4/08/24 08:17, o1bigtenor via Python-list wrote:
> > Greetings
> >
> > Looking at ESP8266 and wanting to program it using micropython (really
> > don't want to have to learn C++ (not enough hours in the day as it
> is!!)).
> >
> > One of the tools I need to be able to use is esptools - -  well in the
> > devuan world you need to run that on either Devaun 3 or 5 - - - its just
> > not available on devuan 4.
> >
> > Tried installing all the tools I need using downloads and .deb installs
> but
> > then I need to have python3.12 and that's also not part of Devuan4.
> >
> > Not versed enough to set up a good venv (if that's possible) so that I
> > could work in that specific venv and have my cake (and get to eat it too
> > (grin!).
> >
> > Suggestions - - - ideas - - - please?
>
> Sorry if this offends, but this is a list of short-cuts and reasons why
> they don't work (immediately).
>
>
> Have just come from a discussion about 'how to start a project'. Amongst
> the questions to ask are: "what resources do we have (or can add) to
> achieve?".
>

Fair question details interleaved - - -

>
> In this case, if Python-skill is a "personnel-resource" (and C++ a
> "constraint"), will question the ESP over Raspberry Pi (say)?
>

Well - - - RPi world technical specs is usable from -20 to 60 C (iirc on
the top number)
and for my project I absolutely need to have usability to at least -40 - -
could possibly do a bit less but -35 C is a hard requirement so the RPi
and Pico (which I would like to use) is out but ESP8266 runs in that -40 to
65 C
range.

>
> Why talking of Python 3.12 when the solution involves MicroPython?
>

Because one uses psytool on one computer to transfer a program to the
MicroPython system.  In fact there are a set of tools that need Python3.12
to be able to do this and therefore the question.

>
>
> Perhaps need to take a step back and look at 'options' - relate needs to
> resources, and evaluate the impact of each decision on later ones - as
> well as against your personal skills (modify objectives to limits, or
> accept that some learning/training will be necessary as pre-requisite to
> (being able to) attack the project).
>
> I have been investigating using a venv but am not finding clear directions
so
that I could set up Python3.12 inside (along with the other needed tools).
The
more I'm looking the less useful most of the information I'm finding is
becoming.
Therefore I thought I would go to the python gurus for information - - -
which I
have.

So please - - - how do I set up a venv so that I can install and run python
3.12
(and other needed programs related to 3.12) inside?

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


Re: Help needed - - running into issues with python and its tools

2024-08-03 Thread dn via Python-list

On 4/08/24 08:17, o1bigtenor via Python-list wrote:

Greetings

Looking at ESP8266 and wanting to program it using micropython (really
don't want to have to learn C++ (not enough hours in the day as it is!!)).

One of the tools I need to be able to use is esptools - -  well in the
devuan world you need to run that on either Devaun 3 or 5 - - - its just
not available on devuan 4.

Tried installing all the tools I need using downloads and .deb installs but
then I need to have python3.12 and that's also not part of Devuan4.

Not versed enough to set up a good venv (if that's possible) so that I
could work in that specific venv and have my cake (and get to eat it too
(grin!).

Suggestions - - - ideas - - - please?


Sorry if this offends, but this is a list of short-cuts and reasons why 
they don't work (immediately).



Have just come from a discussion about 'how to start a project'. Amongst 
the questions to ask are: "what resources do we have (or can add) to 
achieve?".


In this case, if Python-skill is a "personnel-resource" (and C++ a 
"constraint"), will question the ESP over Raspberry Pi (say)?


Why talking of Python 3.12 when the solution involves MicroPython?


Perhaps need to take a step back and look at 'options' - relate needs to 
resources, and evaluate the impact of each decision on later ones - as 
well as against your personal skills (modify objectives to limits, or 
accept that some learning/training will be necessary as pre-requisite to 
(being able to) attack the project).


--
Regards =dn

--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


Help needed - - running into issues with python and its tools

2024-08-03 Thread o1bigtenor via Python-list
Greetings

Looking at ESP8266 and wanting to program it using micropython (really
don't want to have to learn C++ (not enough hours in the day as it is!!)).

One of the tools I need to be able to use is esptools - -  well in the
devuan world you need to run that on either Devaun 3 or 5 - - - its just
not available on devuan 4.

Tried installing all the tools I need using downloads and .deb installs but
then I need to have python3.12 and that's also not part of Devuan4.

Not versed enough to set up a good venv (if that's possible) so that I
could work in that specific venv and have my cake (and get to eat it too
(grin!).

Suggestions - - - ideas - - - please?

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


Re: Help Needed With a Python Gaming Module

2024-04-03 Thread Thomas Passin via Python-list

On 4/3/2024 3:06 PM, WordWeaver Evangelist via Python-list wrote:

Hello everyone! It has been a l-o-n-g time -- nine years in fact --since I last 
participated on this mailing list.


[snip]

3. You are very familiar with the Jython 2 environment, which I am told is 
based on Python 2 and NOT Python 3.


Yes, Jython 2 is currently more or less even with Python 2.7.

You are presumably writing or hosting this in a java environment, and 
you may not realize that you can call Jython code from a java class 
(calling java classes from Jython code is dead simple).  For example, I 
have some java servlet classes that invoke Jython classes and call their 
methods.  If that sounds useful for your project, I can let you know how 
to do it.


[more snips...]

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


Help Needed With a Python Gaming Module

2024-04-03 Thread WordWeaver Evangelist via Python-list
Hello everyone! It has been a l-o-n-g time -- nine years in fact --since I last 
participated on this mailing list.

At that time, I was trying to write a door/external for my PC-ANSI, 
Macintosh-based BBS. Thanks to some of the folks here, I got it done  
although I eventually lost the module a number of years later when I left 
BBSing behind, because I assumed it to be dead.

Anyway, just recently I put my BBS back online again for the fourth time since 
1993, and I am again endeavoring to write a new python-based external -- a game 
-- for my BBS.

Before I continue, let me inform you that I am 70 years old, I am NOT a 
programmer, and I do not know any programming languages. Yes, I am a newbie, a 
noob, a greenhorn. :) So, if anyone here is willing to help me, you are going 
to need a lot of patience . like ChatGPT :)

Following the coding example of another open-source external that was written 
for my BBS, I have made some significant progress, thanks in large part to 
spending hours and hours chatting with ChatGPT over the past two days.

However, due my lack of expertise, and even though ChatGPT had me try all sorts 
of functions and codes and methods, there is one very perplexing issue which 
has prevented me from further development on my game. Even ChatGPT couldn't 
figure it out.

But before I get into the meat of the matter and waste everyone's time here, I 
need to address several questions to all of you Python brainiacs. )

Is there anyone -- or any group of someones -- amongst this noble assemblage, 
who meets all of the following qualifications:

1. You are very familiar with Mac OS 9.2.2

2. You are either moderately or very familiar with Hermes II BBS software.

3. You are very familiar with the Jython 2 environment, which I am told is 
based on Python 2 and NOT Python 3.

If you meet all three of those qualifications, then you may possibly be able to 
help me to overcome the mysterious obstacle I am now facing. Once I see what 
kind of responses I get, I will be very happy to share my nagging problem with 
you.

Thank you for taking the time to read this. Here is to hoping that my coding 
genius is out there, ready and eager to come to my aid.

Thank you in advance.

Kind regads,

Bill Kochman

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


HELP NEEDED application error 0xc000005

2019-09-25 Thread arshad ali via Python-list
Note: Forwarded message attached

-- Original Message --

From: "arshad ali"arsh...@rediffmail.com
To: python-list@python.org
Subject: HELP  NEEDED application error 0xc05--- Begin Message ---
Respected sir,
  In my laptop with windows 7 ultimate 64 bit, when python 3.7.4  
executable 64 bit installed 
it is giving me the error " THE APPLICATION WAS UNABLE TO START CORRECTLY 
(0xc005) CLICK OK TO CLOSE" 
I tried many times.

But python 2.7.16 is working in my laptop.

please help me in getting out of this error for which i will be highly grateful 
to you.

Dr. Arshad
Hyderabad, INDIA--- End Message ---
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help needed urgently for running some code!!!!

2019-09-03 Thread Joel Goldstick
On Tue, Sep 3, 2019 at 1:38 PM Dennis Lee Bieber  wrote:
>
> On Mon, 2 Sep 2019 08:05:14 -0700 (PDT), Spencer Du
>  declaimed the following:
>
> >Hi
> >
> >I want to execute
> >
> >"from devicesEmbedded import *": in GUI.py after all code in GUI.py is run. 
> >Also how do I make the devicesEmbedded.py reload and run when a txt file is 
> >created in the name of "list_of_devices.txt" in the GUI.py python program.
> >
> Reload is one of the least effective features. Especially when you 
> have
> bound names locally within modules. "... import *" binds names locally.
> Reloading a changed module creates a new module entry in Python's run-time,
> but any local names still refer to the old module contents.
>
> Please consider reading the documentation:
> https://docs.python.org/3/library/importlib.html
>
> """
>  importlib.reload(module)
>
> Reload a previously imported module. The argument must be a module
> object, so it must have been successfully imported before. This is useful
> if you have edited the module source file using an external editor and want
> to try out the new version without leaving the Python interpreter. The
> return value is the module object (which can be different if re-importing
> causes a different object to be placed in sys.modules).
>
> When reload() is executed:
>
> Python module’s code is recompiled and the module-level code
> re-executed, defining a new set of objects which are bound to names in the
> module’s dictionary by reusing the loader which originally loaded the
> module. The init function of extension modules is not called a second time.
>
> As with all other objects in Python the old objects are only
> reclaimed after their reference counts drop to zero.
>
> The names in the module namespace are updated to point to any new
> or changed objects.
>
> Other references to the old objects (such as names external to the
> module) are not rebound to refer to the new objects and must be updated in
> each namespace where they occur if that is desired.
> """
>
> NOTE the last paragraph. This means you should NOT be using "... import *"
> syntax for anything you might want to have reloaded. Instead use "import
> modulename" and everywhere you access something in that module use the long
> form "modulename.something". This way, when it is reloaded, "modulename"
> will reference the new contents.
>
>
> As for detecting file changes... You will have to periodically check
> the time-stamp (modification time) of the file, and if it changes, reread
> the file.
>
>
>
>
>
> --
> Wulfraed Dennis Lee Bieber AF6VN
> wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
>
> --
> https://mail.python.org/mailman/listinfo/python-list

Spencer, for the past month (almost) you have been sending "urgent"
requests for people here to write code for you.  You've already
decided what needs to be done, but you haven't really explained what
you want to do.  You don't respond to other's responses for further
clarification, or with your progress.  You basically repeat the same
urgent request.  Please don't do this.  There are many python experts
here who will help you, but getting someone to write your code for you
when you can't really explain what your goal is will get you nowhere,
especially since you claim this is for your job.

To me, its an odd thing to want to do imports depending on a file's
contents.  But maybe its a good idea.  However, you can just import
all of the modules you might expect to need, and ignore if they aren't
present with a suitable try/except block.   Try explaining the bigger
picture of what you are trying to do, and maybe you can gain some
incite into a better way of proceeding.  I'm afraid it looks like you
have been cutting and pasting without understanding what your code's
design is all about.  I could be totally wrong.  good luck

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help needed to run some code!!!!

2019-09-03 Thread Calvin Spealman
It sounds like you have module-level behavior you don't want to happen
during normal import-time. If that is the case, move that behavior into a
class or function you can invoke at the correct time, rather than trying to
do your imports at strange times.

On Mon, Sep 2, 2019 at 11:50 AM Spencer Du  wrote:

> Hi
>
> How can I execute "from devicesEmbedded import *" after this:
> "print("Device added to list")" in GUI.py because currently if I have the
> import added at the top of GUI.py file it always executes first before the
> GUI.py file is executed. I want the devicesEmbedded.py to execute after
> GUI.py has executed first.
>
> Thanks
> Spencer
>
> GUI.py
>
> import logging
> from datetime import timedelta
> import time
> from thespian.actors import *
> from transitions import Machine
> import paho.mqtt.client as mqtt
> import importlib
> import os
> import os.path
> import sys
> from PyQt5.QtWidgets import *
> from PyQt5.QtCore import *
> from PyQt5 import QtWidgets, uic
> from mqtt import *
> # from devicesEmbedded import *
> import json
>
> class MainWindow(QtWidgets.QMainWindow):
> def __init__(self,parent = None):
> QMainWindow.__init__(self)
> super(MainWindow, self).__init__(parent)
> self.mdi = QMdiArea()
> self.setCentralWidget(self.mdi)
>
> self.setMinimumSize(QSize(800, 600))
> self.setWindowTitle("PyQt button example -
> pythonprogramminglanguage.com")
>
> pybutton = QPushButton('Add device', self)
>
> pybutton.clicked.connect(self.importbutton)
>
> pybutton.move(100, 400)
> pybutton.resize(150, 32)
>
> self.textbox = QLineEdit(self)
> self.textbox.move(100,350)
> self.textbox.resize(100, 32)
>
> self.fileName_UI = ""
>
> def importbutton(self):
> self.fileName_UI = self.textbox.text()
> self.loadGUI()
>
> def getGUIFilename(self):
> return self.fileName_UI
>
> def loadGUI(self):
> print("Searching file", self.fileName_UI)
> try:
> module = __import__(self.fileName_UI)
> my_class = getattr(module, "SubWindow")
>
> sub = QMdiSubWindow()
>
> sub.setWidget(my_class())
> sub.setWindowTitle("New GUI:  " + self.fileName_UI)
> self.mdi.addSubWindow(sub)
> sub.show()
>
> print("creating new instance " + self.fileName_UI)
> client = device("Device")
> client.run()
>
> client.loop_start()  # start the loop
> # device_message = self.fileName_UI
> time.sleep(2)
> print("Subscribing to topic",
> "microscope/light_sheet_microscope/UI")
> client.subscribe("microscope/light_sheet_microscope/UI")
> print("Publishing message to topic",
> "microscope/light_sheet_microscope/UI/list_of_devices")
>
> client.publish("microscope/light_sheet_microscope/UI/list_of_devices",
> json.dumps({"type": "device", "payload":{"name": self.fileName_UI, "cmd":
> "adding device"}}, indent=2))
> time.sleep(1)  # wait
> client.loop_stop()  # stop the loop
> print("Device added" + "\n")
>
> client.run()
> client.loop_start()
> time.sleep(2)
> print("Subscribing to topic",
> "microscope/light_sheet_microscope/UI/list_of_devices")
>
> client.subscribe("microscope/light_sheet_microscope/UI/list_of_devices")
> print("Publishing message to topic",
> "microscope/light_sheet_microscope/UI/list_of_devices")
>
> client.publish("microscope/light_sheet_microscope/UI/list_of_devices",
> self.fileName_UI + " added to device list")
> time.sleep(1)
> client.loop_stop()
>
> listofdevices = []
> listofdevices.append(self.fileName_UI)
> with open("list_of_devices.txt", "a+") as myfile:
> for item in listofdevices:
> myfile.write(item + ",")
>
>
> print(item)
> print(listofdevices)
> print("Device added to list")
> except:
> print("creating new instance " + self.fileName_UI)
> client = device("Device")
> client.run()
>
> client.loop_start()  # start the loop
> device_message = self.fileName_UI
> time.sleep(2)
> print("Subscribing to topic",
> "microscope/light_sheet_microscope/UI")
> client.subscribe("microscope/light_sheet_microscope/UI")
> print("Publishing message to topic",
> "microscope/light_sheet_microscope/UI")
> client.publish("microscope/light_sheet_microscope/UI",
> json.dumps({"type": "device", "payload":{"name": self.fileName_UI}},
> indent=2))
> time.sleep(2)  # wait
> client.loop_stop()  # stop the loop
> print(device_message + ".py " + "file doesn't exist")
> print("Device not a

Help needed to run some code!!!!

2019-09-02 Thread Spencer Du
Hi

How can I execute "from devicesEmbedded import *" after this: "print("Device 
added to list")" in GUI.py because currently if I have the import added at the 
top of GUI.py file it always executes first before the GUI.py file is executed. 
I want the devicesEmbedded.py to execute after GUI.py has executed first.

Thanks
Spencer

GUI.py 

import logging 
from datetime import timedelta 
import time 
from thespian.actors import * 
from transitions import Machine 
import paho.mqtt.client as mqtt 
import importlib 
import os 
import os.path 
import sys 
from PyQt5.QtWidgets import * 
from PyQt5.QtCore import * 
from PyQt5 import QtWidgets, uic 
from mqtt import * 
# from devicesEmbedded import * 
import json 

class MainWindow(QtWidgets.QMainWindow): 
def __init__(self,parent = None): 
QMainWindow.__init__(self) 
super(MainWindow, self).__init__(parent) 
self.mdi = QMdiArea() 
self.setCentralWidget(self.mdi) 

self.setMinimumSize(QSize(800, 600)) 
self.setWindowTitle("PyQt button example - 
pythonprogramminglanguage.com") 

pybutton = QPushButton('Add device', self) 

pybutton.clicked.connect(self.importbutton) 

pybutton.move(100, 400) 
pybutton.resize(150, 32) 

self.textbox = QLineEdit(self) 
self.textbox.move(100,350) 
self.textbox.resize(100, 32) 

self.fileName_UI = "" 

def importbutton(self): 
self.fileName_UI = self.textbox.text() 
self.loadGUI() 

def getGUIFilename(self): 
return self.fileName_UI 

def loadGUI(self): 
print("Searching file", self.fileName_UI)   
try: 
module = __import__(self.fileName_UI) 
my_class = getattr(module, "SubWindow") 

sub = QMdiSubWindow() 

sub.setWidget(my_class()) 
sub.setWindowTitle("New GUI:  " + self.fileName_UI) 
self.mdi.addSubWindow(sub) 
sub.show() 

print("creating new instance " + self.fileName_UI) 
client = device("Device") 
client.run() 

client.loop_start()  # start the loop 
# device_message = self.fileName_UI 
time.sleep(2) 
print("Subscribing to topic", 
"microscope/light_sheet_microscope/UI") 
client.subscribe("microscope/light_sheet_microscope/UI") 
print("Publishing message to topic", 
"microscope/light_sheet_microscope/UI/list_of_devices") 

client.publish("microscope/light_sheet_microscope/UI/list_of_devices", 
json.dumps({"type": "device", "payload":{"name": self.fileName_UI, "cmd": 
"adding device"}}, indent=2)) 
time.sleep(1)  # wait 
client.loop_stop()  # stop the loop 
print("Device added" + "\n") 

client.run() 
client.loop_start() 
time.sleep(2) 
print("Subscribing to topic", 
"microscope/light_sheet_microscope/UI/list_of_devices") 

client.subscribe("microscope/light_sheet_microscope/UI/list_of_devices") 
print("Publishing message to topic", 
"microscope/light_sheet_microscope/UI/list_of_devices") 

client.publish("microscope/light_sheet_microscope/UI/list_of_devices", 
self.fileName_UI + " added to device list") 
time.sleep(1) 
client.loop_stop() 

listofdevices = [] 
listofdevices.append(self.fileName_UI) 
with open("list_of_devices.txt", "a+") as myfile: 
for item in listofdevices: 
myfile.write(item + ",") 


print(item) 
print(listofdevices) 
print("Device added to list") 
except: 
print("creating new instance " + self.fileName_UI) 
client = device("Device") 
client.run() 

client.loop_start()  # start the loop 
device_message = self.fileName_UI 
time.sleep(2) 
print("Subscribing to topic", 
"microscope/light_sheet_microscope/UI") 
client.subscribe("microscope/light_sheet_microscope/UI") 
print("Publishing message to topic", 
"microscope/light_sheet_microscope/UI") 
client.publish("microscope/light_sheet_microscope/UI", 
json.dumps({"type": "device", "payload":{"name": self.fileName_UI}}, indent=2)) 
time.sleep(2)  # wait 
client.loop_stop()  # stop the loop 
print(device_message + ".py " + "file doesn't exist") 
print("Device not added") 
if __name__ == "__main__": 
app = QApplication(sys.argv) 
mainWin = MainWindow() 
a = mainWin.show() 
try: 
mainWin.show() 
os.remove("list_of_devices.txt") 
print("Awaiting devices to be launched") 
except: 
print("Awaiting devices to be launched") 
publishedMessage = mainWin.getGUIFilename() 

Help needed urgently for running some code!!!!

2019-09-02 Thread Spencer Du
Hi

I want to execute 

"from devicesEmbedded import *": in GUI.py after all code in GUI.py is run. 
Also how do I make the devicesEmbedded.py reload and run when a txt file is 
created in the name of "list_of_devices.txt" in the GUI.py python program.


GUI.py

import logging
from datetime import timedelta
import time
from thespian.actors import *
from transitions import Machine
import paho.mqtt.client as mqtt
import importlib
import os
import os.path
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5 import QtWidgets, uic
from mqtt import *
# from devicesEmbedded import *
import json

class MainWindow(QtWidgets.QMainWindow):
def __init__(self,parent = None):
QMainWindow.__init__(self)
super(MainWindow, self).__init__(parent)
self.mdi = QMdiArea()
self.setCentralWidget(self.mdi)

self.setMinimumSize(QSize(800, 600))
self.setWindowTitle("PyQt button example - 
pythonprogramminglanguage.com")

pybutton = QPushButton('Add device', self)

pybutton.clicked.connect(self.importbutton)

pybutton.move(100, 400)
pybutton.resize(150, 32)

self.textbox = QLineEdit(self)
self.textbox.move(100,350)
self.textbox.resize(100, 32)

self.fileName_UI = ""

def importbutton(self):
self.fileName_UI = self.textbox.text()
self.loadGUI()

def getGUIFilename(self):
return self.fileName_UI

def loadGUI(self):
print("Searching file", self.fileName_UI)   
try:
module = __import__(self.fileName_UI)
my_class = getattr(module, "SubWindow")

sub = QMdiSubWindow()

sub.setWidget(my_class())
sub.setWindowTitle("New GUI:  " + self.fileName_UI)
self.mdi.addSubWindow(sub)
sub.show()

print("creating new instance " + self.fileName_UI)
client = device("Device")
client.run()

client.loop_start()  # start the loop
# device_message = self.fileName_UI
time.sleep(2)
print("Subscribing to topic", 
"microscope/light_sheet_microscope/UI")
client.subscribe("microscope/light_sheet_microscope/UI")
print("Publishing message to topic", 
"microscope/light_sheet_microscope/UI/list_of_devices")

client.publish("microscope/light_sheet_microscope/UI/list_of_devices", 
json.dumps({"type": "device", "payload":{"name": self.fileName_UI, "cmd": 
"adding device"}}, indent=2))
time.sleep(1)  # wait
client.loop_stop()  # stop the loop
print("Device added" + "\n")

client.run()
client.loop_start()
time.sleep(2)
print("Subscribing to topic", 
"microscope/light_sheet_microscope/UI/list_of_devices")

client.subscribe("microscope/light_sheet_microscope/UI/list_of_devices")
print("Publishing message to topic", 
"microscope/light_sheet_microscope/UI/list_of_devices")

client.publish("microscope/light_sheet_microscope/UI/list_of_devices", 
self.fileName_UI + " added to device list")
time.sleep(1)
client.loop_stop()

listofdevices = []
listofdevices.append(self.fileName_UI)
with open("list_of_devices.txt", "a+") as myfile:
for item in listofdevices:
myfile.write(item + ",")


print(item)
print(listofdevices)
print("Device added to list")
except:
print("creating new instance " + self.fileName_UI)
client = device("Device")
client.run()

client.loop_start()  # start the loop
device_message = self.fileName_UI
time.sleep(2)
print("Subscribing to topic", 
"microscope/light_sheet_microscope/UI")
client.subscribe("microscope/light_sheet_microscope/UI")
print("Publishing message to topic", 
"microscope/light_sheet_microscope/UI")
client.publish("microscope/light_sheet_microscope/UI", 
json.dumps({"type": "device", "payload":{"name": self.fileName_UI}}, indent=2))
time.sleep(2)  # wait
client.loop_stop()  # stop the loop
print(device_message + ".py " + "file doesn't exist")
print("Device not added")
if __name__ == "__main__":
app = QApplication(sys.argv)
mainWin = MainWindow()
a = mainWin.show()
try:
mainWin.show()
os.remove("list_of_devices.txt")
print("Awaiting devices to be launched")
except:
print("Awaiting devices to be launched")
publishedMessage = mainWin.getGUIFilename()
sys.exit(app.exec_())

devicesEmbedded.py:

import random
import asyncio
from actorio import Actor, Message, DataMessage, ask, EndMainLoop, Reference
from mqtt import *
# from GUI im

Re: Python help needed

2019-08-08 Thread Dan Sommers

On 8/8/19 12:26 PM, Paolo G. Cantore wrote:

> I think the special case treatment could be avoided.
>
> First: Join all items with ' and '
> Second: Replace all ' and ' with ', ' except the last

That works great, until one of the elements of the original list is
"spam and eggs":

>>> spam = ['apples', 'spam and eggs', 'bananas', 'tofu', 'cats']
>>> s = " and ".join(spam)
>>> s.replace(" and ", ", ", len(spam) - 2)  # except the last
'apples, spam, eggs, bananas and tofu and cats'

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


Re: Python help needed

2019-08-08 Thread Paolo G. Cantore

Am 08.08.19 um 01:18 schrieb MRAB:

On 2019-08-07 21:36, Kuyateh Yankz wrote:
#trying to write a function that takes a list value as an argument and 
returns a string with all the items separated by a comma and a space, 
with and inserted before the last item. For example, passing the 
previous spam list to the function would return 'apples, bananas, 
tofu, and cats'. But your function should be able to work with any 
list value passed to it.


def myList(aParameter): #defined
 finalList = []
 for i in range(len(aParameter)-1): #targeting the last item in 
the list
   finalList.append('and '+ aParameter[-1]) #Removes the last item 
in the list, append the last item with THE and put it back, then put 
it into the FINAL LIST FUNCTION.

 return finalList
spam = ['apples', 'bananas', 'tofu', 'cats']
print(myList(spam))

#Got up to this point, still couldn't get rid of the '' around the 
items and the []. I tried (','.join()) but could not get there.

#Am I on the wrong path or there's a quick fix here?
https://pastebin.com/JCXisAuz

There's a nice way of doing it using str.join. However, you do need to 
special-case when there's only 1 item.


Start with a list:

 >>> spam = ['apples', 'bananas', 'tofu', 'cats']

The last item will be have an 'and', so let's remove that for the moment:

 >>> spam[ : -1]
['apples', 'bananas', 'tofu']

Join these items together with ', ':

 >>> ', '.join(spam[ : -1])
'apples, bananas, tofu'

Now for the last item:

 >>> ', '.join(spam[ : -1]) + ' and ' + spam[-1]
'apples, bananas, tofu and cats'

For the special case, when len(spam) == 1, just return spam[0].


I think the special case treatment could be avoided.

First: Join all items with ' and '
Second: Replace all ' and ' with ', ' except the last

>>> spam = ['apples', 'bananas', 'tofu', 'cats']
>>> s = " and ".join(spam)
>>> s.replace(" and ", ", ", len(spam) - 2)  # except the last
'apples, bananas, tofu and cats'

Or as a one liner:
" and ".join(spam).replace(" and ", ", ", len(spam) - 2)

It works also for a single item list:
>>> spam = ['apples']
'apples'
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python help needed

2019-08-07 Thread MRAB

On 2019-08-07 21:36, Kuyateh Yankz wrote:
  
#trying to write a function that takes a list value as an argument and returns a string with all the items separated by a comma and a space, with and inserted before the last item. For example, passing the previous spam list to the function would return 'apples, bananas, tofu, and cats'. But your function should be able to work with any list value passed to it.


def myList(aParameter): #defined
 finalList = []
 for i in range(len(aParameter)-1): #targeting the last item in the list
   finalList.append('and '+ aParameter[-1]) #Removes the last item in the 
list, append the last item with THE and put it back, then put it into the FINAL 
LIST FUNCTION.
 return finalList
spam = ['apples', 'bananas', 'tofu', 'cats']
print(myList(spam))

#Got up to this point, still couldn't get rid of the '' around the items and 
the []. I tried (','.join()) but could not get there.
#Am I on the wrong path or there's a quick fix here?
https://pastebin.com/JCXisAuz

There's a nice way of doing it using str.join. However, you do need to 
special-case when there's only 1 item.


Start with a list:

>>> spam = ['apples', 'bananas', 'tofu', 'cats']

The last item will be have an 'and', so let's remove that for the moment:

>>> spam[ : -1]
['apples', 'bananas', 'tofu']

Join these items together with ', ':

>>> ', '.join(spam[ : -1])
'apples, bananas, tofu'

Now for the last item:

>>> ', '.join(spam[ : -1]) + ' and ' + spam[-1]
'apples, bananas, tofu and cats'

For the special case, when len(spam) == 1, just return spam[0].

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


Python help needed

2019-08-07 Thread Kuyateh Yankz
 
#trying to write a function that takes a list value as an argument and returns 
a string with all the items separated by a comma and a space, with and inserted 
before the last item. For example, passing the previous spam list to the 
function would return 'apples, bananas, tofu, and cats'. But your function 
should be able to work with any list value passed to it.

def myList(aParameter): #defined 
finalList = [] 
for i in range(len(aParameter)-1): #targeting the last item in the list
  finalList.append('and '+ aParameter[-1]) #Removes the last item in the 
list, append the last item with THE and put it back, then put it into the FINAL 
LIST FUNCTION.
return finalList
spam = ['apples', 'bananas', 'tofu', 'cats']
print(myList(spam))

#Got up to this point, still couldn't get rid of the '' around the items and 
the []. I tried (','.join()) but could not get there.
#Am I on the wrong path or there's a quick fix here?
https://pastebin.com/JCXisAuz
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help Needed : script weird result.

2018-09-01 Thread mohan4h
On Sunday, September 2, 2018 at 1:12:17 AM UTC+8, moh...@gmail.com wrote:
> All,
> 
> I m trying to run this small script to find the lowest of the given array of 
> numbers. The script works fine for various combination of inputs but fails in 
> a weird way for a particular set of inputs, can anyone point the mistake in 
> the script and the behavior.
> 
> Script
> 
> x = input ("Enter the numbers separated by space and press ENTER :")
> x = x.split(" ")
> 
> def checkmin(arr):
> lowest = arr[0]
> for count in range(0,len(arr),1):
> if arr[count] < lowest :
> lowest = arr[count]
> else :
> pass
> print (lowest)
> return lowest
> 
> minimum = checkmin(x)
> print ("Lowest : {0}".format (minimum))
> 
> 
> Weird output is as below.
> 
> == RESTART: C:\Users\mohan\Desktop\temp.py ==
> Enter the numbers separated by space and press ENTER :5 90 63 82 59 24
> 5
> 5
> 5
> 5
> 5
> 24
> Lowest : 24
> 
> Regards
> Mohan C

Thanks to Duncan, Joel, Peter and Dan.

Now I understood what was wrong with the script and i fixed it, 
Now my scripts executes as expected and also i understand a concept in type 
casting.

As always this group is awesome and responsive, Thanks again guys.

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


Re: Help Needed : script weird result.

2018-09-01 Thread Peter Pearson
On Sat, 1 Sep 2018 10:11:59 -0700 (PDT), moha...@gmail.com wrote:
> All,
>
> I m trying to run this small script to find the lowest of the given
> array of numbers. The script works fine for various combination of
> inputs but fails in a weird way for a particular set of inputs, can
> anyone point the mistake in the script and the behavior.
>
> Script
>
> x = input ("Enter the numbers separated by space and press ENTER :")
> x = x.split(" ")
>
> def checkmin(arr):
> lowest = arr[0]
> for count in range(0,len(arr),1):
> if arr[count] < lowest :
> lowest = arr[count]
> else :
> pass
> print (lowest)
> return lowest
>
> minimum = checkmin(x)
> print ("Lowest : {0}".format (minimum))
>
>
> Weird output is as below.
>
>== RESTART: C:\Users\mohan\Desktop\temp.py ==
> Enter the numbers separated by space and press ENTER :5 90 63 82 59 24
> 5
> 5
> 5
> 5
> 5
> 24
> Lowest : 24

Assuming this is homework, here's a hint:
Instead of "5 90 63 82 59 24", feed it "2 ", or "1 09" 
or "1 2 3 ." (yes, ".").

As a stylistic matter, looping over an array's indices is more
cumbersome than looping over the elements of the array ("for x in arr:"),
unless you actually need the index for something, which you don't.
Also, two of the three arguments you pass to range can be omitted.

-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help Needed : script weird result.

2018-09-01 Thread Dan Sommers

On 9/1/18 1:11 PM, moha...@gmail.com wrote:

All,

I m trying to run this small script to find the lowest of the given array of 
numbers. The script works fine for various combination of inputs but fails in a 
weird way for a particular set of inputs, can anyone point the mistake in the 
script and the behavior.

Script

x = input ("Enter the numbers separated by space and press ENTER :")


Think about what x is here, and what x.split does.


x = x.split(" ")


Now think about what x is again, and recall that Python is strongly typed.

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


Re: Help Needed : script weird result.

2018-09-01 Thread Joel Goldstick
On Sat, Sep 1, 2018 at 1:26 PM duncan smith  wrote:
>
> On 01/09/18 18:11, moha...@gmail.com wrote:
> > All,
> >
> > I m trying to run this small script to find the lowest of the given array 
> > of numbers. The script works fine for various combination of inputs but 
> > fails in a weird way for a particular set of inputs, can anyone point the 
> > mistake in the script and the behavior.
> >
> > Script
> >
> > x = input ("Enter the numbers separated by space and press ENTER :")
> > x = x.split(" ")
> >
> > def checkmin(arr):
> > lowest = arr[0]
> > for count in range(0,len(arr),1):
> > if arr[count] < lowest :
> > lowest = arr[count]
> > else :
> > pass
> > print (lowest)
> > return lowest
> >
> > minimum = checkmin(x)
> > print ("Lowest : {0}".format (minimum))
> >
> >
> > Weird output is as below.
> >
> > == RESTART: C:\Users\mohan\Desktop\temp.py 
> > ==
> > Enter the numbers separated by space and press ENTER :5 90 63 82 59 24
> > 5
> > 5
> > 5
> > 5
> > 5
> > 24
> > Lowest : 24
> >
> > Regards
> > Mohan C
> >
>
>
> Compare,
>
> >>> min(5, 90, 63, 82, 59, 24)
> 5
> >>> min('5', '90', '63', '82', '59', '24')
> '24'
> >>>
>
> Duncan
> --
> https://mail.python.org/mailman/listinfo/python-list

integers are not strings.  Strings collate according to alphanumeric
sequence.  So the 2 in 24 makes it less than the 5


-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help Needed : script weird result.

2018-09-01 Thread duncan smith
On 01/09/18 18:11, moha...@gmail.com wrote:
> All,
> 
> I m trying to run this small script to find the lowest of the given array of 
> numbers. The script works fine for various combination of inputs but fails in 
> a weird way for a particular set of inputs, can anyone point the mistake in 
> the script and the behavior.
> 
> Script
> 
> x = input ("Enter the numbers separated by space and press ENTER :")
> x = x.split(" ")
> 
> def checkmin(arr):
> lowest = arr[0]
> for count in range(0,len(arr),1):
> if arr[count] < lowest :
> lowest = arr[count]
> else :
> pass
> print (lowest)
> return lowest
> 
> minimum = checkmin(x)
> print ("Lowest : {0}".format (minimum))
> 
> 
> Weird output is as below.
> 
> == RESTART: C:\Users\mohan\Desktop\temp.py ==
> Enter the numbers separated by space and press ENTER :5 90 63 82 59 24
> 5
> 5
> 5
> 5
> 5
> 24
> Lowest : 24
> 
> Regards
> Mohan C
> 


Compare,

>>> min(5, 90, 63, 82, 59, 24)
5
>>> min('5', '90', '63', '82', '59', '24')
'24'
>>>

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


Help Needed : script weird result.

2018-09-01 Thread mohan4h
All,

I m trying to run this small script to find the lowest of the given array of 
numbers. The script works fine for various combination of inputs but fails in a 
weird way for a particular set of inputs, can anyone point the mistake in the 
script and the behavior.

Script

x = input ("Enter the numbers separated by space and press ENTER :")
x = x.split(" ")

def checkmin(arr):
lowest = arr[0]
for count in range(0,len(arr),1):
if arr[count] < lowest :
lowest = arr[count]
else :
pass
print (lowest)
return lowest

minimum = checkmin(x)
print ("Lowest : {0}".format (minimum))


Weird output is as below.

== RESTART: C:\Users\mohan\Desktop\temp.py ==
Enter the numbers separated by space and press ENTER :5 90 63 82 59 24
5
5
5
5
5
24
Lowest : 24

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


Help needed in mapping Magento 1.x/PHP data structure into Python equivalent for suds

2016-05-31 Thread Parul M
Hello All,
I need assistance in calling Magento 1.x SOAP API's using Python suds
library.
How to map the *PHP data structure array(array(k1=>v1, k2=>v2,.)) in
terms of python suds*???

The exposed  SOAP API syntax for creating a new customer in magento:
ult = $client->call($session,  'customer.create',  array(array('email' => '
customer-m...@example.org',
  'firstname' =>
'Dough',

  'lastname' => 'Deeks',

  'password' => 'password',

  'website_id' => 1,

  'store_id' => 1)));

suds client instance:
>>> print client
Suds ( https://fedorahosted.org/suds/ )  version: 0.4 GA  build:
R699-20100913

Service ( MagentoService ) tns="urn:Magento"
   Prefixes (2)
  ns0 = "http://schemas.xmlsoap.org/soap/encoding/";
  ns1 = "urn:Magento"
   Ports (1):
  (Port)
 Methods (8):
call(xs:string sessionId, xs:string resourcePath, xs:anyType
args, )
endSession(xs:string sessionId, )
globalFaults(xs:string sessionId, )
login(xs:string username, xs:string apiKey, )
multiCall(xs:string sessionId, FixedArray calls, xs:anyType
options, )
resourceFaults(xs:string resourceName, xs:string sessionId, )
resources(xs:string sessionId, )
startSession()
 Types (49):
ns0:Array
ns0:ENTITIES
ns0:ENTITY

*My Efforts*:
>>> params={
... 'email':'customer...@example.org',
... 'firstname':'Dough',
... 'lastname':'Deeks',
... 'password':'password',
... 'website_id':1,
... 'store_id':1,
... 'group_id':1
... }
>>> a1=client.factory.create("ns0:Array")
>>> a1["item"]=[{"key":key,"value":params[key]} for key in params]
>>> a1
(Array){
   _arrayType = ""
   _offset = ""
   _id = ""
   _href = ""
   item[] =
  {
 value = 1
 key = "group_id"
  },
  {
 value = 1
 key = "store_id"
  },
  {
 value = "Dough"
 key = "firstname"
  },
  {
 value = "Deeks"
 key = "lastname"
  },
  {
 value = 1
 key = "website_id"
  },
  {
 value = "password"
 key = "password"
  },
  {
 value = "customer...@example.org"
 key = "email"
  },
}

>>> a3=client.factory.create("ns0:Array")
>>> a3.array=a1
>>> a3
(Array){
   _arrayType = ""
   _offset = ""
   _id = ""
   _href = ""
   array =
  (Array){
 _arrayType = ""
 _offset = ""
 _id = ""
 _href = ""
 item[] =
{
   value = 1
   key = "group_id"
},
{
   value = 1
   key = "store_id"
},
{
   value = "Dough"
   key = "firstname"
},
{
   value = "Deeks"
   key = "lastname"
},
{
   value = 1
   key = "website_id"
},
{
   value = "password"
   key = "password"
},
{
   value = "customer...@example.org"
   key = "email"
},
  }
}

>>> client.service.call(session,'customer.create',a3)
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python27\lib\site-packages\suds\client.py", line 542, in __call__
return client.invoke(args, kwargs)
  File "C:\Python27\lib\site-packages\suds\client.py", line 602, in invoke
result = self.send(soapenv)
  File "C:\Python27\lib\site-packages\suds\client.py", line 643, in send
result = self.succeeded(binding, reply.message)
  File "C:\Python27\lib\site-packages\suds\client.py", line 678, in
succeeded
reply, result = binding.get_reply(self.method, reply)
  File "C:\Python27\lib\site-packages\suds\bindings\binding.py", line 151,
in get_reply
self.detect_fault(soapbody)
  File "C:\Python27\lib\site-packages\suds\bindings\binding.py", line 182,
in detect_fault
raise WebFault(p, fault)
suds.WebFault: Server raised fault: 'Customer email is required'


The data provided, is obviously not in the correct format.
Any guidance would be much appreciated.

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


Re: Help needed with compiling python

2015-11-26 Thread Kev Dwyer
Cecil Westerhof wrote:

> On Thursday 26 Nov 2015 09:29 CET, Steven D'Aprano wrote:
> 
>> On Thursday 26 November 2015 18:00, Cecil Westerhof wrote:
>>
>>> On Wednesday 25 Nov 2015 23:58 CET, Laura Creighton wrote:
>>>
 In a message of Wed, 25 Nov 2015 22:52:23 +0100, Cecil Westerhof
 writes:
>
> My system python was all-ready damaged: that is why I wanted to
> build myself.

 Your Suse system probably wants to use python for something. If
 your system python is damaged, you badly need to fix that, using
 the system package managers tools, before Suse does some sort of
 update on you, using the broken python, which damages more of your
 system.
>>>
>>> I tried that. But it installs only things in /usr/lib and
>>> /usr/lib64, nothing in /usr/bin, but at the same time it is adamant
>>> that it installed python. I wanted a quick fix, but it looks like
>>> that is not going to work. :'-( I'll have to find a way to get
>>> things fixed.
>>>
>>
>> On the assumption that you are more interested in fixing your broken
>> system than learning how to compile Python, what happens if you use
>> the Suse package manager to re-install Python?
>>
>> e.g. zypper python
> 
> It installs things in /usr/lib and /usr/lib64, but nothing in
> /usr/bin. So it installs libraries, but not programs.
> 
> 
> By the way: I am of-course most interested to fix my system, but I
> would not mind to have python compiled also, so I (can) work with the
> latest stable version. ;-)
> 

FWIW, I'm running OpenSuse 13.2 on a number of machines.  Pythons built
with make altinstall have the python executable placed in /usr/local/bin.

e.g.:

kev@pluto ~  which python3.5
/usr/local/bin/python3.5

kev@pluto ~  which python2.7
/usr/local/bin/python2.7


NB due to http://bugs.python.org/issue15631 I find I have to symlink 
lib-dynload to get a working python:

kev@pluto ~  ls -l /usr/local/lib/python3.5/lib-dynload
lrwxrwxrwx 1 root root 38 Sep 26 19:51 /usr/local/lib/python3.5/lib-dynload 
-> /usr/local/lib64/python3.5/lib-dynload

Having said that, I'd still recommend that you follow everyone else's advice 
and fix your system python/rebuild your OS.  Opensuse has not attempted to 
install python 2.7.9 on any of my (fully patched) machines, so something is 
wrong with your install, unless you're using Tumbleweed.

Cheers,

Kev

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


Re: Help needed with compiling python

2015-11-26 Thread Zachary Ware
On Thu, Nov 26, 2015 at 3:39 PM, Cecil Westerhof  wrote:
> On Thursday 26 Nov 2015 12:07 CET, Dave Farrance wrote:
>> zypper in -f 
>>
>> So you'll want to try package names like "python" and "python2.7".
>
> Sadly that also only installs only libraries and no applications.

Try "python-base".  (See `zypper wp /usr/bin/python`).

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


Re: Help needed with compiling python

2015-11-26 Thread Cecil Westerhof
On Thursday 26 Nov 2015 12:07 CET, Dave Farrance wrote:

> Cecil Westerhof  wrote:
>
>> On Wednesday 25 Nov 2015 23:58 CET, Laura Creighton wrote:
>>>
>>> Your Suse system probably wants to use python for something. If
>>> your system python is damaged, you badly need to fix that, using
>>> the system package managers tools, before Suse does some sort of
>>> update on you, using the broken python, which damages more of your
>>> system.
>>
>> I tried that. But it installs only things in /usr/lib and
>> /usr/lib64, nothing in /usr/bin, but at the same time it is adamant
>> that it installed python. I wanted a quick fix, but it looks like
>> that is not going to work. :'-( I'll have to find a way to get
>> things fixed.
>
> A complete reinstall of Suse (after saving your home directory and
> work) might be quickest if you're in the dark about what's broken.
>
> But you might be able to fix it. If you can figure out which
> packages contain the damaged files, then do forced reinstalls of
> those. I've not used Suse, but a quick Google tells me that the
> syntax is:
>
> zypper in -f 
>
> So you'll want to try package names like "python" and "python2.7".

Sadly that also only installs only libraries and no applications.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help needed with compiling python

2015-11-26 Thread Cecil Westerhof
On Thursday 26 Nov 2015 09:29 CET, Steven D'Aprano wrote:

> On Thursday 26 November 2015 18:00, Cecil Westerhof wrote:
>
>> On Wednesday 25 Nov 2015 23:58 CET, Laura Creighton wrote:
>>
>>> In a message of Wed, 25 Nov 2015 22:52:23 +0100, Cecil Westerhof
>>> writes:

 My system python was all-ready damaged: that is why I wanted to
 build myself.
>>>
>>> Your Suse system probably wants to use python for something. If
>>> your system python is damaged, you badly need to fix that, using
>>> the system package managers tools, before Suse does some sort of
>>> update on you, using the broken python, which damages more of your
>>> system.
>>
>> I tried that. But it installs only things in /usr/lib and
>> /usr/lib64, nothing in /usr/bin, but at the same time it is adamant
>> that it installed python. I wanted a quick fix, but it looks like
>> that is not going to work. :'-( I'll have to find a way to get
>> things fixed.
>>
>
> On the assumption that you are more interested in fixing your broken
> system than learning how to compile Python, what happens if you use
> the Suse package manager to re-install Python?
>
> e.g. zypper python

It installs things in /usr/lib and /usr/lib64, but nothing in
/usr/bin. So it installs libraries, but not programs.


By the way: I am of-course most interested to fix my system, but I
would not mind to have python compiled also, so I (can) work with the
latest stable version. ;-)

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help needed with compiling python

2015-11-26 Thread Dave Farrance
Cecil Westerhof  wrote:

>On Wednesday 25 Nov 2015 23:58 CET, Laura Creighton wrote:
>>
>> Your Suse system probably wants to use python for something. If your
>> system python is damaged, you badly need to fix that, using the
>> system package managers tools, before Suse does some sort of update
>> on you, using the broken python, which damages more of your system.
>
>I tried that. But it installs only things in /usr/lib and /usr/lib64,
>nothing in /usr/bin, but at the same time it is adamant that it
>installed python. I wanted a quick fix, but it looks like that is not
>going to work. :'-( I'll have to find a way to get things fixed.

A complete reinstall of Suse (after saving your home directory and work)
might be quickest if you're in the dark about what's broken.

But you might be able to fix it.  If you can figure out which packages
contain the damaged files, then do forced reinstalls of those.  I've not
used Suse, but a quick Google tells me that the syntax is:

zypper in -f 

So you'll want to try package names like "python" and "python2.7".
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help needed with compiling python

2015-11-26 Thread Steven D'Aprano
On Thursday 26 November 2015 18:00, Cecil Westerhof wrote:

> On Wednesday 25 Nov 2015 23:58 CET, Laura Creighton wrote:
> 
>> In a message of Wed, 25 Nov 2015 22:52:23 +0100, Cecil Westerhof
>> writes:
>>>
>>> My system python was all-ready damaged: that is why I wanted to
>>> build myself.
>>
>> Your Suse system probably wants to use python for something. If your
>> system python is damaged, you badly need to fix that, using the
>> system package managers tools, before Suse does some sort of update
>> on you, using the broken python, which damages more of your system.
> 
> I tried that. But it installs only things in /usr/lib and /usr/lib64,
> nothing in /usr/bin, but at the same time it is adamant that it
> installed python. I wanted a quick fix, but it looks like that is not
> going to work. :'-( I'll have to find a way to get things fixed.
> 

On the assumption that you are more interested in fixing your broken system 
than learning how to compile Python, what happens if you use the Suse 
package manager to re-install Python?

e.g. zypper python

or equivalent.



-- 
Steve

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


Re: Help needed with compiling python

2015-11-25 Thread Cecil Westerhof
On Wednesday 25 Nov 2015 23:58 CET, Laura Creighton wrote:

> In a message of Wed, 25 Nov 2015 22:52:23 +0100, Cecil Westerhof
> writes:
>>
>> My system python was all-ready damaged: that is why I wanted to
>> build myself.
>
> Your Suse system probably wants to use python for something. If your
> system python is damaged, you badly need to fix that, using the
> system package managers tools, before Suse does some sort of update
> on you, using the broken python, which damages more of your system.

I tried that. But it installs only things in /usr/lib and /usr/lib64,
nothing in /usr/bin, but at the same time it is adamant that it
installed python. I wanted a quick fix, but it looks like that is not
going to work. :'-( I'll have to find a way to get things fixed.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help needed with compiling python

2015-11-25 Thread Cecil Westerhof
On Wednesday 25 Nov 2015 23:39 CET, Zachary Ware wrote:

> On Wed, Nov 25, 2015 at 3:52 PM, Cecil Westerhof  wrote:
>> My system python was all-ready damaged: that is why I wanted to
>> build myself.
>
> Then you should try to repair the system Python install via the
> system package manager. It's not worth the hassle to try to replace
> it; it almost certainly won't work for some strange corner case that
> won't bite you until 3 months from now. It's perfectly OK to have a
> second Python install in /usr/local, even of the same version as the
> system Python.

I tried that. It did install things in /usr/lib and /usr/lib64, but
nothing in /usr/bin. Thought to solve it this way, but I suppose I
have to delve deeper in it.

>> It is an openSUSE system. I installed the readline with:
>> zypper install readline-devel
>>
>> The strange thing is that it does mot compile anymore now. I get:
>> Python build finished, but the necessary bits to build these
>> modules were not found: _bsddb _tkinter bsddb185 dbm dl gdbm
>> imageop sunaudiodev To find the necessary bits, look in setup.py in
>> detect_modules() for the module's name.
>
> Before you installed readline-devel, readline would have been listed
> there as well. It's ok to have modules listed there if you don't

I did not look good the first time then, because I do not remember
having those messages.

But I still get:
ImportError: No module named readline

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help needed with compiling python

2015-11-25 Thread Laura Creighton
In a message of Wed, 25 Nov 2015 22:52:23 +0100, Cecil Westerhof writes:
>
>My system python was all-ready damaged: that is why I wanted to build
>myself.

Your Suse system probably wants to use python for something.  If your
system python is damaged, you badly need to fix that, using the 
system package managers tools, before Suse does some sort of update
on you, using the broken python, which damages more of your system.

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


Re: Help needed with compiling python

2015-11-25 Thread Zachary Ware
On Wed, Nov 25, 2015 at 3:52 PM, Cecil Westerhof  wrote:
> My system python was all-ready damaged: that is why I wanted to build
> myself.

Then you should try to repair the system Python install via the system
package manager.  It's not worth the hassle to try to replace it; it
almost certainly won't work for some strange corner case that won't
bite you until 3 months from now.  It's perfectly OK to have a second
Python install in /usr/local, even of the same version as the system
Python.

> It is an openSUSE system. I installed the readline with:
> zypper install readline-devel
>
> The strange thing is that it does mot compile anymore now. I get:
> Python build finished, but the necessary bits to build these modules were not 
> found:
> _bsddb _tkinter   bsddb185
> dbmdl gdbm
> imageopsunaudiodev
> To find the necessary bits, look in setup.py in detect_modules() for the 
> module's name.

Before you installed readline-devel, readline would have been listed
there as well.  It's ok to have modules listed there if you don't need
those particular modules.  Most of those are actually deprecated, and
have been removed from Python 3.  Of those that remain, _tkinter
requires tcl-devel and tk-devel; dbm and gdbm require similarly named
development packages (I have no experience with using dbm/gdbm).

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


Re: Help needed with compiling python

2015-11-25 Thread Cecil Westerhof
On Wednesday 25 Nov 2015 21:49 CET, Zachary Ware wrote:

> On Wed, Nov 25, 2015 at 2:23 PM, Cecil Westerhof  wrote:
>> I wanted to install python myself. I started with 2.7.10. If that
>> works I also will install 3.5.0.
>>
>> I did:
>> ./configure --prefix=/usr
>> make
>> make altinstall
>>
>> I have:
>> /usr/bin/python2.7
>>
>> But when I execute this, I get: Could not find platform dependent
>> libraries  Consider setting $PYTHONHOME to
>> [:] Python 2.7.10 (default, Nov 25 2015,
>> 20:58:29) [GCC 4.8.5] on linux2 Type "help", "copyright", "credits"
>> or "license" for more information. Traceback (most recent call
>> last): File "/etc/pythonstart", line 7, in  import readline
>> ImportError: No module named readline
>>
>> What do I need to do to get it working?
>
> First off, I strongly suggest not using --prefix=/usr.  Stick with
> --prefix=/usr/local (the default) to avoid overwriting the system
> Python, which may differ from a source build (and, in fact,
> overwriting your system Python may be what's causing some of your
> problems; those first two lines are worrying).

My system python was all-ready damaged: that is why I wanted to build
myself.


> Secondly, there are several optional modules that are not compiled
> unless particular libraries are found to link against, including
> readline. You'll need the readline development package (probably
> readline-dev or readline-devel, depending on your distribution). You
> can quickly pull in the dependencies for all optional modules by
> doing something like the following for an apt-based system: `apt-get
> build-dep python3`.

It is an openSUSE system. I installed the readline with:
zypper install readline-devel

The strange thing is that it does mot compile anymore now. I get:
Python build finished, but the necessary bits to build these modules were not 
found:
_bsddb _tkinter   bsddb185
dbmdl gdbm
imageopsunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the 
module's name.

I have to look into that.

I still can install it, but get the same errors.

I think I need a bit more time to solve it.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help needed with compiling python

2015-11-25 Thread Zachary Ware
On Wed, Nov 25, 2015 at 2:23 PM, Cecil Westerhof  wrote:
> I wanted to install python myself. I started with 2.7.10. If that
> works I also will install 3.5.0.
>
> I did:
> ./configure --prefix=/usr
> make
> make altinstall
>
> I have:
> /usr/bin/python2.7
>
> But when I execute this, I get:
> Could not find platform dependent libraries 
> Consider setting $PYTHONHOME to [:]
> Python 2.7.10 (default, Nov 25 2015, 20:58:29)
> [GCC 4.8.5] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> Traceback (most recent call last):
>   File "/etc/pythonstart", line 7, in 
> import readline
> ImportError: No module named readline
>
> What do I need to do to get it working?

First off, I strongly suggest not using --prefix=/usr.  Stick with
--prefix=/usr/local (the default) to avoid overwriting the system
Python, which may differ from a source build (and, in fact,
overwriting your system Python may be what's causing some of your
problems; those first two lines are worrying).

Secondly, there are several optional modules that are not compiled
unless particular libraries are found to link against, including
readline.  You'll need the readline development package (probably
readline-dev or readline-devel, depending on your distribution).  You
can quickly pull in the dependencies for all optional modules by doing
something like the following for an apt-based system: `apt-get
build-dep python3`.

Hope this helps,
-- 
Zach
-- 
https://mail.python.org/mailman/listinfo/python-list


Help needed with compiling python

2015-11-25 Thread Cecil Westerhof
I wanted to install python myself. I started with 2.7.10. If that
works I also will install 3.5.0.

I did:
./configure --prefix=/usr
make
make altinstall

I have:
/usr/bin/python2.7

But when I execute this, I get:
Could not find platform dependent libraries 
Consider setting $PYTHONHOME to [:]
Python 2.7.10 (default, Nov 25 2015, 20:58:29) 
[GCC 4.8.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
  File "/etc/pythonstart", line 7, in 
import readline
ImportError: No module named readline

What do I need to do to get it working?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help needed

2014-11-30 Thread Denis McMahon
On Sat, 29 Nov 2014 11:35:18 -0800, Gautam R Bharadwaj wrote:

> Here is the code in python, this code arranges the alphabets in
> descending order and now I want to encode each alphabet with 0 and next
> alphabet with 1, then 00,01,10,11,000,001 and so on. Please help me with
> that.
> 
> //
> //CODE
> 
> from collections import defaultdict import string text ='intalks is an
> organization comprised of passionate
> students'.lower().translate(None,string.punctuation+' ')
> c = defaultdict(int)
> c.update({letter:0 for letter in string.lowercase[:26]})
> for letter in text:
> c[letter] += 1
> 
> for letter,freq in sorted(c.iteritems(),key=lambda (l,f): (-f,l)):
> print freq, letter

If you can confirm that the following:

000111101100010110010011001101001111010101011001100100011110

is the output you want in terms of the original string encoded according 
to your encoding scheme, then your problem domain currently is two fold:

a) To write a function that generates the encoding
b) To apply the encoding to the original string

To achieve the former, I used a combination of determining a string 
length, converting a string to an integer using base 2, converting a 
number to a string in binary form, and generating arbitrary length 
strings of zeroes.

Not necessarily all done in the most pythonic of manners I must admit. 
Have you attempted anything to generate you string of encodings yet? 
Because until you show a good faith effort, you don't my solution to your 
homework problem for free.

To achieve the latter, I took the encodings and strung them together 
according to the letters they represented in the original string.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Help needed

2014-11-29 Thread Gautam R Bharadwaj
Here is the code in python, this code arranges the alphabets in descending 
order and now I want to encode each alphabet with 0 and next alphabet with 1, 
then 00,01,10,11,000,001 and so on. Please help me with that.

//
//CODE

from collections import defaultdict
import string
text ='intalks is an organization comprised of passionate 
students'.lower().translate(None,string.punctuation+' ')
c = defaultdict(int)
c.update({letter:0 for letter in string.lowercase[:26]}) 
for letter in text:
c[letter] += 1


for letter,freq in sorted(c.iteritems(),key=lambda (l,f): (-f,l)): 
print freq, letter

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


Re: Help needed to create a Python extension library for an existing shared memory hash table library

2014-03-23 Thread Rustom Mody
On Sunday, March 23, 2014 6:37:11 PM UTC+5:30, Jens Thoms Toerring wrote:
> Simon Hardy-Francis  wrote:
> > Hi Python fans, I just released my first open source project ever called
> > SharedHashFile [1]. It's a shared memory hash table written in C. Some guy
> > on Quora asked [2] whether there's an extension library for Python coming
> > out. I would like to do one but I know little about Python. I was wondering
> > if anybody in this group has experience writing extension libraries for
> > Python?

> There are, as far as I know, a number of tools that can help you
> to create extension modules from C/C++ libraries (i.e. Python bin-
> dings for the library). One that I have used successfully with a
> largish C++ library of mine is shortly described here

> http://www.riverbankcomputing.com/software/sip/intro

> and the documentation and download are at

> http://pyqt.sourceforge.net/Docs/sip4/
> http://www.riverbankcomputing.com/software/sip/download

> Since I haven't used any of the alternatives I can't comment on
> how good they are. A list of them can be found here

> https://wiki.python.org/moin/IntegratingPythonWithOtherLanguages

Thats an old looking list -- pyrex is on, boost is not
Worst of all the basic builting extending/embedding seems to be
not mentioned!

Heres a list I posted recently
https://mail.python.org/pipermail/python-list/2013-June/650250.html

If it looks ok, maybe it should go up on that wiki
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Help needed to create a Python extension library for an existing shared memory hash table library

2014-03-23 Thread Jens Thoms Toerring
Simon Hardy-Francis  wrote:
> Hi Python fans, I just released my first open source project ever called
> SharedHashFile [1]. It's a shared memory hash table written in C. Some guy
> on Quora asked [2] whether there's an extension library for Python coming
> out. I would like to do one but I know little about Python. I was wondering
> if anybody in this group has experience writing extension libraries for
> Python?

There are, as far as I know, a number of tools that can help you
to create extension modules from C/C++ libraries (i.e. Python bin-
dings for the library). One that I have used successfully with a
largish C++ library of mine is shortly described here

http://www.riverbankcomputing.com/software/sip/intro

and the documentation and download are at

http://pyqt.sourceforge.net/Docs/sip4/
http://www.riverbankcomputing.com/software/sip/download

Since I haven't used any of the alternatives I can't comment on
how good they are. A list of them can be found here

https://wiki.python.org/moin/IntegratingPythonWithOtherLanguages

   Regards, Jens
-- 
  \   Jens Thoms Toerring  ___  j...@toerring.de
   \__  http://toerring.de
-- 
https://mail.python.org/mailman/listinfo/python-list


Help needed to create a Python extension library for an existing shared memory hash table library

2014-03-22 Thread Simon Hardy-Francis
Hi Python fans, I just released my first open source project ever called 
SharedHashFile [1]. It's a shared memory hash table written in C. Some guy on 
Quora asked [2] whether there's an extension library for Python coming out. I 
would like to do one but I know little about Python. I was wondering if anybody 
in this group has experience writing extension libraries for Python? Could you 
help? Or could we collaborate? Thanks and all the best, Simon

[1] https://github.com/simonhf/sharedhashfile
[2] 
http://www.quora.com/Inter-Process-Communication-1/Whats-a-good-library-to-share-a-key-value-store-across-multiple-processes-through-shared-memory
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Anki add-on - Help needed

2013-11-06 Thread Joel Goldstick
On Wed, Nov 6, 2013 at 9:17 AM, SH  wrote:
> Is anybody here able to help me finish off an Anki add-on? If you're not
> familiar with it, Anki (http://ankisrs.net/) is an open source, cross
> platform flashcard learning program, in PyQT. It's extensible, with add-
> ons.
>
> Thing is, I'm not a programmer, but I've managed to make my own add-on by
> trying to figure out how other people's add-ons work. I've got something
> that works, but it needs finishing off.
>
> There is a lot I don't understand, but I've got this snippet which will
> retrieve a value associated with the key 'dictKey' from a dictionary held
> in a file. However, it will only do it if I open the Options dialog in
> Anki (I'm guessing that's what DeckConf.loadConf is about). How can I get
> that value for use in another function, without having to open the dialog?
>
> [code]
> from aqt.deckconf import DeckConf
> from anki.hooks import wrap
>
> def load_dictVal(self):
> c = self.conf
> x = c.get('dictKey')
> print(x)
>
> DeckConf.loadConf = wrap(DeckConf.loadConf, load_dictVal)
> [/code]
>
> The dictionary is in a file at (on Linux) ~/Anki/User 1/collection.anki2.
> 'User 1' may vary, and each user has their own collection.anki2 file. The
> file's header says it's 'SQLite format 3'.
>
>
> Secondly, separate from the above, I want to get a True/False value from
> whether a deck is currently being studied? Maybe whether the review screen
> is open, or something?
>
> Any help would be greatly appreciated.
>
> --
>
> Stew
>
> --
> https://mail.python.org/mailman/listinfo/python-list

Best to you if someone here can help, but your question isn't really a
python question as much as one about how anki or pyqt work.  Have you
looked for mailing lists for pyqt or anki? you might have better luck
there.

-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Anki add-on - Help needed

2013-11-06 Thread SH
Is anybody here able to help me finish off an Anki add-on? If you're not
familiar with it, Anki (http://ankisrs.net/) is an open source, cross
platform flashcard learning program, in PyQT. It's extensible, with add-
ons.

Thing is, I'm not a programmer, but I've managed to make my own add-on by
trying to figure out how other people's add-ons work. I've got something
that works, but it needs finishing off.

There is a lot I don't understand, but I've got this snippet which will
retrieve a value associated with the key 'dictKey' from a dictionary held
in a file. However, it will only do it if I open the Options dialog in
Anki (I'm guessing that's what DeckConf.loadConf is about). How can I get
that value for use in another function, without having to open the dialog?

[code]
from aqt.deckconf import DeckConf
from anki.hooks import wrap

def load_dictVal(self):
c = self.conf
x = c.get('dictKey')
print(x)

DeckConf.loadConf = wrap(DeckConf.loadConf, load_dictVal)
[/code]

The dictionary is in a file at (on Linux) ~/Anki/User 1/collection.anki2.
'User 1' may vary, and each user has their own collection.anki2 file. The
file's header says it's 'SQLite format 3'.


Secondly, separate from the above, I want to get a True/False value from
whether a deck is currently being studied? Maybe whether the review screen
is open, or something?

Any help would be greatly appreciated.

-- 

Stew

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


Re: pyGTK Help Needed Please

2013-09-20 Thread Michael Torrie
On 09/20/2013 12:30 PM, bingefel...@gmail.com wrote:
> Hi folks,
> 
> I'm trying to run a program called Nicotine+ on my Mac which is running 
> 10.8.5. Nicotine+ requires GTK2, pyGTK2 and Python to run. I believe I have 
> all of these installed via Macports (please see here - 
> http://pastebin.com/nwmrpp2Y )
> 
> When I try to run Nicotine+ I get this message:
> 
> '/Users/**/Downloads/nicotine+-1.2.16', 
> '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', 
> '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', 
> '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
>  
> '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
>  
> '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
>  
> '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', 
> '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
>  
> '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
>  
> '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
>  
> '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
>  '/Library/Python/2.7/site-packages']
> Exception: No module named pygtk
> 
> 
> If I run Python and type import pygtk I get this message:
> 
> Traceback (most recent call last):
> File "", line 1, in 
> ImportError: No module named pygtk
> 
> 
> can anyone help me please?

You probably need to run the program using the version of Python that's
installed in MacPorts.  Your system python does not know anything about
MacPorts, so it obviously can't find pyGTK, since it's not in the system
library location.  I can't remember where MacPorts puts things, but
presumably you'd have to do edit the nicotine+-1.2.16 file and change
the first line to point to the MacPorts version of python.
-- 
https://mail.python.org/mailman/listinfo/python-list


pyGTK Help Needed Please

2013-09-20 Thread bingefeller
Hi folks,

I'm trying to run a program called Nicotine+ on my Mac which is running 10.8.5. 
Nicotine+ requires GTK2, pyGTK2 and Python to run. I believe I have all of 
these installed via Macports (please see here - http://pastebin.com/nwmrpp2Y )

When I try to run Nicotine+ I get this message:

'/Users/**/Downloads/nicotine+-1.2.16', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
 
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
 '/Library/Python/2.7/site-packages']
Exception: No module named pygtk


If I run Python and type import pygtk I get this message:

Traceback (most recent call last):
File "", line 1, in 
ImportError: No module named pygtk


can anyone help me please?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: help needed

2013-04-09 Thread leonardo
thanks i did it!



Il giorno 08/apr/2013, alle ore 13:56, rusi  ha scritto:

> On Apr 8, 4:41 pm, Dave Angel  wrote:
> 
>> Go back to the previous message and you'll see Adam tells you exactly
>> what to type at the terminal.  But to be more literal:
>> 
>> python ex13.py  first 2nd 3rd
> 
> 
> followed by RET (also called ENTER) key
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Re: help needed

2013-04-08 Thread rusi
On Apr 8, 4:41 pm, Dave Angel  wrote:

> Go back to the previous message and you'll see Adam tells you exactly
> what to type at the terminal.  But to be more literal:
>
> python ex13.py  first 2nd 3rd


followed by RET (also called ENTER) key
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help needed

2013-04-08 Thread Dave Angel

On 04/08/2013 07:24 AM, leonardo wrote:


thanks adam, but it is not clear to me yet.
if i open the terminal how do i work on it? what should i type in?


Please don't top-post.  It kills off the context.

Go back to the previous message and you'll see Adam tells you exactly 
what to type at the terminal.  But to be more literal:


python ex13.py  first 2nd 3rd



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


Re: help needed

2013-04-08 Thread leonardo

thanks adam, but it is not clear to me yet.
if i open the terminal how do i work on it? what should i type in?

thanks


Il giorno 08/apr/2013, alle ore 11:25, Adam Mesha  ha scritto:

> On Mon, Apr 8, 2013 at 11:01 AM, leonardo selmi  wrote:
> then i get this error:
> 
> Traceback (most recent call last):
>   File "/Users/leonardo/Documents/ex13.py", line 3, in 
> script, first, second, third = argv
> ValueError: need more than 1 value to unpack
> 
> You didn't provide any arguments to the script.
>  
> in the book the author says that i should run the program like this:
> 
> $ python ex13.py first 2nd 3rd
> The script is called: ex13.py
> Your first variable is: first
> Your second variable is: 2nd
> Your third variable is: 3rd
> but how can i do that?? what are the steps? where should i go?
> 
> You need to open a command line terminal and type the first line (without the 
> dollar sign). You will need to change your directory to the directory that 
> contains your exercise script, probably by doing "cd 
> /path/to/exercise/directory". If you're on Windows it's the same idea, you 
> run the "cmd" program, but you would have to specify the full path to the 
> python interpreter instead of just "python", or follow the directions that 
> have been offered for fixing Windows.
> 
> Adam
> www.mesha.org
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Re: help needed

2013-04-08 Thread Chris Angelico
On Mon, Apr 8, 2013 at 7:29 PM, leonardo  wrote:
> thanks barrett, but i am using a mac..

Open up Terminal - that'll give you a window with a bash prompt.
Proceed from there; it's the same as the default shell on many
Linuxes.

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


Re: help needed

2013-04-08 Thread leonardo

thanks barrett, but i am using a mac..



Il 08/04/2013 11.15, Barrett Lewis ha scritto:
Do you happen to be on windows? Because if you are then you need to 
edit the registry. If you are on windows let me know and I will walk 
you through the fix, but if not then it would be a waste of time for 
me to explain it.





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


Re: help needed

2013-04-08 Thread Adam Mesha
On Mon, Apr 8, 2013 at 11:01 AM, leonardo selmi  wrote:

> then i get this error:
>
> Traceback (most recent call last):
>   File "/Users/leonardo/Documents/ex13.py", line 3, in 
> script, first, second, third = argv
> ValueError: need more than 1 value to unpack
>

You didn't provide any arguments to the script.


> in the book the author says that i should run the program like this:
>
> $ python ex13.py first 2nd 3rdThe script is called: ex13.pyYour first 
> variable is: firstYour second variable is: 2ndYour third variable is: 3rd
>
> but how can i do that?? what are the steps? where should i go?
>

You need to open a command line terminal and type the first line (without
the dollar sign). You will need to change your directory to the directory
that contains your exercise script, probably by doing "cd
/path/to/exercise/directory". If you're on Windows it's the same idea, you
run the "cmd" program, but you would have to specify the full path to the
python interpreter instead of just "python", or follow the directions that
have been offered for fixing Windows.

Adam
www.mesha.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help needed

2013-04-08 Thread Barrett Lewis
Do you happen to be on windows? Because if you are then you need to edit
the registry. If you are on windows let me know and I will walk you through
the fix, but if not then it would be a waste of time for me to explain it.
-- 
http://mail.python.org/mailman/listinfo/python-list


help needed

2013-04-08 Thread leonardo selmi
hello all,

i have typed the following program from the book "learn python the hard way":

from sys import argv

script, first, second, third = argv

print "The script is called:", script
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third
then i get this error:

Traceback (most recent call last):
  File "/Users/leonardo/Documents/ex13.py", line 3, in 
script, first, second, third = argv
ValueError: need more than 1 value to unpack

in the book the author says that i should run the program like this:

$ python ex13.py first 2nd 3rd
The script is called: ex13.py
Your first variable is: first
Your second variable is: 2nd
Your third variable is: 3rd
but how can i do that?? what are the steps? where should i go?
thanks!

best regards
leonardo-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help needed installing easy_install and lxml2

2012-08-16 Thread Ian

On 16/08/2012 08:01, Stefan Behnel wrote:
http://lxml.de/FAQ.html#where-are-the-binary-builds Stefan 


Hi Stefan,

Thanks Stefan,  everything is working fine now.

Regards

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


Re: Help needed installing easy_install and lxml2

2012-08-16 Thread Stefan Behnel
Ian, 15.08.2012 21:39:
> On a reasonably fresh (3 day old) install of 64 bit windows 7, I have
> installed the 64 bit Python 2.7.3 from http://www.python.org/download/
> 
> Then I installed  the 64 bit version of easy_install using
> http://pypi.python.org/pypi/setuptools
> 
> And then install lxml 2.3.5, for which I use the instructions at
> http://lxml.de/installation.html#installation
> 
> This ends with:
> Processing lxml-2.3.5.tgz
> Running lxml-2.3.5\setup.py -q bdist_egg --dist-dir
> c:\users\ian\appdata\local\temp\easy_install-9__rq7\lxml-2.3.5\egg-dist-tmp-uj_v_2
> 
> Building lxml version 2.3.5.
> Building without Cython.
> ERROR: 'xslt-config' is not recognized as an internal or external command,
> operable program or batch file.
> 
> ** make sure the development packages of libxml2 and libxslt are installed **
> 
> Using build configuration of libxslt
> error: Setup script exited with error: Unable to find vcvarsall.bat
> 
> C:\Users\ian>
> 
> Now what? I thought I was installing the binary package do I would not need
> any development versions.
> 
> What do these errors mean, and how can I overcome them?

http://lxml.de/FAQ.html#where-are-the-binary-builds

Stefan


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


Help needed installing easy_install and lxml2

2012-08-15 Thread Ian

Hi,

On a reasonably fresh (3 day old) install of 64 bit windows 7, I have 
installed the 64 bit Python 2.7.3 from http://www.python.org/download/


Then I installed  the 64 bit version of easy_install using 
http://pypi.python.org/pypi/setuptools


And then install lxml 2.3.5, for which I use the instructions at 
http://lxml.de/installation.html#installation


This ends with:
Processing lxml-2.3.5.tgz
Running lxml-2.3.5\setup.py -q bdist_egg --dist-dir 
c:\users\ian\appdata\local\temp\easy_install-9__rq7\lxml-2.3.5\egg-dist-tmp-uj_v_2

Building lxml version 2.3.5.
Building without Cython.
ERROR: 'xslt-config' is not recognized as an internal or external command,
operable program or batch file.

** make sure the development packages of libxml2 and libxslt are 
installed **


Using build configuration of libxslt
error: Setup script exited with error: Unable to find vcvarsall.bat

C:\Users\ian>

Now what? I thought I was installing the binary package do I would not 
need any development versions.


What do these errors mean, and how can I overcome them?

Thanks

Ian





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


Re: help needed with subprocess, pipes and parameters

2012-07-17 Thread John Pote

nuffi,

Have you tried running your piped commands

c:\Programs\bob\bob.exe -x -y "C:\text\path\to some\file.txt" | 
c:\Programs\kate\kate.exe -A 2 --dc "Print Media Is Dead" --da "Author" 
--dt "Title" --hf "Times" --bb "14" --aa "" --font "Ariel" - 
"C:\rtf\path\to some\file.rtf"


in a single instance of subprocess? Start it up and use the poll method 
to wait until the subprocess has terminated. Then open the output file 
to get the results.


My recent (and single, hence limited, experience) of using subprocess 
indicated that the spawned process may take a little time to start up. Try


bob = subprocess.Popen([bobPath, '-x', '-y', docpath], stdout = 
subprocess.PIPE,)

time.sleep( 0.5 ) #experiment with the delay
kate = subprocess.Popen([katePath, A, dc, da, dt, hf, fn, bb, path], 
stdin = bob.stdout, stdout = subprocess.PIPE,)


Never looked under the subprocess hood but maybe there's a race 
condition with the kate subprocess starting before the bob subprocess 
has set up its stdout. It's unlikely but so easy to check with a sleep 
between the subprocesses it has to be worth a go.


John


On 13/07/2012 08:34, nuffi wrote:


If I copy and paste the following command into a command window,   it does what 
I need.

c:\Programs\bob\bob.exe -x -y "C:\text\path\to some\file.txt" | c:\Programs\kate\kate.exe -A 2 --dc "Print Media Is Dead" --da "Author" 
--dt "Title" --hf "Times" --bb "14" --aa "" --font "Ariel" - "C:\rtf\path\to some\file.rtf"

My mission is to recreate this command within a python script,  so that I can 
pass a bunch of different parameters into it,  and use it as a batch over a 
bunch of different papers.

http://docs.python.org/library/subprocess.html seems to be the thing to use in 
python 2.7.3.  I also checked out 
http://www.doughellmann.com/PyMOTW/subprocess/.

My attempts run fine,  create destination folders ok and prints done but don't 
actually seem to process the file.  Is there some way to get subprocess to 
output the command it's generating so I can see what I'm doing wrong,  rather 
than just the output of the command?

How can I chekc that kate's opening the pipe left from bob?Bob may take 
some time to execute,  will that matter?


The code I came up with looks like this:

import os, glob, subprocess

sourceDir = "c:\\text\\"
destDir = "c:\\rtf\\"
bobPath = "C:\\Programs\\bob\\bob.exe"
katePath = "C:\\Programs\\kate\\kate.exe"

def get_new_path(doc):
 blah = doc.replace(sourceDir, destDir)
 if not os.path.isdir(blah):
 os.makedirs(blah)
 rtf = blah.replace('.txt', '.rtf')
 pathString = '- "' + (os.path.join(rtf)) + '"'
 return(pathString)


def convert_doc(doc):
 dc = '--dc "Print Media Is Dead"'
 da = '--da "Author"'
 dt = '--dt "Title"'
 hf = '--hf "Times"'
 fn = '--font "Ariel"'
 bb = '--bb "14"'
 docpath = '"' + (os.path.join(doc)) + '"'
 path = get_new_path(doc)
 A = '-A 2'
 bob = subprocess.Popen([bobPath, '-x', '-y', docpath], stdout = 
subprocess.PIPE,)
 kate = subprocess.Popen([katePath, A, dc, da, dt, hf, fn, bb, path], stdin 
= bob.stdout, stdout = subprocess.PIPE,)
 end_of_pipe = kate.stdout
 #print kate
 #subprocess.call(['echo', "Test peice of text", '>', 'D:\\output.txt'])
 for line in end_of_pipe:
 print '\t', blah.strip()
 #raw_input()
 return('done')


test = convert_doc("c:\\text\\path to\\some\\specific text file.txt")
print(blah)


==

Thanks for looking  :-)





--- Posted via news://freenews.netfront.net/ - Complaints to n...@netfront.net 
---
--
http://mail.python.org/mailman/listinfo/python-list


Re: help needed with subprocess, pipes and parameters

2012-07-14 Thread Chris Rebert
On Friday, July 13, 2012, nuffi wrote:

>
> If I copy and paste the following command into a command window,   it does
> what I need.
>
> c:\Programs\bob\bob.exe -x -y "C:\text\path\to some\file.txt" |
> c:\Programs\kate\kate.exe -A 2 --dc "Print Media Is Dead" --da "Author"
> --dt "Title" --hf "Times" --bb "14" --aa "" --font "Ariel" -
> "C:\rtf\path\to some\file.rtf"
>
> My mission is to recreate this command within a python script,  so that I
> can pass a bunch of different parameters into it,  and use it as a batch
> over a bunch of different papers.
>

>
> The code I came up with looks like this:
>
> import os, glob, subprocess
>
> sourceDir = "c:\\text\\"
> destDir = "c:\\rtf\\"
> bobPath = "C:\\Programs\\bob\\bob.exe"
> katePath = "C:\\Programs\\kate\\kate.exe"
>
> def get_new_path(doc):
> blah = doc.replace(sourceDir, destDir)
> if not os.path.isdir(blah):
> os.makedirs(blah)
> rtf = blah.replace('.txt', '.rtf')
> pathString = '- "' + (os.path.join(rtf)) + '"'
> return(pathString)
>
>
> def convert_doc(doc):
> dc = '--dc "Print Media Is Dead"'
> da = '--da "Author"'
> dt = '--dt "Title"'
> hf = '--hf "Times"'
> fn = '--font "Ariel"'
> bb = '--bb "14"'
> docpath = '"' + (os.path.join(doc)) + '"'
> path = get_new_path(doc)
> A = '-A 2'
> bob = subprocess.Popen([bobPath, '-x', '-y', docpath], stdout =
> subprocess.PIPE,)
> kate = subprocess.Popen([katePath, A, dc, da, dt, hf, fn, bb, path],
> stdin = bob.stdout, stdout = subprocess.PIPE,)


Your tokenization of the command is wrong. Read the Note box in the
subprocess docs for guidance on how to get it right:
http://docs.python.org/library/subprocess.html#popen-constructor

Cheers,
Chris via iPhone


-- 
Cheers,
Chris
--
http://rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


help needed with subprocess, pipes and parameters

2012-07-13 Thread nuffi

If I copy and paste the following command into a command window,   it does what 
I need.  

c:\Programs\bob\bob.exe -x -y "C:\text\path\to some\file.txt" | 
c:\Programs\kate\kate.exe -A 2 --dc "Print Media Is Dead" --da "Author" --dt 
"Title" --hf "Times" --bb "14" --aa "" --font "Ariel" - "C:\rtf\path\to 
some\file.rtf"

My mission is to recreate this command within a python script,  so that I can 
pass a bunch of different parameters into it,  and use it as a batch over a 
bunch of different papers.

http://docs.python.org/library/subprocess.html seems to be the thing to use in 
python 2.7.3.  I also checked out 
http://www.doughellmann.com/PyMOTW/subprocess/.

My attempts run fine,  create destination folders ok and prints done but don't 
actually seem to process the file.  Is there some way to get subprocess to 
output the command it's generating so I can see what I'm doing wrong,  rather 
than just the output of the command?

How can I chekc that kate's opening the pipe left from bob?Bob may take 
some time to execute,  will that matter?


The code I came up with looks like this:

import os, glob, subprocess

sourceDir = "c:\\text\\"
destDir = "c:\\rtf\\"
bobPath = "C:\\Programs\\bob\\bob.exe"
katePath = "C:\\Programs\\kate\\kate.exe"

def get_new_path(doc):
blah = doc.replace(sourceDir, destDir)
if not os.path.isdir(blah):
os.makedirs(blah)
rtf = blah.replace('.txt', '.rtf')
pathString = '- "' + (os.path.join(rtf)) + '"'
return(pathString)


def convert_doc(doc):
dc = '--dc "Print Media Is Dead"'
da = '--da "Author"'
dt = '--dt "Title"'
hf = '--hf "Times"'
fn = '--font "Ariel"'
bb = '--bb "14"'
docpath = '"' + (os.path.join(doc)) + '"'
path = get_new_path(doc)
A = '-A 2'
bob = subprocess.Popen([bobPath, '-x', '-y', docpath], stdout = 
subprocess.PIPE,)
kate = subprocess.Popen([katePath, A, dc, da, dt, hf, fn, bb, path], stdin 
= bob.stdout, stdout = subprocess.PIPE,)
end_of_pipe = kate.stdout
#print kate
#subprocess.call(['echo', "Test peice of text", '>', 'D:\\output.txt'])
for line in end_of_pipe:
print '\t', blah.strip()
#raw_input()
return('done')


test = convert_doc("c:\\text\\path to\\some\\specific text file.txt")
print(blah)


==

Thanks for looking  :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help needed with nested parsing of file into objects

2012-06-05 Thread richard
On Jun 5, 10:33 pm, Alain Ketterlin 
wrote:
> richard  writes:
> >> > An instance of TestArray
> >> >  a=a
> >> >  b=b
> >> >  c=c
> >> >  List of 2 A elements:
> >> >   Instance of A element
> >> >    a=1
> >> >    b=2
> >> >    c=3
> >> >   Instance of A element
> >> >    d=1
> >> >    e=2
> >> >    f=3
> >> >  List of 1 B elements
> >> >   Instance of B element
> >> >    a=1
> >> >    b=2
> >> >    c=3
> >> >    List of 2 C elements
> >> >     Instance of C element
> >> >      a=1
> >> >      b=2
> >> >      c=3
> >> >     Instance of C element
> >> >      a=1
> >> >      b=2
> >> >      c=3
>
> [...]
>
> > Hi Alain thanks for the reply. With regards to the missing case "An
> > Instance of" im not sure where/ how that is working as the case i put
> > in originally "Instance of" is in the file and been handled in the
> > previous case.
>
> Both cases are different in your example above. Top level elements are
> labeled "An instance ...", whereas "inner" instances are labeled
> "Instance of ...".
>
> > Also when running the final solution im getting a list of [None, None]
> > as the final stack?
>
> There's only one way this can happen: by falling through to the last
> case of build(). Check the regexps etc. again.
>
> > just busy debugging it to see whats going wrong. But sorry should have
> > been clearer with regards to the format mentioned above. The objects
> > are been printed out as dicts so where you put in
>
> >         elif "An Instance of" in couple[0]:
> >             return dict(couple[1])
>
> >         should still be ?
> >         elif "Instance of" in couple[0]:
> >             match = re.search("Instance of (.+) element", couple[0])
> >             return ("attr_%s" % match.group(1),Stanza(couple[1])) #
> > instantiating new stanza object and setting attributes.
>
> Your last "Instance of..." case is correct, but "An instance..." is
> different, because there's no containing object, so it's probably more
> like: return Stanza(couple[1]).
>
> -- Alain.

A big thank you to everyone who has helped me tackle / shed light on
this problem it is working great. Much appreciated.

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


Re: Help needed with nested parsing of file into objects

2012-06-05 Thread Alain Ketterlin
richard  writes:

>> > An instance of TestArray
>> >  a=a
>> >  b=b
>> >  c=c
>> >  List of 2 A elements:
>> >   Instance of A element
>> >    a=1
>> >    b=2
>> >    c=3
>> >   Instance of A element
>> >    d=1
>> >    e=2
>> >    f=3
>> >  List of 1 B elements
>> >   Instance of B element
>> >    a=1
>> >    b=2
>> >    c=3
>> >    List of 2 C elements
>> >     Instance of C element
>> >      a=1
>> >      b=2
>> >      c=3
>> >     Instance of C element
>> >      a=1
>> >      b=2
>> >      c=3
[...]

> Hi Alain thanks for the reply. With regards to the missing case "An
> Instance of" im not sure where/ how that is working as the case i put
> in originally "Instance of" is in the file and been handled in the
> previous case.

Both cases are different in your example above. Top level elements are
labeled "An instance ...", whereas "inner" instances are labeled
"Instance of ...".

> Also when running the final solution im getting a list of [None, None]
> as the final stack?

There's only one way this can happen: by falling through to the last
case of build(). Check the regexps etc. again.

> just busy debugging it to see whats going wrong. But sorry should have
> been clearer with regards to the format mentioned above. The objects
> are been printed out as dicts so where you put in
>
> elif "An Instance of" in couple[0]:
> return dict(couple[1])
>
> should still be ?
> elif "Instance of" in couple[0]:
> match = re.search("Instance of (.+) element", couple[0])
> return ("attr_%s" % match.group(1),Stanza(couple[1])) #
> instantiating new stanza object and setting attributes.

Your last "Instance of..." case is correct, but "An instance..." is
different, because there's no containing object, so it's probably more
like: return Stanza(couple[1]).

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


Re: Help needed with nested parsing of file into objects

2012-06-05 Thread richard
On Jun 5, 10:21 pm, richard  wrote:
> On Jun 5, 9:40 pm, Alain Ketterlin 
> wrote:
>
>
>
>
>
>
>
>
>
> > richard  writes:
>
> > [I'm leaving the data in the message in case anybody has troubles going
> > up-thread.]
>
> > > Hi guys still struggling to get the code that was posted to me on this
> > > forum to work in my favour and get the output in the format shown
> > > above. This is what I have so far. Any help will be greatly
> > > apprectiated.
>
> > > output trying to achieve
> > > parsed = [
> > >     {
> > >       "a":"a",
> > >       "b":"b",
> > >       "c":"c",
> > >       "A_elements":[
> > >           {
> > >             "a":1,
> > >             "b":2,
> > >             "c":3
> > >           },
> > >           {
> > >              "a":1,
> > >              "b":2,
> > >              "c":3
> > >           }
> > >        ],
> > >       "B_elements":[
> > >           {
> > >             "a":1,
> > >             "b":2,
> > >             "c":3,
> > >             "C_elements":[
> > >                  {
> > >                      "a":1,
> > >                      "b":2,
> > >                      "c":3
> > >                   },
> > >                   {
> > >                       "a":1,
> > >                       "b":2,
> > >                       "c":3
> > >                   }
> > >              ]
> > >           }
> > >        ]
> > >     },
>
> > >     {
> > >       "a":"1",
> > >       "b":"2",
> > >       "c":"3",
> > >     }
>
> > > ]
>
> > > file format unchangeable
>
> > > An instance of TestArray
> > >  a=a
> > >  b=b
> > >  c=c
> > >  List of 2 A elements:
> > >   Instance of A element
> > >    a=1
> > >    b=2
> > >    c=3
> > >   Instance of A element
> > >    d=1
> > >    e=2
> > >    f=3
> > >  List of 1 B elements
> > >   Instance of B element
> > >    a=1
> > >    b=2
> > >    c=3
> > >    List of 2 C elements
> > >     Instance of C element
> > >      a=1
> > >      b=2
> > >      c=3
> > >     Instance of C element
> > >      a=1
> > >      b=2
> > >      c=3
>
> > > An instance of TestArray
> > >  a=1
> > >  b=2
> > >  c=3
>
> > > def test_parser(filename):
> > >     class Stanza:
> > >         def __init__(self, values):
> > >             for attr, val in values:
> > >                 setattr(self, attr, val)
>
> > >     def build(couple):
> > >         if "=" in couple[0]:
> > >             attr, val = couple[0].split("=")
> > >             return attr,val
> > >         elif "Instance of" in couple[0]:
> > >             match = re.search("Instance of (.+) element", couple[0])
> > >             return ("attr_%s" % match.group(1),Stanza(couple[1]))
> > >         elif "List of" in couple[0]:
> > >             match = re.search("List of \d (.+) elements", couple[0])
> > >             return ("%s_elements" % match.group(1),couple[1])
>
> > You forgot one case:
>
> >     def build(couple):
> >         if "=" in couple[0]:
> >             attr, val = couple[0].split("=")
> >             return attr,val
> >         elif "Instance of" in couple[0]:
> >             #match = re.search("Instance of (.+) element", couple[0])
> >             #return ("attr_%s" % match.group(1),Stanza(couple[1]))
> >             return dict(couple[1])
> >         elif "An instance of" in couple[0]: # you forgot that case
> >             return dict(couple[1])
> >         elif "List of" in couple[0]:
> >             match = re.search("List of \d (.+) elements", couple[0])
> >             return ("%s_elements" % match.group(1),couple[1])
> >         else:
> >             pass # put a test here
>
> > >     fo = open(filename, "r")
> > >     RE = re.compile("( *)(.*)")
> > >     stack = [("-",[])]
> > >     for line in fo:
> > >         matches = RE.match(line)
> > >         if len(matches.group(2)) > 0:
> > >             depth = 1 + len(matches.group(1))
> > >             while len(stack) > depth:
> > >                 stack[-2][1].append(build(stack[-1]))
> > >                 del stack[-1]
> > >             stack.append( (matches.group(2),[]) )
> > >     while len(stack) > 1:
> > >         stack[-2][1].append(stack[-1])
>
> > Change this to:
>
> >           stack[-2][1].append(build(stack[-1])) # call build() here also
>
> > >         del stack[-1]
> > >     return stack
>
> > Actually the first and only element of stack is a container: all you
> > need is the second element of the only tuple in stack, so:
>
> >       return stack[0][1]
>
> > and this is your list. If you need it pretty printed, you'll have to
> > work the hierarchy.
>
> > -- Alain.
>
> Hi Alain, thanks for the reply. Amended the code and just busy
> debugging but the stack i get back justs return [None, None]. Also
> should have been clearer when i mentioned the format above the dicts
> are actually objects instantaited from classes and just printed out as
> obj.__dict__ just for representation putposes. so where you have
> replaced the following i presume this was because of my format
> confusion. Thanks
>
>
>
>
>
>
>
>
>
> >         elif "I

Re: Help needed with nested parsing of file into objects

2012-06-05 Thread richard
On Jun 5, 9:40 pm, Alain Ketterlin 
wrote:
> richard  writes:
>
> [I'm leaving the data in the message in case anybody has troubles going
> up-thread.]
>
>
>
>
>
>
>
>
>
> > Hi guys still struggling to get the code that was posted to me on this
> > forum to work in my favour and get the output in the format shown
> > above. This is what I have so far. Any help will be greatly
> > apprectiated.
>
> > output trying to achieve
> > parsed = [
> >     {
> >       "a":"a",
> >       "b":"b",
> >       "c":"c",
> >       "A_elements":[
> >           {
> >             "a":1,
> >             "b":2,
> >             "c":3
> >           },
> >           {
> >              "a":1,
> >              "b":2,
> >              "c":3
> >           }
> >        ],
> >       "B_elements":[
> >           {
> >             "a":1,
> >             "b":2,
> >             "c":3,
> >             "C_elements":[
> >                  {
> >                      "a":1,
> >                      "b":2,
> >                      "c":3
> >                   },
> >                   {
> >                       "a":1,
> >                       "b":2,
> >                       "c":3
> >                   }
> >              ]
> >           }
> >        ]
> >     },
>
> >     {
> >       "a":"1",
> >       "b":"2",
> >       "c":"3",
> >     }
>
> > ]
>
> > file format unchangeable
>
> > An instance of TestArray
> >  a=a
> >  b=b
> >  c=c
> >  List of 2 A elements:
> >   Instance of A element
> >    a=1
> >    b=2
> >    c=3
> >   Instance of A element
> >    d=1
> >    e=2
> >    f=3
> >  List of 1 B elements
> >   Instance of B element
> >    a=1
> >    b=2
> >    c=3
> >    List of 2 C elements
> >     Instance of C element
> >      a=1
> >      b=2
> >      c=3
> >     Instance of C element
> >      a=1
> >      b=2
> >      c=3
>
> > An instance of TestArray
> >  a=1
> >  b=2
> >  c=3
>
> > def test_parser(filename):
> >     class Stanza:
> >         def __init__(self, values):
> >             for attr, val in values:
> >                 setattr(self, attr, val)
>
> >     def build(couple):
> >         if "=" in couple[0]:
> >             attr, val = couple[0].split("=")
> >             return attr,val
> >         elif "Instance of" in couple[0]:
> >             match = re.search("Instance of (.+) element", couple[0])
> >             return ("attr_%s" % match.group(1),Stanza(couple[1]))
> >         elif "List of" in couple[0]:
> >             match = re.search("List of \d (.+) elements", couple[0])
> >             return ("%s_elements" % match.group(1),couple[1])
>
> You forgot one case:
>
>     def build(couple):
>         if "=" in couple[0]:
>             attr, val = couple[0].split("=")
>             return attr,val
>         elif "Instance of" in couple[0]:
>             #match = re.search("Instance of (.+) element", couple[0])
>             #return ("attr_%s" % match.group(1),Stanza(couple[1]))
>             return dict(couple[1])
>         elif "An instance of" in couple[0]: # you forgot that case
>             return dict(couple[1])
>         elif "List of" in couple[0]:
>             match = re.search("List of \d (.+) elements", couple[0])
>             return ("%s_elements" % match.group(1),couple[1])
>         else:
>             pass # put a test here
>
> >     fo = open(filename, "r")
> >     RE = re.compile("( *)(.*)")
> >     stack = [("-",[])]
> >     for line in fo:
> >         matches = RE.match(line)
> >         if len(matches.group(2)) > 0:
> >             depth = 1 + len(matches.group(1))
> >             while len(stack) > depth:
> >                 stack[-2][1].append(build(stack[-1]))
> >                 del stack[-1]
> >             stack.append( (matches.group(2),[]) )
> >     while len(stack) > 1:
> >         stack[-2][1].append(stack[-1])
>
> Change this to:
>
>           stack[-2][1].append(build(stack[-1])) # call build() here also
>
> >         del stack[-1]
> >     return stack
>
> Actually the first and only element of stack is a container: all you
> need is the second element of the only tuple in stack, so:
>
>       return stack[0][1]
>
> and this is your list. If you need it pretty printed, you'll have to
> work the hierarchy.
>
> -- Alain.

Hi Alain, thanks for the reply. Amended the code and just busy
debugging but the stack i get back justs return [None, None]. Also
should have been clearer when i mentioned the format above the dicts
are actually objects instantaited from classes and just printed out as
obj.__dict__ just for representation putposes. so where you have
replaced the following i presume this was because of my format
confusion. Thanks

> elif "Instance of" in couple[0]:
> match = re.search("Instance of (.+) element", couple[0])
> return ("attr_%s" % match.group(1),Stanza(couple[1])) 
> #instantiating new object and setting attributes
>
with
> elif "Instance of" in couple[0]:
> #match = re.search("Instance of (.+) element", couple[0])
>  

Re: Help needed with nested parsing of file into objects

2012-06-05 Thread richard
On Jun 5, 9:40 pm, Alain Ketterlin 
wrote:
> richard  writes:
>
> [I'm leaving the data in the message in case anybody has troubles going
> up-thread.]
>
>
>
>
>
>
>
>
>
> > Hi guys still struggling to get the code that was posted to me on this
> > forum to work in my favour and get the output in the format shown
> > above. This is what I have so far. Any help will be greatly
> > apprectiated.
>
> > output trying to achieve
> > parsed = [
> >     {
> >       "a":"a",
> >       "b":"b",
> >       "c":"c",
> >       "A_elements":[
> >           {
> >             "a":1,
> >             "b":2,
> >             "c":3
> >           },
> >           {
> >              "a":1,
> >              "b":2,
> >              "c":3
> >           }
> >        ],
> >       "B_elements":[
> >           {
> >             "a":1,
> >             "b":2,
> >             "c":3,
> >             "C_elements":[
> >                  {
> >                      "a":1,
> >                      "b":2,
> >                      "c":3
> >                   },
> >                   {
> >                       "a":1,
> >                       "b":2,
> >                       "c":3
> >                   }
> >              ]
> >           }
> >        ]
> >     },
>
> >     {
> >       "a":"1",
> >       "b":"2",
> >       "c":"3",
> >     }
>
> > ]
>
> > file format unchangeable
>
> > An instance of TestArray
> >  a=a
> >  b=b
> >  c=c
> >  List of 2 A elements:
> >   Instance of A element
> >    a=1
> >    b=2
> >    c=3
> >   Instance of A element
> >    d=1
> >    e=2
> >    f=3
> >  List of 1 B elements
> >   Instance of B element
> >    a=1
> >    b=2
> >    c=3
> >    List of 2 C elements
> >     Instance of C element
> >      a=1
> >      b=2
> >      c=3
> >     Instance of C element
> >      a=1
> >      b=2
> >      c=3
>
> > An instance of TestArray
> >  a=1
> >  b=2
> >  c=3
>
> > def test_parser(filename):
> >     class Stanza:
> >         def __init__(self, values):
> >             for attr, val in values:
> >                 setattr(self, attr, val)
>
> >     def build(couple):
> >         if "=" in couple[0]:
> >             attr, val = couple[0].split("=")
> >             return attr,val
> >         elif "Instance of" in couple[0]:
> >             match = re.search("Instance of (.+) element", couple[0])
> >             return ("attr_%s" % match.group(1),Stanza(couple[1]))
> >         elif "List of" in couple[0]:
> >             match = re.search("List of \d (.+) elements", couple[0])
> >             return ("%s_elements" % match.group(1),couple[1])
>
> You forgot one case:
>
>     def build(couple):
>         if "=" in couple[0]:
>             attr, val = couple[0].split("=")
>             return attr,val
>         elif "Instance of" in couple[0]:
>             #match = re.search("Instance of (.+) element", couple[0])
>             #return ("attr_%s" % match.group(1),Stanza(couple[1]))
>             return dict(couple[1])
>         elif "An instance of" in couple[0]: # you forgot that case
>             return dict(couple[1])
>         elif "List of" in couple[0]:
>             match = re.search("List of \d (.+) elements", couple[0])
>             return ("%s_elements" % match.group(1),couple[1])
>         else:
>             pass # put a test here
>
> >     fo = open(filename, "r")
> >     RE = re.compile("( *)(.*)")
> >     stack = [("-",[])]
> >     for line in fo:
> >         matches = RE.match(line)
> >         if len(matches.group(2)) > 0:
> >             depth = 1 + len(matches.group(1))
> >             while len(stack) > depth:
> >                 stack[-2][1].append(build(stack[-1]))
> >                 del stack[-1]
> >             stack.append( (matches.group(2),[]) )
> >     while len(stack) > 1:
> >         stack[-2][1].append(stack[-1])
>
> Change this to:
>
>           stack[-2][1].append(build(stack[-1])) # call build() here also
>
> >         del stack[-1]
> >     return stack
>
> Actually the first and only element of stack is a container: all you
> need is the second element of the only tuple in stack, so:
>
>       return stack[0][1]
>
> and this is your list. If you need it pretty printed, you'll have to
> work the hierarchy.
>
> -- Alain.

Hi Alain thanks for the reply. With regards to the missing case "An
Instance of" im not sure where/ how that is working as the case i put
in originally "Instance of" is in the file and been handled in the
previous case. Also when running the final solution im getting a list
of [None, None] as the final stack? just busy debugging it to see
whats going wrong. But sorry should have been clearer with regards to
the format mentioned above. The objects are been printed out as dicts
so where you put in

elif "An Instance of" in couple[0]:
return dict(couple[1])

should still be ?
elif "Instance of" in couple[0]:
match = re.search("Instance of (.+) element", couple[0])
return ("attr_%s" % match.group(1),Stanza(couple[1])) 

Re: Help needed with nested parsing of file into objects

2012-06-05 Thread Alain Ketterlin
richard  writes:


[I'm leaving the data in the message in case anybody has troubles going
up-thread.]

> Hi guys still struggling to get the code that was posted to me on this
> forum to work in my favour and get the output in the format shown
> above. This is what I have so far. Any help will be greatly
> apprectiated.
>
> output trying to achieve
> parsed = [
> {
>   "a":"a",
>   "b":"b",
>   "c":"c",
>   "A_elements":[
>   {
> "a":1,
> "b":2,
> "c":3
>   },
>   {
>  "a":1,
>  "b":2,
>  "c":3
>   }
>],
>   "B_elements":[
>   {
> "a":1,
> "b":2,
> "c":3,
> "C_elements":[
>  {
>  "a":1,
>  "b":2,
>  "c":3
>   },
>   {
>   "a":1,
>   "b":2,
>   "c":3
>   }
>  ]
>   }
>]
> },
>
> {
>   "a":"1",
>   "b":"2",
>   "c":"3",
> }
>
> ]
>
> file format unchangeable
>
> An instance of TestArray
>  a=a
>  b=b
>  c=c
>  List of 2 A elements:
>   Instance of A element
>a=1
>b=2
>c=3
>   Instance of A element
>d=1
>e=2
>f=3
>  List of 1 B elements
>   Instance of B element
>a=1
>b=2
>c=3
>List of 2 C elements
> Instance of C element
>  a=1
>  b=2
>  c=3
> Instance of C element
>  a=1
>  b=2
>  c=3
>
> An instance of TestArray
>  a=1
>  b=2
>  c=3
>
> def test_parser(filename):
> class Stanza:
> def __init__(self, values):
> for attr, val in values:
> setattr(self, attr, val)
>
> def build(couple):
> if "=" in couple[0]:
> attr, val = couple[0].split("=")
> return attr,val
> elif "Instance of" in couple[0]:
> match = re.search("Instance of (.+) element", couple[0])
> return ("attr_%s" % match.group(1),Stanza(couple[1]))
> elif "List of" in couple[0]:
> match = re.search("List of \d (.+) elements", couple[0])
> return ("%s_elements" % match.group(1),couple[1])

You forgot one case:

def build(couple):
if "=" in couple[0]:
attr, val = couple[0].split("=")
return attr,val
elif "Instance of" in couple[0]:
#match = re.search("Instance of (.+) element", couple[0])
#return ("attr_%s" % match.group(1),Stanza(couple[1]))
return dict(couple[1])
elif "An instance of" in couple[0]: # you forgot that case
return dict(couple[1])
elif "List of" in couple[0]:
match = re.search("List of \d (.+) elements", couple[0])
return ("%s_elements" % match.group(1),couple[1])
else:
pass # put a test here

> fo = open(filename, "r")
> RE = re.compile("( *)(.*)")
> stack = [("-",[])]
> for line in fo:
> matches = RE.match(line)
> if len(matches.group(2)) > 0:
> depth = 1 + len(matches.group(1))
> while len(stack) > depth:
> stack[-2][1].append(build(stack[-1]))
> del stack[-1]
> stack.append( (matches.group(2),[]) )
> while len(stack) > 1:
> stack[-2][1].append(stack[-1])

Change this to:

  stack[-2][1].append(build(stack[-1])) # call build() here also

> del stack[-1]
> return stack

Actually the first and only element of stack is a container: all you
need is the second element of the only tuple in stack, so:

  return stack[0][1]

and this is your list. If you need it pretty printed, you'll have to
work the hierarchy.

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


Re: Help needed with nested parsing of file into objects

2012-06-05 Thread richard
On Jun 5, 8:50 pm, Eelco  wrote:
> > thank you both for your replies. Unfortunately it is a pre-existing
> > file format imposed by an external system that I can't
> > change. Thank you for the code snippet.
>
> Hi Richard,
>
> Despite the fact that it is a preexisting format, it is very close
> indeed to valid YAML code.
>
> Writing your own whitespace-aware parser can be a bit of a pain, but
> since YAML does this for you, I would argue the cleanest solution
> would be to bootstrap that functionality, rather than roll your own
> solution, or to resort to hard to maintain regex voodoo.
>
> Here is my solution. As a bonus, it directly constructs a custom
> object hierarchy (obviously you would want to expand on this, but the
> essentials are there). One caveat: at the moment, the conversion to
> YAML relies on the appparent convention that instances never directly
> contain other instances, and lists never directly contain lists. This
> means all instances are list entries and get a '-' appended, and this
> just works. If this is not a general rule, youd have to keep track of
> an enclosing scope stack an emit dashes based on that. Anyway, the
> idea is there, and I believe it to be one worth looking at.
>
> 
> import yaml
>
> class A(yaml.YAMLObject):
>     yaml_tag = u'!A'
>     def __init__(self, **kwargs):
>         self.__dict__.update(kwargs)
>     def __repr__(self):
>         return 'A' + str(self.__dict__)
>
> class B(yaml.YAMLObject):
>     yaml_tag = u'!B'
>     def __init__(self, **kwargs):
>         self.__dict__.update(kwargs)
>     def __repr__(self):
>         return 'B' + str(self.__dict__)
>
> class C(yaml.YAMLObject):
>     yaml_tag = u'!C'
>     def __init__(self, **kwargs):
>         self.__dict__.update(kwargs)
>     def __repr__(self):
>         return 'C' + str(self.__dict__)
>
> class TestArray(yaml.YAMLObject):
>     yaml_tag = u'!TestArray'
>     def __init__(self, **kwargs):
>         self.__dict__.update(kwargs)
>     def __repr__(self):
>         return 'TestArray' + str(self.__dict__)
>
> class myList(yaml.YAMLObject):
>     yaml_tag = u'!myList'
>     def __init__(self, **kwargs):
>         self.__dict__.update(kwargs)
>     def __repr__(self):
>         return 'myList' + str(self.__dict__)
>
> data = \
> """
> An instance of TestArray
>  a=a
>  b=b
>  c=c
>  List of 2 A elements:
>   Instance of A element
>    a=1
>    b=2
>    c=3
>   Instance of A element
>    d=1
>    e=2
>    f=3
>  List of 1 B elements
>   Instance of B element
>    a=1
>    b=2
>    c=3
>    List of 2 C elements
>     Instance of C element
>      a=1
>      b=2
>      c=3
>     Instance of C element
>      a=1
>      b=2
>      c=3
> An instance of TestArray
>  a=1
>  b=2
>  c=3
> """.strip()
>
> #remove trailing whitespace and seemingly erronous colon in line 5
> lines = ['  '+line.rstrip().rstrip(':') for line in data.split('\n')]
>
> def transform(lines):
>     """transform text line by line"""
>     for line in lines:
>         #regular mapping lines
>         if line.find('=') > 0:
>             yield line.replace('=', ': ')
>         #instance lines
>         p = line.find('nstance of')
>         if p > 0:
>             s = p + 11
>             e = line[s:].find(' ')
>             if e == -1: e = len(line[s:])
>             tag = line[s:s+e]
>             whitespace= line.partition(line.lstrip())[0]
>             yield whitespace[:-2]+' -'+ ' !'+tag
>         #list lines
>         p = line.find('List of')
>         if p > 0:
>             whitespace= line.partition(line.lstrip())[0]
>             yield whitespace[:-2]+'  '+ 'myList:'
>
> ##transformed = (transform( lines))
> ##for i,t in enumerate(transformed):
> ##    print '{:>3}{}'.format(i,t)
>
> transformed = '\n'.join(transform( lines))
> print transformed
>
> res = yaml.load(transformed)
> print res
> print yaml.dump(res)
> 

Hi Eelco many thanks for the reply / solution it definitely looks like
a clean way to go about it. However installing 3rd party libs like
yaml on the server I dont think is on the cards at the moment.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help needed with nested parsing of file into objects

2012-06-05 Thread richard
On Jun 4, 3:20 pm, richard  wrote:
> On Jun 4, 3:14 pm, Alain Ketterlin 
> wrote:
>
>
>
>
>
>
>
>
>
> > richard  writes:
> > > Hi guys i am having a bit of dificulty finding the best approach /
> > > solution to parsing a file into a list of objects / nested objects any
> > > help would be greatly appreciated.
>
> > > #file format to parse .txt
> > > [code]
> > > An instance of TestArray
> > >  a=a
> > >  b=b
> > >  c=c
> > >  List of 2 A elements:
> > >   Instance of A element
>
> > [...]
>
> > Below is a piece of code that seems to work on your data. It builds a
> > raw tree, i leave it to you to adapt and built the objects you want. The
> > assumption is that the number of leading blanks faithfully denotes
> > depth.
>
> > As noted in another message, you're probably better off using an
> > existing syntax (json, python literals, yaml, xml, ...)
>
> > -- Alain.
>
> > #!/usr/bin/env python
>
> > import sys
> > import re
>
> > RE = re.compile("( *)(.*)")
> > stack = [("-",[])] # tree nodes are: (head,[children])
> > for line in sys.stdin:
> >     matches = RE.match(line)
> >     if len(matches.group(2)) > 0:
> >         depth = 1 + len(matches.group(1))
> >         while len(stack) > depth:
> >             stack[-2][1].append(stack[-1])
> >             del stack[-1]
> >             pass
> >         stack.append( (matches.group(2),[]) )
> >         pass
> >     pass
> > while len(stack) > 1:
> >     stack[-2][1].append(stack[-1])
> >     del stack[-1]
> >     pass
>
> > print(stack)
>
> thank you both for your replies. Unfortunately it is a pre-existing
> file format imposed by an external system that I can't
> change. Thank you for the code snippet.

Hi guys still struggling to get the code that was posted to me on this
forum to work in my favour and get the output in the format shown
above. This is what I have so far. Any help will be greatly
apprectiated.

output trying to achieve
parsed = [
{
  "a":"a",
  "b":"b",
  "c":"c",
  "A_elements":[
  {
"a":1,
"b":2,
"c":3
  },
  {
 "a":1,
 "b":2,
 "c":3
  }
   ],
  "B_elements":[
  {
"a":1,
"b":2,
"c":3,
"C_elements":[
 {
 "a":1,
 "b":2,
 "c":3
  },
  {
  "a":1,
  "b":2,
  "c":3
  }
 ]
  }
   ]
},

{
  "a":"1",
  "b":"2",
  "c":"3",
}

]

file format unchangeable

An instance of TestArray
 a=a
 b=b
 c=c
 List of 2 A elements:
  Instance of A element
   a=1
   b=2
   c=3
  Instance of A element
   d=1
   e=2
   f=3
 List of 1 B elements
  Instance of B element
   a=1
   b=2
   c=3
   List of 2 C elements
Instance of C element
 a=1
 b=2
 c=3
Instance of C element
 a=1
 b=2
 c=3

An instance of TestArray
 a=1
 b=2
 c=3

def test_parser(filename):
class Stanza:
def __init__(self, values):
for attr, val in values:
setattr(self, attr, val)

def build(couple):
if "=" in couple[0]:
attr, val = couple[0].split("=")
return attr,val
elif "Instance of" in couple[0]:
match = re.search("Instance of (.+) element", couple[0])
return ("attr_%s" % match.group(1),Stanza(couple[1]))
elif "List of" in couple[0]:
match = re.search("List of \d (.+) elements", couple[0])
return ("%s_elements" % match.group(1),couple[1])

fo = open(filename, "r")
RE = re.compile("( *)(.*)")
stack = [("-",[])]
for line in fo:
matches = RE.match(line)
if len(matches.group(2)) > 0:
depth = 1 + len(matches.group(1))
while len(stack) > depth:
stack[-2][1].append(build(stack[-1]))
del stack[-1]
stack.append( (matches.group(2),[]) )
while len(stack) > 1:
stack[-2][1].append(stack[-1])
del stack[-1]
return stack

stanzas = test_parser("test.txt")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help needed with nested parsing of file into objects

2012-06-05 Thread Eelco
> thank you both for your replies. Unfortunately it is a pre-existing
> file format imposed by an external system that I can't
> change. Thank you for the code snippet.

Hi Richard,

Despite the fact that it is a preexisting format, it is very close
indeed to valid YAML code.

Writing your own whitespace-aware parser can be a bit of a pain, but
since YAML does this for you, I would argue the cleanest solution
would be to bootstrap that functionality, rather than roll your own
solution, or to resort to hard to maintain regex voodoo.

Here is my solution. As a bonus, it directly constructs a custom
object hierarchy (obviously you would want to expand on this, but the
essentials are there). One caveat: at the moment, the conversion to
YAML relies on the appparent convention that instances never directly
contain other instances, and lists never directly contain lists. This
means all instances are list entries and get a '-' appended, and this
just works. If this is not a general rule, youd have to keep track of
an enclosing scope stack an emit dashes based on that. Anyway, the
idea is there, and I believe it to be one worth looking at.


import yaml

class A(yaml.YAMLObject):
yaml_tag = u'!A'
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def __repr__(self):
return 'A' + str(self.__dict__)

class B(yaml.YAMLObject):
yaml_tag = u'!B'
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def __repr__(self):
return 'B' + str(self.__dict__)

class C(yaml.YAMLObject):
yaml_tag = u'!C'
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def __repr__(self):
return 'C' + str(self.__dict__)

class TestArray(yaml.YAMLObject):
yaml_tag = u'!TestArray'
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def __repr__(self):
return 'TestArray' + str(self.__dict__)

class myList(yaml.YAMLObject):
yaml_tag = u'!myList'
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def __repr__(self):
return 'myList' + str(self.__dict__)


data = \
"""
An instance of TestArray
 a=a
 b=b
 c=c
 List of 2 A elements:
  Instance of A element
   a=1
   b=2
   c=3
  Instance of A element
   d=1
   e=2
   f=3
 List of 1 B elements
  Instance of B element
   a=1
   b=2
   c=3
   List of 2 C elements
Instance of C element
 a=1
 b=2
 c=3
Instance of C element
 a=1
 b=2
 c=3
An instance of TestArray
 a=1
 b=2
 c=3
""".strip()

#remove trailing whitespace and seemingly erronous colon in line 5
lines = ['  '+line.rstrip().rstrip(':') for line in data.split('\n')]


def transform(lines):
"""transform text line by line"""
for line in lines:
#regular mapping lines
if line.find('=') > 0:
yield line.replace('=', ': ')
#instance lines
p = line.find('nstance of')
if p > 0:
s = p + 11
e = line[s:].find(' ')
if e == -1: e = len(line[s:])
tag = line[s:s+e]
whitespace= line.partition(line.lstrip())[0]
yield whitespace[:-2]+' -'+ ' !'+tag
#list lines
p = line.find('List of')
if p > 0:
whitespace= line.partition(line.lstrip())[0]
yield whitespace[:-2]+'  '+ 'myList:'

##transformed = (transform( lines))
##for i,t in enumerate(transformed):
##print '{:>3}{}'.format(i,t)

transformed = '\n'.join(transform( lines))
print transformed

res = yaml.load(transformed)
print res
print yaml.dump(res)

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


Re: Help needed with nested parsing of file into objects

2012-06-04 Thread richard
On Jun 4, 3:14 pm, Alain Ketterlin 
wrote:
> richard  writes:
> > Hi guys i am having a bit of dificulty finding the best approach /
> > solution to parsing a file into a list of objects / nested objects any
> > help would be greatly appreciated.
>
> > #file format to parse .txt
> > [code]
> > An instance of TestArray
> >  a=a
> >  b=b
> >  c=c
> >  List of 2 A elements:
> >   Instance of A element
>
> [...]
>
> Below is a piece of code that seems to work on your data. It builds a
> raw tree, i leave it to you to adapt and built the objects you want. The
> assumption is that the number of leading blanks faithfully denotes
> depth.
>
> As noted in another message, you're probably better off using an
> existing syntax (json, python literals, yaml, xml, ...)
>
> -- Alain.
>
> #!/usr/bin/env python
>
> import sys
> import re
>
> RE = re.compile("( *)(.*)")
> stack = [("-",[])] # tree nodes are: (head,[children])
> for line in sys.stdin:
>     matches = RE.match(line)
>     if len(matches.group(2)) > 0:
>         depth = 1 + len(matches.group(1))
>         while len(stack) > depth:
>             stack[-2][1].append(stack[-1])
>             del stack[-1]
>             pass
>         stack.append( (matches.group(2),[]) )
>         pass
>     pass
> while len(stack) > 1:
>     stack[-2][1].append(stack[-1])
>     del stack[-1]
>     pass
>
> print(stack)

thank you both for your replies. Unfortunately it is a pre-existing
file format imposed by an external system that I can't
change. Thank you for the code snippet.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help needed with nested parsing of file into objects

2012-06-04 Thread Alain Ketterlin
richard  writes:

> Hi guys i am having a bit of dificulty finding the best approach /
> solution to parsing a file into a list of objects / nested objects any
> help would be greatly appreciated.
>
> #file format to parse .txt
> [code]
> An instance of TestArray
>  a=a
>  b=b
>  c=c
>  List of 2 A elements:
>   Instance of A element
[...]

Below is a piece of code that seems to work on your data. It builds a
raw tree, i leave it to you to adapt and built the objects you want. The
assumption is that the number of leading blanks faithfully denotes
depth.

As noted in another message, you're probably better off using an
existing syntax (json, python literals, yaml, xml, ...)

-- Alain.

#!/usr/bin/env python

import sys
import re

RE = re.compile("( *)(.*)")
stack = [("-",[])] # tree nodes are: (head,[children])
for line in sys.stdin:
matches = RE.match(line)
if len(matches.group(2)) > 0:
depth = 1 + len(matches.group(1))
while len(stack) > depth:
stack[-2][1].append(stack[-1])
del stack[-1]
pass
stack.append( (matches.group(2),[]) )
pass
pass
while len(stack) > 1:
stack[-2][1].append(stack[-1])
del stack[-1]
pass

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


Re: Help needed with nested parsing of file into objects

2012-06-04 Thread Roy Smith
In article 
<6b296278-fd32-45fb-b5c7-6c0fe5ce4...@q2g2000vbv.googlegroups.com>,
 richard  wrote:

> Hi guys i am having a bit of dificulty finding the best approach /
> solution to parsing a file into a list of objects / nested objects any
> help would be greatly appreciated.

The first question is "Why do you want to do this?"  Is this some 
pre-existing file format imposed by an external system that you can't 
change?  Or are you just looking for a generic way to store nested 
structures in a file?

If the later, then I would strongly suggest not rolling your own.  Take 
a look at json or pickle (or even xml) and adopt one of those.
-- 
http://mail.python.org/mailman/listinfo/python-list


Help needed with nested parsing of file into objects

2012-06-04 Thread richard
Hi guys i am having a bit of dificulty finding the best approach /
solution to parsing a file into a list of objects / nested objects any
help would be greatly appreciated.

#file format to parse .txt
[code]
An instance of TestArray
 a=a
 b=b
 c=c
 List of 2 A elements:
  Instance of A element
   a=1
   b=2
   c=3
  Instance of A element
   d=1
   e=2
   f=3
 List of 1 B elements
  Instance of B element
   a=1
   b=2
   c=3
   List of 2 C elements
Instance of C element
 a=1
 b=2
 c=3
Instance of C element
 a=1
 b=2
 c=3

An instance of TestArray
 a=1
 b=2
 c=3
[/code]

expected output
list of 2 TestArray objects been the parents the first one having an
attribute holding a list of the 2 instance of A objects the parents
children, another
attribute of the parent holding a list of just the 1 child instance of
B object with the child object then containing an attribute holding a
list of the 2 Instance of C objects
but the nesting could be more this is just an example. The instance of
TestArray may or may not have any nesting at all
this is illustrated in the second TestArray. Basically just want to
create a list of objects with the objects may or may not contain more
nested objects as attributes but
need a generic way to do it that would work for any amount of depth.

#end list of objects with objects printed as dicts

[code]
parsed = [
{
  "a":"a",
  "b":"b",
  "c":"c",
  "A_elements":[
  {
"a":1,
"b":2,
"c":3
  },
  {
 "a":1,
 "b":2,
 "c":3
  }
   ],
  "B_elements":[
  {
"a":1,
"b":2,
"c":3,
"C_elements":[
 {
 "a":1,
 "b":2,
 "c":3
  },
  {
  "a":1,
  "b":2,
  "c":3
  }
 ]
  }
   ]
},

{
  "a":"1",
  "b":"2",
  "c":"3",
}

]

[/code]

#this is what i have so far which works with the 2nd instance but cant
figure
out the best way to handle the multi nested objects.

[code]
import re
def test_parser(filename):
parent_stanza = None
stanzas = []

class parentStanza:
pass

fo = open(filename)

for line in fo:
line = line.strip()
if re.search("An instance of TestArray", line):
if parent_stanza:
stanzas.append(parent_stanza)
parent_stanza = parentStanza()
if parent_stanza and "=" in line:
attr, val = line.split("=")
setattr(parent_stanza, attr, val)
else:
stanzas.append(parent_stanza)
return stanzas

stanzas = test_parser("test.txt")

import pprint
for stanza in stanzas:
pprint.pprint(stanza.__dict__)
n=raw_input("paused")
[/code]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help needed to understand an error message.

2012-03-30 Thread J. Cliff Dyer
So the problem is that python doesn't know what you're trying to do.  It
doesn't know that you meant to say "print."  When the parser is looking
at the word Print, it assumes you are referencing an object named Print,
which is completely legal.  It's only once you've created the next
token, a string literal, that the parser discovers the error: you can't
have a string literal following a variable.  

*You* think your error is that you misspelled "print."  The parser
thinks your error is trying to put a string literal next to a variable.

Cheers,
Cliff


On Mon, 2012-03-26 at 18:22 +0530, Aloke Ghosh wrote:
> Hi,
> I am learning Python and do not have programming experience.
> I was following
> an exercise from http://learnpythonthehardway.org/book/ex2.html
> and made a mistake in entry :
> 
> 
> Print"I like typing this." 
> 
> 
> and got the following error message:
> 
> 
> In [2]: Print"I like typing this."
> 
>File "", line 1
>  Print"I like typing this."
> ^
> SyntaxError: invalid syntax
> 
> 
> I feel the error is in Capital P in print .
> However the error indicated with "^" 
> hints at quote at the end of the line.
> 
> 
> Can any one please help me understand this.
> 
> 
> -- 
> A.K.Ghosh


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


RE: help needed to understand an error message.

2012-03-26 Thread Prasad, Ramit
>> I feel the error is in Capital P in print .
>> However the error indicated with "*^*" 
>> hints at quote at the end of the line.
> 
> Anyway, the hint indicates the last quote because this is the location
> where the python interpreter realizes it won't be able to execute the
> code. You should not worry about that too much.

Often when I see errors the problem can be earlier in 
the line or a line or two before. Just look backwards 
from where the error says the problem was found.

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

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


Re: help needed to understand an error message.

2012-03-26 Thread Jean-Michel Pichavant

Aloke Ghosh wrote:

Hi,
I am learning Python and do not have programming experience.
I was following 
an exercise from http://learnpythonthehardway.org/book/ex2.html

and made a mistake in entry :

*Print"I like typing this."* 


and got the following error message:

*In [2]: Print"I like typing this."*
**
*   File "", line 1*
* Print"I like typing this."*
*^*
*SyntaxError: invalid syntax*

I feel the error is in Capital P in print .
However the error indicated with "*^*" 
hints at quote at the end of the line.


*Can any one please help me understand this.*

--
A.K.Ghosh

Why don't you just try with a lowercase p ?

The correct syntax would be

print "I like typing this"

or in Python 3:

print ("I like typing this")

Anyway, the hint indicates the last quote because this is the location 
where the python interpreter realizes it won't be able to execute the 
code. You should not worry about that too much.


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


help needed to understand an error message.

2012-03-26 Thread Aloke Ghosh
Hi,
I am learning Python and do not have programming experience.
I was following an exercise from
http://learnpythonthehardway.org/book/ex2.html
and made a mistake in entry :

*Print"I like typing this."*

and got the following error message:

*In [2]: Print"I like typing this."*
**
*   File "", line 1*
* Print"I like typing this."*
*^*
*SyntaxError: invalid syntax*

I feel the error is in Capital P in print .
However the error indicated with "*^*"
hints at quote at the end of the line.

*Can any one please help me understand this.*

-- 
A.K.Ghosh
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help needed to understand the error message

2012-03-23 Thread MRAB

On 24/03/2012 03:37, Aloke Ghosh wrote:

Hi,
I am learning Python and do not have programming experience.
I was following an exercise from
http://learnpythonthehardway.org/book/ex2.html
and made a mistake in entry :

*Print"I like typing this."*

and got the following error message:

*In [2]: Print"I like typing this."*
**
*   File "", line 1*
* Print"I like typing this."*
*^*
*SyntaxError: invalid syntax*

I feel the error is in Capital P in print .


Correct. (I'm assuming that you're using Python 2; Python 3 is a little
different.)


However the error indicated with "*^*"
hints at quote at the end of the line.

*Can any one please help me understand this.*


It will tell you approximately where the error is, but, as in this
example, the actual error may be a little earlier.

It tries to be helpful, but remember that it isn't intelligent! :-)
--
http://mail.python.org/mailman/listinfo/python-list


Help needed to understand the error message

2012-03-23 Thread Aloke Ghosh
Hi,
I am learning Python and do not have programming experience.
I was following an exercise from
http://learnpythonthehardway.org/book/ex2.html
and made a mistake in entry :

*Print"I like typing this."*

and got the following error message:

*In [2]: Print"I like typing this."*
**
*   File "", line 1*
* Print"I like typing this."*
*^*
*SyntaxError: invalid syntax*

I feel the error is in Capital P in print .
However the error indicated with "*^*"
hints at quote at the end of the line.

*Can any one please help me understand this.*

-- 
A.K.Ghosh
Bangalore:560016
Karnataka, India.

Mob : +91 9448116503
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Help needed: dynamically pull data from different levels of a dict

2012-03-01 Thread Peter Rubenstein
Thanks, Chris.  That's the algorithm I was looking for.  And I will be 
converting most of this data to objects.  Thanks again.

-Original Message-
From: Chris Rebert [mailto:c...@rebertia.com] 
Sent: Wednesday, February 29, 2012 11:44 PM
Subject: Re: Help needed: dynamically pull data from different levels of a dict

On Wed, Feb 29, 2012 at 7:56 PM, Peter Rubenstein 
 wrote:
> Hi,
>
> I'd appreciate a bit of help on this problem.  I have some data that 
> I've converted to a dict and I want to pull out individual pieces of it.
>
> Simplified version--
>
> a={'1':'a', '2':'b', '3':{4:'d'}, '5':{'6': {'7': [ {'8':'e'}, 
> {'9':'f'} ] } } }
>
> I'd like to be able to code something like:
>
> data_needed = ['1', '2', '3:4', '5:6:7-8'] for val in data_needed:
> answer=extract_from(a,val)
> print answer
>
> And get:
> a
> b
> c

"c" apparently sprung completely out of thin air...

> d
> e
>
> Problem is I can't figure out what extract_from would look like, such 
> that it would proceed dynamically down to the right level.  I'm open 
> to the possibility that I'm not approaching this the right way.

data_needed = ['1', '2', ('3', '4'), ('5', '6', '7', 0, '8')]

def extract_from(mapping, key_path):
current = mapping
for key in key_path:
current = current[key]
return current


I would perhaps try and restructure the data into something less generic than 
nested dicts & lists, e.g. objects. You then might be able to introduce helper 
querying methods.
I would also be worried about Law of Demeter violations, but fortunately your 
concrete example doesn't reach any deeper than 2 levels.

Cheers,
Chris
--
http://chrisrebert.com


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


Re: Help needed: dynamically pull data from different levels of a dict

2012-02-29 Thread Terry Reedy

On 2/29/2012 11:04 PM, Peter Rubenstein wrote:


I'd appreciate a bit of help on this problem.  I have some data that I've 
converted to a dict and I want to pull out individual pieces of it.

Simplified version--
a={'1':'a', '2':'b', '3':{4:'d'}, '5':{'6': {'7': [ {'8':'e'}, {'9':'f'} ] } } }

I'd like to be able to code something like:

data_needed = ['1', '2', '3:4', '5:6:7-8']for val in data_needed:
answer=extract_from(a,val)print answer

And get:abcde

Problem is I can't figure out what extract_from would look like, such that it 
would proceed dynamically down to the right level.  I'm open to the possibility 
that I'm not approaching this the right way.
If it helps, one member of my actual dict quoted below.  So in real life, 
something likedata_needed=['name','active-defects', 'admin-status:format', 
'description', 'traffic-statistics:input-bps']etc.

Thanks in advance,Peter

{ 'ge-0/0/0': {'active-alarms': {'interface-alarms': {'alarm-not-present': 
''}},  'active-defects': {'interface-alarms': {'alarm-not-present': ''}},  
'admin-status': {'_text': 'up', 'format': 'Enabled'},  
'current-physical-address': '00:1f:12:c0:e8:00',  'description': 
'INFRA:CROSS:ASH-64CB-1B:GE-0/0/0:',  'hardware-physical-address': 
'00:1f:12:c0:e8:00',  'if-config-flags': {'iff-snmp-traps': '', 
'internal-flags': '0x4000'},  'if-device-flags': {'ifdf-present': '', 
'ifdf-running': ''},  'if-flow-control': 'enabled',  'if-media-flags': 
{'ifmf-none': ''},  'interface-flapped': {'_text': '2010-05-23 18:20:36 UTC 
(92w3d 02:27 ago)',   'seconds': '55909644'},  'l2pt-error': 'none',  
'link-level-type': 'Ethernet',  'local-index': '171',  'logical-interface': 
{'address-family': [{'address-family-flags': {'ifff-no-redirects': '',  
'internal-flags': '0x0'}, 'address-family-name': 'inet', 
'interface-address': {'ifa-destination': '207.46.43.2/31',  'ifa-flags': 
{'ifa

f-current-preferred': '', 'ifaf-current-primary': ''},  'ifa-local': 
'207.46.43.2'}, 'mtu': '9178'},{'address-family-flags': 
{'ifff-mtu-user-conf': '',  'internal-flags': '0x1000'}, 
'address-family-name': 'mpls', 'mtu': '9174'},{'address-family-flags': 
{'ifff-none': ''}, 'address-family-name': 'multiservice', 'mtu': 
'Unlimited'}],   'description': 'INFRA:CROSS:ASH-64CB-1B:GE-0/0/0.0:',   
'encapsulation': 'ENET2',   'if-config-flags': {'iff-snmp-traps': ''},   
'local-index': '67',   'name': 'ge-0/0/0.0',   'snmp-index': '117',   
'traffic-statistics': {'input-packets': '46367422526659','output-packets': 
'35670513402384','style': 'brief'}},  'loopback': 'disabled',  'mtu': 
'9192',  'name': 'ge-0/0/0',  'oper-status': 'up',  
'physical-interface-cos-information': {'physical-interface-cos-hw-max-queues': 
'8',   'physical-interface-cos-use-max-queues': '8'},  'snmp-index': '116',  
'source-filtering': 'disabled',  'speed': '10Gbps',  't
raffic-statistics': {'input-bps': '4104358720',   'input-pps': '1059450',   
'output-bps': '232358',   'output-pps': '537816',   'style': 'brief'}},}



--
Terry Jan Reedy

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


Re: Help needed: dynamically pull data from different levels of a dict

2012-02-29 Thread Chris Rebert
On Wed, Feb 29, 2012 at 7:56 PM, Peter Rubenstein
 wrote:
> Hi,
>
> I'd appreciate a bit of help on this problem.  I have some data that I've
> converted to a dict and I want to pull out individual pieces of it.
>
> Simplified version--
>
> a={'1':'a', '2':'b', '3':{4:'d'}, '5':{'6': {'7': [ {'8':'e'}, {'9':'f'} ] }
> } }
>
> I'd like to be able to code something like:
>
> data_needed = ['1', '2', '3:4', '5:6:7-8']
> for val in data_needed:
>     answer=extract_from(a,val)
>     print answer
>
> And get:
> a
> b
> c

"c" apparently sprung completely out of thin air...

> d
> e
>
> Problem is I can't figure out what extract_from would look like, such that
> it would proceed dynamically down to the right level.  I'm open to the
> possibility that I'm not approaching this the right way.

data_needed = ['1', '2', ('3', '4'), ('5', '6', '7', 0, '8')]

def extract_from(mapping, key_path):
current = mapping
for key in key_path:
current = current[key]
return current


I would perhaps try and restructure the data into something less
generic than nested dicts & lists, e.g. objects. You then might be
able to introduce helper querying methods.
I would also be worried about Law of Demeter violations, but
fortunately your concrete example doesn't reach any deeper than 2
levels.

Cheers,
Chris
--
http://chrisrebert.com
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   5   >