Re: Python 3 is killing Python

2014-07-16 Thread Javier
> I don't see anyone taking the Python 2 source code and backporting a
> bunch of Python 3 features (and/or adding a bunch of their own
> features) and creating the Python 2.8 that
> http://blog.startifact.com/guido_no.jpg rejects. What split is
> actually occurring, or going to occur? I think anyone who talks of
> splitting has an unrealistically low idea of the costs of such a
> split; moving away from what the core Python devs are doing means
> setting up everything fresh, and it's just way too much work to do
> that.

Up to now there have been no attemps of forking because python2.x was
still being developed and they even ported some of the features of
python3 to 2.6/2.7.

I think there has been a severe miscalculation, and the change in the
name of the interpreter python3 to python
http://legacy.python.org/dev/peps/pep-0394/ is a good example of the
disconnection between GvR and the real world.

Arch Linux was the only distro to fall in the trap, and those who use
it (as myself) need to put fake executables in /usr/local/bin
for everything: (python, sphinx, virtualenv...) selecting 2 or 3

http://sindhus.bitbucket.org/manage-python-2-3.html

Things are a bit more complex than just changing '#!/usr/bin/env python'
to '#!/usr/bin/env python2'

Let's see what it happens now that no more features are added to 2.x.
2.8 fork anybody?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Multiple python versions, one dev environment???

2014-07-17 Thread Javier
Are you using arch linux.  


I deal with multiple interpreters putting fake executables in
/usr/local/bin for everything: (python, sphinx, virtualenv, pydoc,
idle, python-config...) selecting 2 or 3.  You can do the same for
selecting 2.3, 2.5, 2.7.  What the scripts do is to detect whether it
is a system script whose prefix starts with /usr/bin, or whether it is
a user script.  Being in /usr/local/bin they will override executables
in /usr/bin. Remember to chmod a+x the files in /usr/local/bin

http://sindhus.bitbucket.org/manage-python-2-3.html
http://stackoverflow.com/questions/15400985/how-to-completely-
replace-python-3-with-python-2-in-arch-linux
https://wiki.archlinux.org/index.php/Python#Dealing_with_
version_problem_in_build_scripts

I use these scripts, but there is more than one way to do it

/usr/local/bin/python===
#!/bin/bash
script=`readlink -f -- "$1"`
case "$script" in
/usr/bin*)
exec python3 "$@"
;;
esac
exec python2 "$@"

/usr/local/bin/virtualenv===
#!/bin/bash
script=`readlink -f -- "$1"`
case "$script" in
/usr/bin*)
exec virtualenv3 "$@"
;;
esac

exec virtualenv2 "$@"








Joep van Delft  wrote:
> Hello! 
> 
> The condensed version of the question would probably be: How does one
> deal with multiple interpreters and one package where you want to try
> some changes? 
> 
> The background: 
> I made a trivial change to some package (docutils) to scratch a
> personal itch, and I want to offer this back to the community
> (whether it will be accepted or not). Because of this, I ran into
> some issues. 
> 
> Some facts:
> 1. Python3 is my main interpreter. 
> 2. The tests of docutils only run under python2.
> 3. I desire not to touch my distribution's version of
>   site-packagesX-Y.
> 4. I prefer to have one and only one development directory of
>   my target package. 
> 
> My confusions: 
> 1. Is it possible to have one source control managed directory of
>   some package, which is used by two versions of python? 
> 2. I assume that the *.pyc-files generated while using some python
>   source are version dependent. What is the recommended way to have
>   'em both installed? 
> 3. The way I have stumped a wall over here, is the puzzle of how to
>   make python2 have a different $PYTHONPATH as python3. I hope to
>   hear how this strategy is silly :) 
> 4. I have contemplated the way of linking the source files from my
>   development directory into user specified site-packages
>   directories. Problem 3. still is valid. 
> 5. Should venv and friends/foes com into play? If so: How? 
> 
> Appreciate any light shed on these issues. 
> 
> Thanks! 
> 
> 
>Joep
> 
> 
> 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Multiple python versions, one dev environment???

2014-07-17 Thread Javier
> I can work with this (have not tried though), but there must be a
> more elegant solution than symlinking my way forward... 


I don't really understand what you are trying to do, but I would advise
to use environment variables to control the behaviour of the fake scripts
in /usr/local/bin

In bash you can do 

export PYVERSION=2.5

And from that time onwards everything defaults to python2.5.

note the ${PYVERSION} that I have included now in the sample scripts
below to select the python version.


I don't think you need to, but if you want to change the environment
variable inside python you can set environment variables with something like
os.environ.?  Look at the docs.


Caveat1: I have not tested this, but it should work ok.  The setup I use is
much simpler: just default to python2.7

Caveat2: Arch linux packagers dont use a consistent naming of things:
There exists /usr/bin/virtualenv3, but there does not exist
/usr/bin/sphinx-build3 (it is /usr/bin/sphinx-build)
Somebody should send a bug to the package maintainer.

PS: Once you setup a workaround to bypass all the python=python3 nonsense,
Arch Linux is a nice linux distro, the best out there.  I will stick
to it.

HTH

/usr/local/bin/python===
#!/bin/bash
script=`readlink -f -- "$1"`
case "$script" in
/usr/bin*)
exec python3 "$@"
;;
esac
exec python${PYVERSION} "$@"

/usr/local/bin/virtualenv===
#!/bin/bash
script=`readlink -f -- "$1"`
case "$script" in
/usr/bin*)
exec virtualenv3 "$@"
;;
esac

exec virtualenv${PYVERSION} "$@"



Joep van Delft  wrote:
> Hello Javier! 
> 
> Thanks, those links are helping a bit. And: yes, I am using Archlinux.
> 
> But still those links assume that there are totally separate
> site-packages* directories installed for both. I am not sure how I
> would surpass this distinction between py-X.P and py-Y.Q. 
> 
> Should I really create a massive amount of symlinks like this?: 
> 
> | #!/usr/bin/zsh
> | for d in ~/src/mypackage/**/*(/); do 
> |# matches all directories
> |mkdir -p "~/src/py-2.7/mypackage/${d#*src/mypackage}"
> |mkdir -p "~/src/py-3.4/mypackage/${d#*src/mypackage}"
> | done
> | for f in ~/src/mypackage/**/^*.pyc(.); do 
> |# matches all files except for *.pyc
> |ln -s "$f" "~/src/py-2.7/mypackage${f#*src/mypackage}"
> |ln -s "$f" "~/src/py-3.4/mypackage${f#*src/mypackage}"
> | done
> 
> ...and then set $PYTHONPATH according to the target version in a
> #!/usr/local/bin-script? 
> 
> I can work with this (have not tried though), but there must be a
> more elegant solution than symlinking my way forward... 
> 
> Cheers!
> 
> 
>Joep
> 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Clize 3.0b1: An argument parser that draws a CLI from your function sigature

2015-04-27 Thread Javier
It would be nice if it could automatically generate the python code
for 'clizing a function', i.e., from the example in
https://clize.readthedocs.org/en/latest/

def hello_world(name=None, no_capitalize=False):
...

being able to do

clize.generate_py_code(hello_world)

which would return something in the fashion of
"""
if __name__ == '__main__':
###process sys.argv
...
name=sys.argv[1]
no_capitalize=...
hello_world(name=name, no_capitalize=no_capitalize)
"""

Sometimes you may want to eliminate dependencies.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Send data to asyncio coroutine

2015-07-28 Thread Javier
El martes, 21 de julio de 2015, 15:42:47 (UTC+2), Ian  escribió:
> On Tue, Jul 21, 2015 at 5:31 AM,   wrote:
> > Hello, I'm trying to understand and link asyncio with ordinary coroutines. 
> > Now I just want to understand how to do this on asyncio:
> >
> >
> > def foo():
> > data = yield 8
> > print(data)
> > yield "bye"
> >
> > def bar():
> > f = foo()
> > n = f.next()
> > print(n)
> > message = f.send("hello")
> > print(message)
> >
> >
> > What is the equivalent for coro.send("some data") in asyncio?
> 
> I don't know of any reason why you couldn't do it just like the above.
> However, the exchange would not be asynchronous, if that is your goal.
> 
> > coro.send on an asyncio coroutine throws AssertionError: yield from wasn't 
> > used with future.
> 
> So somehow a future got involved where it shouldn't have been. What
> was the actual code that you tried to run?
> 
> Note that while "yield" and "yield from" look similar, they are quite
> different, and you cannot send to a generator that is currently paused
> at a "yield from".
> 
> If you want to emulate bidirectional communication similar to
> coro.send asynchronously, I think you'll need to use Futures to
> mediate, something like this (lightly tested):
> 
> @asyncio.coroutine
> def foo(fut):
> data, fut = yield from send_to_future(8, fut)
> print("foo", data)
> fut.set_result("bye")
> 
> @asyncio.coroutine
> def bar():
> n, fut = yield from start_coro(foo)
> print("bar", n)
> message = yield from send_to_future("hello", fut)
> print("bar", message)
> 
> def start_coro(coro):
> future = asyncio.Future()
> asyncio.async(coro(future))
> return future
> 
> def send_to_future(data, future):
> new_future = asyncio.Future()
> future.set_result((data, new_future))
> return new_future




Hello again. I have been investigating a bit your example. I don't understand 
why I can't write something like this:



import asyncio

def foo():
print("start foo")
try:
while True:
val = yield
print("foo:", val)
yield from asyncio.sleep(3)
except GeneratorExit:
print("foo closed")
print("exit foo")

def bar(next):
print("start bar")
next.send(None)
try:
while True:
val = yield
next.send("bar/"+val)
except GeneratorExit:
print("bar closed")
print("exit bar")

def fun(next):
next.send(None)
for e in ["hello", "world", "I'm", "pythonist"]:
next.send(e)

@asyncio.coroutine
def run():
fun(bar(foo()))

loop = asyncio.get_event_loop()
loop.run_until_complete(run())
loop.close()

---

The expected output is:

start bar
start foo
foo: bar/hello
foo: bar/world
foo: bar/I'm
foo: bar/phytonist
bar closed
exit bar
foo closed
exit foo

But the yield from asyncio.sleep(3) call raises AssertionError, however it's 
inside a Task!
I think this is a big flaw in python/asyncio design.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Send data to asyncio coroutine

2015-07-28 Thread Javier
El martes, 28 de julio de 2015, 23:18:11 (UTC+2), Javier  escribió:
> El martes, 21 de julio de 2015, 15:42:47 (UTC+2), Ian  escribió:
> > On Tue, Jul 21, 2015 at 5:31 AM,   wrote:
> > > Hello, I'm trying to understand and link asyncio with ordinary 
> > > coroutines. Now I just want to understand how to do this on asyncio:
> > >
> > >
> > > def foo():
> > > data = yield 8
> > > print(data)
> > > yield "bye"
> > >
> > > def bar():
> > > f = foo()
> > > n = f.next()
> > > print(n)
> > > message = f.send("hello")
> > > print(message)
> > >
> > >
> > > What is the equivalent for coro.send("some data") in asyncio?
> > 
> > I don't know of any reason why you couldn't do it just like the above.
> > However, the exchange would not be asynchronous, if that is your goal.
> > 
> > > coro.send on an asyncio coroutine throws AssertionError: yield from 
> > > wasn't used with future.
> > 
> > So somehow a future got involved where it shouldn't have been. What
> > was the actual code that you tried to run?
> > 
> > Note that while "yield" and "yield from" look similar, they are quite
> > different, and you cannot send to a generator that is currently paused
> > at a "yield from".
> > 
> > If you want to emulate bidirectional communication similar to
> > coro.send asynchronously, I think you'll need to use Futures to
> > mediate, something like this (lightly tested):
> > 
> > @asyncio.coroutine
> > def foo(fut):
> > data, fut = yield from send_to_future(8, fut)
> > print("foo", data)
> > fut.set_result("bye")
> > 
> > @asyncio.coroutine
> > def bar():
> > n, fut = yield from start_coro(foo)
> > print("bar", n)
> > message = yield from send_to_future("hello", fut)
> > print("bar", message)
> > 
> > def start_coro(coro):
> > future = asyncio.Future()
> > asyncio.async(coro(future))
> > return future
> > 
> > def send_to_future(data, future):
> > new_future = asyncio.Future()
> > future.set_result((data, new_future))
> > return new_future
> 
> 
> 
> 
> Hello again. I have been investigating a bit your example. I don't understand 
> why I can't write something like this:
> 
> 
> 
> import asyncio
> 
> def foo():
> print("start foo")
> try:
> while True:
> val = yield
> print("foo:", val)
> yield from asyncio.sleep(3)
> except GeneratorExit:
> print("foo closed")
> print("exit foo")
> 
> def bar(next):
> print("start bar")
> next.send(None)
> try:
> while True:
> val = yield
> next.send("bar/"+val)
> except GeneratorExit:
> print("bar closed")
> print("exit bar")
> 
> def fun(next):
> next.send(None)
> for e in ["hello", "world", "I'm", "pythonist"]:
> next.send(e)
> 
> @asyncio.coroutine
> def run():
> fun(bar(foo()))
> 
> loop = asyncio.get_event_loop()
> loop.run_until_complete(run())
> loop.close()
> 
> ---
> 
> The expected output is:
> 
> start bar
> start foo
> foo: bar/hello
> foo: bar/world
> foo: bar/I'm
> foo: bar/phytonist
> bar closed
> exit bar
> foo closed
> exit foo
> 
> But the yield from asyncio.sleep(3) call raises AssertionError, however it's 
> inside a Task!
> I think this is a big flaw in python/asyncio design.


I think that force the developer to 'yield from' all function calls to keep 
async capabilities is a big mistake, it should be more flexible, like this:

import asyncio

@asyncio.coroutine
fun non_blocking_io():
""" Everybody knows I'm doing non blocking IO """
...

fun foo():
""" I invoke functions that do IO stuff """
data = yield from non_blocking_io()
yield from store_data_db(data)
...

fun bar():
""" I don't know what foo implementation does """
foo()

asyncio.async(bar())


Does python 3.5 await/async solve this?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Send data to asyncio coroutine

2015-07-29 Thread Javier
El miércoles, 29 de julio de 2015, 1:07:22 (UTC+2), Ian  escribió:
> On Tue, Jul 28, 2015 at 1:17 PM, Javier  wrote:
> > Hello again. I have been investigating a bit your example. I don't 
> > understand why I can't write something like this:
> >
> > 
> >
> > import asyncio
> >
> > def foo():
> > print("start foo")
> > try:
> > while True:
> > val = yield
> > print("foo:", val)
> > yield from asyncio.sleep(3)
> > except GeneratorExit:
> > print("foo closed")
> > print("exit foo")
> >
> > def bar(next):
> > print("start bar")
> > next.send(None)
> > try:
> > while True:
> > val = yield
> > next.send("bar/"+val)
> > except GeneratorExit:
> > print("bar closed")
> > print("exit bar")
> >
> > def fun(next):
> > next.send(None)
> > for e in ["hello", "world", "I'm", "pythonist"]:
> > next.send(e)
> >
> > @asyncio.coroutine
> > def run():
> > fun(bar(foo()))
> >
> > loop = asyncio.get_event_loop()
> > loop.run_until_complete(run())
> > loop.close()
> 
> Because "yield from asyncio.sleep(3)" doesn't magically pause the
> coroutine as you want it to. It yields a future, which is meant to be
> yielded back up the coroutine chain to the event loop. The event loop
> would then resume the coroutine once the future is done, which in the
> case of asyncio.sleep will happen after the sleep timer completes.
> 
> In your example, the future never makes it back to the event loop.
> asyncio.sleep yields the future to foo, and since foo is suspended by
> a yield from, foo yields the future to bar, where it is the result of
> the next.send call. The return value of next.send is ignored, so the
> future just gets dropped on the floor at this point. bar yields to
> fun, which sends bar the next string in its list, "world". bar sends
> "world" to foo, and since foo is still suspended by a yield from, it
> sends "world" on to the asyncio.sleep future. Not a new asyncio.sleep
> future, but the same one that it's still yielding from. The future
> then realizes that something is wrong, because its generator code is
> running again but it doesn't have a result yet, so it throws that
> AssertionError.
> 
> If you want the yield from in foo to work properly, then you need to
> make sure that the future gets back to the event loop, and if you do
> that in some tricky way other than a yield from chain, you'll also
> need to make sure that you're not trying to send it more data before
> foo has resumed.
> 
> > I think this is a big flaw in python/asyncio design.
> 
> I don't entirely disagree. I think that the implementation of async
> coroutines on top of synchronous coroutines on top of generators is
> overly clever and results in a somewhat leaky abstraction and a fair
> amount of confusion.



I see, so I was wrong. I used to see event loop, and yield from as a language 
improvement but it's actually a library improvement that, as a side effect, 
prevents you from usign some language features like ordinary 
generator/coroutine communication. That is a pity. 

Thank you very much for your time and explanations, now I understand some 
points. I'll keep on learning asyncio.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Send data to asyncio coroutine

2015-08-01 Thread Javier
El martes, 21 de julio de 2015, 13:31:56 (UTC+2), Javier  escribió:
> Hello, I'm trying to understand and link asyncio with ordinary coroutines. 
> Now I just want to understand how to do this on asyncio:
> 
> 
> def foo():
> data = yield 8
> print(data)
> yield "bye"
> 
> def bar():
> f = foo()
> n = f.next()
> print(n)
> message = f.send("hello")
> print(message)
> 
> 
> What is the equivalent for coro.send("some data") in asyncio?
> 
> coro.send on an asyncio coroutine throws AssertionError: yield from wasn't 
> used with future.
> 
> 
> Thank you




Asyncio is a crazy headache! I realized that I can't use asyncio tcp servers 
with pickle! Asyncio is good as a concept but bad in real life. 

I think python's non blocking I/O is far from being something useful for 
developers till non-async code can invoke async code transparently. Duplicating 
all code/libs when you realize that something not fits asyncio is not a 
solution and even less a pythonic solution.

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


Re: Send data to asyncio coroutine

2015-08-01 Thread Javier
El sábado, 1 de agosto de 2015, 19:19:00 (UTC+2), Marko Rauhamaa  escribió:
> Javier :
> 
> > Asyncio is a crazy headache! I realized that I can't use asyncio tcp
> > servers with pickle! Asyncio is good as a concept but bad in real
> > life.
> >
> > I think python's non blocking I/O is far from being something useful
> > for developers till non-async code can invoke async code
> > transparently. Duplicating all code/libs when you realize that
> > something not fits asyncio is not a solution and even less a pythonic
> > solution.
> 
> After all these decades, we are still struggling to find the naturally
> flowing paradigm for asynchronous programming. Different
> approaches/libraries/frameworks don't usually mix well or at all.
> 
> First, I believe it has been a grave mistake to write a ton of utility
> libraries that block. They make it easy to put together a prototype, but
> before long you realize the mess they have led you to and the only way
> out is a complete rewrite or a number of complicated adapters that drain
> performance, hurt quality and don't really add true value.
> 
> Could asyncio be the basis of a de-facto Python way of doing
> asynchronous programming? Maybe. GvR definitely has that intention.
> However, I'm afraid the paradigm is quite unnatural. Essentially, it is
> thread programming where blocking calls are replaced with funny syntax.
> Most developers are familiar with multithreading, but they often are not
> actively aware what functions are blocking. Reading from a socket is
> blocking. Writing to a socket is blocking as well. Is file I/O blocking?
> Is database access blocking? Is socket.getaddrinfo() blocking?
> 
> A function may be nonblocking in one release of a package but might then
> become blocking in the next release.
> 
> I'm an advocate of the "callback hell" together with clearly expressed
> finite state machines. They are super easy to understand. They lead to
> very complicated code but the complications can be analyzed and debugged
> based on the elementary knowledge. Also, you don't need a complicated
> framework for it. The only thing missing from select.epoll() is timers,
> but timers are not all that hard to implement (especially if you had an
> a balanced tree implementation at your disposal).
> 
> Still, even the select.epoll() method requires callback implementations
> of the different protocols and databases.
> 
> 
> Marko

I agree with you, Marko, I came from callbacks too. So, if GvR wants the yield 
from become de-facto, does it mean that all python libraries will evolve to 
become asyncio friendly libs? or that I have to write my own library so I can 
use existing libraries like pickle? I think "callback hell" is "peccata minuta" 
compared with "yield from hell".



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


Re: Send data to asyncio coroutine

2015-08-01 Thread Javier
El sábado, 1 de agosto de 2015, 18:45:17 (UTC+2), Mark Lawrence  escribió:
> On 01/08/2015 17:07, Javier wrote:
> >
> > Asyncio is a crazy headache! I realized that I can't use asyncio tcp 
> > servers with pickle! Asyncio is good as a concept but bad in real life.
> >
> > I think python's non blocking I/O is far from being something useful for 
> > developers till non-async code can invoke async code transparently. 
> > Duplicating all code/libs when you realize that something not fits asyncio 
> > is not a solution and even less a pythonic solution.
> >
> 
> I'll keep my eyes open for your solution on pypi as clearly you know 
> better than the Python core developers.  Fully documented and tested of 
> course.
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

Don't be rascal, friend. Nobody thinks that self is better than core 
developers, and personaly I don't think I am better than anybody, but, I have 
my own opinion.
The fact that the core team is better at python coding and compilers than me 
does not mean that her implementation fits my needs/opinion.

I dont like the current event loop implementation (plus yield from): 
- It forces me to use beta libraries for doing something that another 
production ready library already does, 
- I can't use one of the most awesome python features: yielding between 
generators and coroutines
- As you said, I'm not as smart as they are but I thought python is for 
everybody, not only for them. Should I ask them how can I use pickle with 
streamreader? I think it would be better if it would become trivial.


I read PEPs. I don't imagine a good users community if all of us would have to 
read the pythons source code to understand how to use new features or rewrite a 
new implementation proposal to be allowed to tell our opinion, as you claims, 

I would like that all the code would run on event loop, but till then I just 
believe that event loop should be a native feature, not a python hack. I 
believe that we should be able to call asyncio functions without doing "yield 
from" through all the stack. I believe that It's possible an implementation 
that allows generators for processing data streams and that allows to mix 
classic code with loop code.

And finally I claim a place for not super-level pythoners that want to talk 
about features improvement without being asked for a reference implementation, 
each of us have our own role.

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


Re: Send data to asyncio coroutine

2015-08-01 Thread Javier
El sábado, 1 de agosto de 2015, 20:46:49 (UTC+2), Mark Lawrence  escribió:
> On 01/08/2015 19:38, Marko Rauhamaa wrote:
> > Javier :
> >
> >> El sábado, 1 de agosto de 2015, 18:45:17 (UTC+2), Mark Lawrence  escribió:
> >>> clearly you know better than the Python core developers
> >>
> >> Nobody thinks that self is better than core developers, and personaly
> >> I don't think I am better than anybody, but, I have my own opinion.
> >
> > It is odd how an engineering forum like this one so often judges ideas
> > based on the pedigree of the participants rather than objective
> > technical arguments.
> >
> >
> > Marko
> >
> 
> What I find odd is that the bleating and whinging comes long after the 
> PEP process has finished and the code is already in production. 
> Wouldn't it be easier for everybody all around to sort this out right at 
> the start of the process?
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence


I think so too, Mark, but I talk about it when I have used it. I came from 
blocking IO development. But isn't this a live language?

Well! let's forget all this and let's work with python 3.4 :)


My intention now is to use the asyncio.StreamReader passed as argument to the 
asyncio.start_server callback to read objects serialized with pickle. The 
problems are that pickle cant read from it (because dont yield from the full 
stack) and that I don't know the exact length of each serialized object, so I 
can't extract data manually.

Knows anybody the steps to follow?

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


Re: Send data to asyncio coroutine

2015-08-01 Thread Javier
El sábado, 1 de agosto de 2015, 21:15:07 (UTC+2), Marko Rauhamaa  escribió:
> Javier :
> 
> > My intention now is to use the asyncio.StreamReader passed as argument
> > to the asyncio.start_server callback to read objects serialized with
> > pickle. The problems are that pickle cant read from it (because dont
> > yield from the full stack) and that I don't know the exact length of
> > each serialized object, so I can't extract data manually.
> >
> > Knows anybody the steps to follow?
> 
> You probably need to frame your pickled encoding. A simple thing would
> be to use struct.pack/unpack to encode the length of the pickle encoding
> in front of the pickle encoding. When decoding, you first read out the
> length, then the pickle encoding, and finally you unpickle the payload.
> 
> 
> Marko


Great! it works! I could not find a way to send an integer with fixed length, 
struct.pack/unpack does the job perfectly.

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


monospaced font in MS Windows with wxpython

2015-09-11 Thread Javier
I am trying to use a monospaced font (preferably small) in MS Windows
with wxpython.  I have tried

txtctrl.SetFont(wx.Font(10, wx.MODERN, wx.NORMAL, wx.NORMAL, False, 
u'Consolas'))

but no success, I still get a proportional font.

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


Re: monospaced font in MS Windows with wxpython

2015-09-11 Thread Javier
The font I posted before was actually monospaced.
I was just putting the definition in the wrong place

All solved now.  Sorry for the noise.

> txtctrl.SetFont(wx.Font(10, wx.MODERN, wx.NORMAL, wx.NORMAL, False, 
> u'Consolas'))

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


Tools for refactoring/obfuscation

2012-03-06 Thread Javier
I am looking for an automated tool for refactoring/obfuscation.
Something that changes names of functions, variables, or which would
merge all the functions of various modules in a single module.
The closest I have seen is http://bicyclerepair.sourceforge.net/

Does somebody know of something that can work from the command line or
simple data structures/text files?, like a python dictionary of functions
{"old":"new",...}

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


Re: Tools for refactoring/obfuscation

2012-03-28 Thread Javier
Yes, in general I follow clear guidelines for writing code.  I just use
modules with functions in the same directory and clear use of name
spaces. I almost never use classes.  I wonder if you use some tool for
refactoring.  I am mainly intersted in scripting tools, no eclipse-style
guis.

Just let me know if you use some scripting tool.

And, as somebody pointed in this thread obfuscating or refactoring the
code are very different things but they can be done with the same tools.

Javier


Vladimir Ignatov  wrote:
> Hi,
> 
> (sorry for replying to the old topic)
> 
> On Tue, Mar 6, 2012 at 10:29 PM, Javier  wrote:
>> I am looking for an automated tool for refactoring/obfuscation.
>> Something that changes names of functions, variables, or which would
>> merge all the functions of various modules in a single module.
>> The closest I have seen is http://bicyclerepair.sourceforge.net/
>>
>> Does somebody know of something that can work from the command line or
>> simple data structures/text files?, like a python dictionary of functions
>> {"old":"new",...}
> 
> I am not surprised what nobody answers. I think that such tool is
> nearly impossible given the dynamic Python's nature.
> But if you put little discipline/restrictions in your source code,
> when doing obfuscation could be much more easier. Almost trivial I
> would say.
> 
> Javier, you can contact me directly if you are interested in this topic.
> 
> Vladimir Ignatov
> kmisoft at gmail com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tools for refactoring/obfuscation

2012-04-02 Thread Javier
Well, a .pyc file would be a too blatant obfuscation, and people at my
job would get angry.  I need something more subtle.  So I need a
refactoring tool, preferably with which I can do scripting.  These is
what I found up to now in the CheeseShop:

http://pypi.python.org/pypi/bicyclerepair/0.7.1
http://pypi.python.org/pypi/rope/0.9.3

I need to check how to do scripting with them.  There seems to be no
manual for them.

This code also looks interesting, but in its present state it is for
blatant obfuscation, although it could be changed to do some refactoring:

http://pypi.python.org/pypi/pyfuscate/0.1





Lie Ryan  wrote:
> On 03/29/2012 03:04 AM, Javier wrote:
>> Yes, in general I follow clear guidelines for writing code.  I just use
>> modules with functions in the same directory and clear use of name
>> spaces. I almost never use classes.  I wonder if you use some tool for
>> refactoring.  I am mainly intersted in scripting tools, no eclipse-style
>> guis.
>>
>> Just let me know if you use some scripting tool.
>>
>> And, as somebody pointed in this thread obfuscating or refactoring the
>> code are very different things but they can be done with the same tools.
> 
> if you're not using classes, your code is obfuscated already
> 
> Anyway, I think it's better if you describe why you want such a tool. If 
> you want to keep your code a secret, just distribute the .pyc file. If 
> you want to refactor your code to improve readability, there is rope.
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a directory structure and modifying files automatically in Python

2012-05-06 Thread Javier
>Learn how to use a database.  Creating and managing a
> big collection of directories to handle small data items is the
> wrong approach to data storage.
>
>John Nagle

Or not... Using directories may be a way to do rapid prototyping, and
check quickly how things are going internally, without needing to resort
to complex database interfaces.

Just a quote from the history of usenet:

   I wrote the very first version of
   netnews as a 150-line shellscript. It
   had multiple newsgroups and
   cross-posting; newsgroups were
   directories and cross-posting was
   implemented as multiple links to the
   article. It was far too slow to use
   for production, but the flexibility
   permitted endless experimentation with
   the protocol design.
   -- Steven M. Bellovin

http://www.linuxtopia.org/online_books/programming_books/art_of_unix_programming/ch14s04_2.html

for the question of the OP:

import string
import os
namefile="..."
for line in open("foobar").readlines()
   dirname,number=string.split(line)
   os.system("mkdir "+dirname)
   f=open(dirname+"/"+namefile,"w")
   f.write("TEXT..."+number)
   f.close()

Portability can be improved by using os.path or something like that.




John Nagle  wrote:
> On 4/30/2012 8:19 AM, deltaquat...@gmail.com wrote:
>> Hi,
>>
>> I would like to automate the following task under Linux. I need to create a 
>> set of directories such as
>>
>> 075
>> 095
>> 100
>> 125
>>
>> The directory names may be read from a text file foobar, which also contains 
>> a number corresponding to each dir, like this:
>>
>> 075 1.818
>> 095 2.181
>> 100 2.579
>> 125 3.019
>>
>>
>> In each directory I must copy a text file input.in. This file contains  two 
>> lines which need to be edited:
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: usenet reading

2012-05-26 Thread Javier
news.aioe.org
nntp.aioe.org


http://www.aioe.org/

Aioe.org hosts a public news server, an USENET site that is
intentionally kept open for all IP addresses without requiring any kind
of authentication both for reading and posting.Each IP address is
authorized to post 25 messages per day...





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


Re: Extending dict (dict's) to allow for multidimensional dictionary

2011-03-06 Thread Javier
Looks a good idea.  I use this kind of "recursive dicts" to represent
tree like datastruct in python.  Like:

car["ford"]["taurus"]["price"]=...
car["toyota"]["corolla"]["mpg"]=...
car["toyota"]["corolla"]["price"]=...


It would be good if it could be combined with class2dict (converting
dict elemnets into attributes of a class/instance), 

http://vsbabu.org/mt/archives/2003/02/13/joy_of_python_classes_and_dictionaries.html

so the former would look a bit nicer:

car.toyota.corolla.mpg=...
car.toyota.corolla.price=...

Does anybody have  another idea for representing tree-like data?  Is
there another type for trees in python?



Ravi  wrote:
> I found a solution here:
> 
> http://parand.com/say/index.php/2007/07/13/simple-multi-dimensional-dictionaries-in-python/
> 
> Please tell how good is it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Eigensolver for Large Sparse Matrices in Python

2011-06-09 Thread Javier
Hi,

I think you can also use scipy.sparse.linalg.eigen.arpack in addition to 
scipy.sparse.linalg.eigen.lobpcg

Also, from my experience with this routines I can tell you that they
don't like to be asked a small number of eigenvalues.
Contrary to common sense I have found these routines to prefer to
calculate 30 eigenvalues than 5 eigenvalues.  Try to ask it for more
eigenvalues.

Does anybody know why the routines don't work well when they are aked
for  small number of eigenvalues?

Andrew MacLean  wrote:
> Hi,
> 
> I need to solve symmetric generalized eigenvalue problems with large,
> sparse stiffness
> and mass matrices, say 'A' and 'B'. The problem is of the form Av =
> lambdaBV. I have been using lobpcg (scipy.sparse.linalg.lobpcg), in
> Scipy 0.7.2, although this has been giving me incorrect values that
> are also about 1000 times too large.
> 
> They are both Hermitian, and 'B' is positive definite, and both are of
> approximately of size 70 000 x 70 000. 'A' has about 5 million non-
> zero values and 'B'
> has about 1.6 million. 'A' has condition number on the order of 10^9
> and 'B' has a condition number on the order of 10^6. I have stored
> them both as "csc" type sparse matrices from the scipy.sparse library.
> 
> The part of my code using lobpcg is fairly simple (for the 20 smallest
> eigenvalues):
> 
> from scipy.sparse.linalg import lobpcg
> from scipy import rand
> 
> X = rand(A.shape[0], 20)
> 
> W, V = lobpcg (A, X, B = B, largest = False, maxiter = 40)
> ---
> 
> I tested lobpcg on a "scaled down" version of my problem, with 'A' and
> 'B' matrices of size 10 000 x 10 000, and got the correct values
> (using maxiter = 20), as confirmed by using the "eigs" function in
> Matlab. I used it here to find the smallest 10 eigenvalues, and here
> is a table of my results, showing that the eigenvalues computed from
> lobpcg in Python are very close to those using eigs in Matlab:
> 
> https://docs.google.com/leaf?id=0Bz-X2kbPhoUFMTQ0MzM2MGMtNjgwZi00N2U0...
> 
> With full sized 'A' and 'B' matrices, I could not get the correct
> values, and it became clear that increasing the maximum number of
> iterations indefinitely would not work (see graph below). I made a
> graph for the 20th smallest eigenvalue vs. the number of iterations. I
> compared 4 different guesses for X, 3 of which were just random
> matrices (as in the code above), and a 4th orthonormalized one.
> 
> https://docs.google.com/leaf?id=0Bz-X2kbPhoUFYTM4OTIxZGQtZmE0Yi00MTMy...
> 
> It appears that it will take a very large number of iterations to get
> the correct eigenvalues.  As well, I tested lobpcg by using
> eigenvectors generated by eigs in
> Matlab as X, and lobpcg returned the correct values.
> 
> I don't believe it is a bug that was solved for lobpcg in newer
> versions of Scipy, as I have also gotten the same problem using the
> most recent version (4.12) of lobpcg for Matlab.
> 
> If anyone has any suggestions for how to improve the results of
> lobpcg, or has experience with an alternate solver (such as JDSYM from
> Pysparse or eigsh in newer versions of Scipy) with matrices of this
> size, any recommendations would be grealty appreciated.
> 
> Thanks,
> Andrew
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: i want to learn pyqt ,but i have no c++ knowlage. is it ok????

2011-06-10 Thread Javier
??  wrote:
> i want to learn pyqt ,but i have no c++ knowlage. is it ok


It should be ok.  I would recoomend this book:

"Rapid GUI Programming with Python and Qt" (Prentice Hall Open Source Software
Development) 
Mark Summerfield (Author)
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to make statements running in strictly sequential fashion like in an interactive shell

2011-08-19 Thread Javier
Never used it, but I think you can try this:

Pexpect - a Pure Python Expect-like module
Pexpect is a pure Python Expect-like module. Pexpect makes Python...
www.noah.org/python/pexpect/ 




lzlu123  wrote:
> I have an instrument that has a RS232 type serial comm port and I need
> to connect to and control. I use Python 3.2 in Windows XP, plus
> pySerial module. I have a problem when I execute a script consisting
> of statements that open the comm port, configure it, write strings to
> and receive strings from it. Thoese strings aer either commands
> pertinent to the instrument (control) or responses from the instrument
> (response).
> 
> When those statements are executed in a python interpreter
> interactively (at >>>), I get what I expect and the results are good
> and correct. However, when I execute the script, either being invoked
> within the interpreter or run file, I don???t get what I want. The
> statements in the script is the same as what I use in the interactive
> interpreter.
> 
> Why do I get the strange behavior and how can I change the script to
> make it to behave like in interactive interpreter?
> 
> --script---
> def read(comport):
> 
>wrt_str=b'movt 3000'+b'\r\n'
>ret_str=comport.write(wrt_str)
> 
>wrt_str=b'scan'+b'\r\n'
>ret_str=comport.write(wrt_str)
> 
>rsp_str=comport.readlines() #1
> 
>wrt_str=b'hllo'+b'\r\n'
>ret_str=comport.write(wrt_str)
> 
>rsp_str=comport.readlines()#2
> --
> 
> The problem is with the lines above with ###. In interactive mode,
> there is about 1 second delay at #1, and 9 seonds delay at #2. I get
> correct responses there. However, if I execute the script above, there
> is no delay at all and I get incorrect results (garbage). I set the
> read timeout to 0 in comm port set up, as
> 
> comport.timeout=0
> So the comport should be in blocking mode if it waits for the end of
> line or end of file.
> 
> I tried many things, like exec (execfile in 2.7), but at no avail.
> 
> I have an update to the original post I made a few days ago. I think I
> know what the problem is and want to know if anyone has a solution:
> 
> After putting "print" and "time.sleep(delay)" after every statement, I
> found when the script is running, it appears going around the pyserial
> statement, such as "comport.write(..)" or "comport.readlines(...)"
> while the pyserial command is executing (appearing as waiting and
> busying doing some thing, you know serial port is slow). So for
> example, when I exec all statements in a python interactive shell, I
> am not able to type and run a new statement if the previous one is not
> returned. Let's ay, if comport.readlines() is not returning, I can't
> type and run the next comport.write(...) statemtn. However, in a
> script that is running, if the comport.readlines() is busy reading,
> the next statement is running, if the next statement happens to be a
> comport.write() which will abort the reading.
> 
> Is there any way to force the python script to behave like running
> exactly sequentially?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List spam

2011-08-19 Thread Javier
You will lose a lot of people asking/answering interesting stuff, and
maybe eventually the list will die.  Me (like many people with little
free time) seldom post in blogs/forums/mailing lists where I need to
register.

gene heskett  wrote:
> That is asking the user to take considerable effort and resources to do 
> that.  What is wrong with the mailing list only approach?


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


Re: Distributing Python-programs to Ubuntu users

2009-09-25 Thread Javier Collado
Hello,

I recommend you to check this:
https://wiki.ubuntu.com/PackagingGuide/Complete

The best way to release the software to Ubuntu users is by means of a
PPA (https://help.launchpad.net/Packaging/PPA) so that people can
track your application updates automatically. Before the PPA is
created you need to have a launchpad account and a sign the Ubuntu
Code of Conduct. However isn't that hard and you just have to do all
this setup for the first time.

A tool that might be used to automate package creation for an
application is Quickly (https://wiki.ubuntu.com/Quickly). However, if
the project development has already started, probably it won't be
useful for you.

Best regards,
Javier

2009/9/25 Olof Bjarnason :
> Hi!
>
> I write small games in Python/PyGame. I want to find a way to make a
> downloadable package/installer/script to put on my webpage, especially
> for Ubuntu users.
>
> I've skimmed a couple of tutorials on how to generate .deb-files, but,
> wow, it's a whole new skill set to do that!
>
> Does anyone have any hint on a more economic way of creating
> single-file distribution packages for Python+PyGame projects? Maybe
> some GUI-tool that automates the .deb file creation process, but
> targetting Python specifically and not C++.
>
> /Olof
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Where to find pexpect

2009-10-13 Thread Javier Collado
Hello,

Google is your friend:
http://sourceforge.net/projects/pexpect/
http://sourceforge.net/projects/pexpect/files/pexpect/Release%202.3/pexpect-2.3.tar.gz/download

Best regards,
Javier

2009/10/13 Antoon Pardon :
> I have been looking for pexpect. The links I find like
> http://pexpect.sourceforge.net all end up at
> http://www.noah.org/wiki/Pexpect which produces a 404 not
> found problem.
>
> Does someone know the current location?
>
> --
> Antoon Pardon
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: the usage of 'yield' keyword

2009-10-14 Thread Javier Collado
Hello,

I think that the best information available on the subject is the following:
http://www.dabeaz.com/generators/
http://www.dabeaz.com/coroutines/

Best regards,
Javier

2009/10/14 Peng Yu :
> http://docs.python.org/reference/simple_stmts.html#grammar-token-yield_stmt
>
> The explanation of yield is not clear to me, as I don't know what a
> generator is. I see the following example using 'yield'. Could
> somebody explain how 'yield' works in this example? Thank you!
>
> def brange(limit):
>  i = 0
>  while i < limit:
>      yield i
>      i += 1
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Frameworks

2009-10-19 Thread Javier Santana
juno
http://github.com/breily/juno

it's very easy, uses sqlalchemy as ORM and jinja2 (others can be used
if you want) for templates.

On Mon, Oct 19, 2009 at 10:24 AM, Bruno Desthuilliers
 wrote:
> flebber a écrit :
>>
>> Hi
>>
>> I have been searching through the vast array of python frameworks
>> http://wiki.python.org/moin/WebFrameworks and its quite astounding the
>> choice available.
>>
>> I am looking at using a web framework for my personal project which
>> isn't actually aimed at developing a website as such. However I deduce
>> that rather than creating a gui application and screen input for data,
>> I can use a web browser for this and have a great array of tools to
>> format input screens and output display formats.
>
> Yeps - but remember that a web app will have a couple limitations /
> drawbacks, specially wrt/ handling complex UI.
>
>> Since I will be retreiving information from several websites (usually
>> csv files) formatting them and submitting them to a database and
>> creating queries and printouts based on them most frameworks seem to
>> handle this basically with ease and for any complex queries most
>> support SqlAlchemy.
>>
>> Is it simply a case of just picking one and starting and I would find
>> it hard to be dissapointed or is there a few special considerations to
>> make, though I am unsure what they are?
>
> Given your "specs", forget about monstruosities like Zope, Twisted etc, that
> will mostly get in the way. You have simple needs, use a simple tool !-)
>
>> Most obvious ones I am considering are Django (Of course),
>
> A pretty good framework, but you'll loose some of it's nice features if you
> ever want to use an alternate DB layer or templating system. OTHO, most
> other more "flexible" frameworks just don't offer this level of integration,
> so it's may not be such a big deal.
>
> Note that Django's ORM, while already pretty good and constently improving,
> is not as powerful as SLQAlchemy (now nothing prevents you from going down
> to raw SQL for the more complex queries - and this might be better anyway,
> since complex queries usually requires to be very fine tuned and tend to not
> be really portable). The Forms API OTHO is a real winner IMHO.
>
>> Pylons
>> includes SqlAlchemy, Sql Object and templating and I here turbogears
>> plans to sit on top of this platform.
>
> I admit I fail to see what TG brings except for more indirection levels.
>
>> Zope I am considering but I am a
>> little confused by this.
>
> Friendly advice (based on years of working experience): don't waste your
> time with Zope.
>
>> The are heaps of others but not sure how to
>> narrow the selection criteria.
>>
>> How/Why woul you split Django and Pylons let alone the others?
>
> Django : very strong integration, excellent documentation and support, huge
> community, really easy to get started with. And possibly a bit more mature
> and stable...
>
> Pylons : more loosely coupled (imply: less integration), based on "standard"
> components - which is both a blessing and a curse, specially wrt/
> documentation -, requires a good knowledge of Python and the HTTP protocol
> to get started with. Very powerful and flexible but this comes with a
> price...
>
> Now both are written by talented programmers, and both are pretty good
> tools. I guess it's more a matter of personal preferences and/or external
> constraints (PHB etc...) than anything else.
>
> A couple other "lightweight" candidates you migh want to consider are
> werkzeug and web.py:
>
> http://werkzeug.pocoo.org/
> http://webpy.org/
>
>> Database likely to be MySQl
>
> Mmmm If your application is "write-heavy", PostgreSQL might be a better
> choice. Anyway, both Django's ORM and SQLAlchemy work fine with MySQL
> AFAICT.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: substituting list comprehensions for map()

2009-11-02 Thread Javier Collado
Hello,

I'll do the following:
[op1+op2 for op1,op2 in zip(operandlist1, operandlist2)]

Best regards,
Javier

2009/11/2 Jon P. :
> I'd like to do:
>
> resultlist = operandlist1 + operandlist2
>
> where for example
>
> operandlist1=[1,2,3,4,5]
> operandlist2=[5,4,3,2,1]
>
> and resultlist will become [6,6,6,6,6].  Using map(), I
> can do:
>
> map(lambda op1,op2: op1 + op2, operandlist1, operandlist2)
>
> Is there any reasonable way to do this via a list comprehension ?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to specify Python version in script?

2009-11-11 Thread Javier Collado
Hello,

If you are working on linux, you can change the shebang line from:
#!/usr/bin/python

to:
#!/usr/bin/python2.6

Best regards,
Javier

P.S. If you just want to avoid python 3 while running the latest
python 2.x version, this should also work:
#!/usr/bin/python2

2009/11/11 Benjamin Kaplan :
> On Wed, Nov 11, 2009 at 12:16 PM, kj  wrote:
>>
>>
>>
>>
>> I have a script that must be run with Python 2.6.x.  If one tries
>> to run it with, say, 2.5.x, *eventually* it runs into problems and
>> crashes.  (The failure is quicker if one attempts to run it with
>> Python 3.x.)
>>
>> Is there some way to specify at the very beginning of the script
>> the acceptable range of Python versions?
>>
>
> min_version = (2,6)
> import sys
> if sys.version_info < min_version :
>   print >> stderr, "must be run with at least Python 2.6"
>   sys.exit(1)
>
>
>> TIA!
>>
>> kynn
>>
>> P.S. I know that I can hardcode the path to a specific intpreter
>> in the #! line, but I'm trying to keep the code a bit more general
>> than that.
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: When to use mechanize and Windmill library during WebScraping ?

2009-12-12 Thread Javier Collado
Hello,

If a script that uses mechanize fails to find an html node that has
been identified with Firebug, this is probably because that node has
been autogenerated (provided that the expression to get the node is
correct).

As an alternative to verify this, you can try to download the html
page and open it in your favourite editor. If some of the nodes that
you can see in your browser are missing or empty, then one of the
JavaScript scripts in the page should have created/populated it.

If you're in doubt, you can try to use mechanize and, if you have
problems such as the described above, then you can move to windmill or
some other tool that executes JavaScript code before trying to get the
desired data.

Best regards,
Javier

2009/12/11 Raji Seetharaman :
> Hi
>
> For 'Webscraping with Python' mechanize or urllib2 and windmill or selenium
> libraries are used  to download the webpages.
>
> http://www.packtpub.com/article/web-scraping-with-python
>
> The above link makes use of mechanize library to download the web pages.
>
> The below link uses windmill library to download the web pages.
>
> http://www.packtpub.com/article/web-scraping-with-python-part-2
>
> I dont know when to use mechanize or windmill library
>
> It has been said that Windmill library is used when the HTML file is auto
> generated by the JavaScript code.
>
> Also i dont know how to identify whether the HTML file is auto generated by
> the JavaScript code or not ?
>
> Suggest me
>
> Thanks
>
> Raji. S
> http://sraji.wordpress.com/
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ignore leading '>>>' and ellipsis?

2010-01-14 Thread Javier Collado
Hello,

I think that's exactly what the cpaste magic function does. Type
'cpaste?' in your IPython session for more information.

Best regards,
Javier

2010/1/14 Reckoner :
>
> Hi,
>
> I am studying some examples in a tutorial where there are a lot of
> leading >>> characters and ellipsis in the text. This makes it hard to
> cut and paste into the IPython interpreter since it doesn't like these
> strings.
>
> Is there another interpreter I could use that will appropriately
> ignore and interpret these leading terms?
>
> For example, I cannot paste the following directly into the
> interpreter:
>
>>>> d = dict(x.__array_interface__)
>>>> d['shape'] = (3, 2, 5)
>>>> d['strides'] = (20, 20, 4)
>
>>>> class Arr:
> ...     __array_interface__ = d
> ...     base = x
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Symbols as parameters?

2010-01-21 Thread Javier Collado
Hello,

I'd say that isn't totally incorrect to use strings instead of
symbols. Please note that in other programming languages symbols,
atoms and the like are in fact immutable strings, which is what python
provides by default.

Best regards,
Javier

2010/1/21 Alf P. Steinbach :
> * Martin Drautzburg:
>>
>> Hello all,
>>
>> When passing parameters to a function, you sometimes need a paramter
>> which can only assume certain values, e.g.
>>
>>        def move (direction):
>>                ...
>> If direction can only be "up", "down", "left" or "right", you can solve
>> this by passing strings, but this is not quite to the point:
>>
>>        - you could pass invalid strings easily
>>        - you need to quote thigs, which is a nuisance
>>        - the parameter IS REALLY NOT A STRING, but a direction
>>
>> Alternatively you could export such symbols, so when you "import *" you
>> have them available in the caller's namespace. But that forces you
>> to "import *" which pollutes your namespace.
>>
>> What I am really looking for is a way
>>
>>        - to be able to call move(up)
>>        - having the "up" symbol only in the context of the function call
>>
>> So it should look something like this
>>
>> ... magic, magic ...
>> move(up)
>> ... unmagic, unmagic ...
>> print up
>>
>> This should complain that "up" is not defined during the "print" call,
>> but not when move() is called. And of course there should be as little
>> magic as possible.
>>
>> Any way to achieve this?
>
>>>> def move( direction ):
> ...   print( "move " + str( direction ) )
> ...
>>>> move( "up" )
> move up
>>>>
>>>> class using_directions:
> ...     up = 42
> ...     move( up )
> ...
> move 42
>>>> up
> Traceback (most recent call last):
>  File "", line 1, in 
> NameError: name 'up' is not defined
>>>> _
>
>
> Of course it's an abuse of the language. :-)
>
> So I wouldn't recommend it, but it's perhaps worth having seen it.
>
>
> Cheers & hth.,
>
> - Alf
>
> PS: I hope this was not a homework question.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess troubles

2010-01-21 Thread Javier Collado
Hello,

If you set shell=False, then I think that arg2 should be separated
into two different parts.

Also, arg3 could be set just to pattern (no need to add extra spaces
or using str function).

Best regards,
Javier

2010/1/21 Tomas Pelka :
> Hey all,
>
> have a problem with following piece of code:
>
> --
> import subprocess
>
> paattern = "python"
> cmd = "/usr/bin/locate"
> arg1 = " -i"
> arg2 = " -d /var/www/books/mlocate.db"
> arg3 = str(" " + pattern)
>
> p1 = subprocess.Popen([cmd, arg1, arg2, arg3], shell=False,
> stdout=subprocess.PIPE, stderr=subprocess.PIPE)
> (stdoutdata, stderrdata) = p1.communicate()
>
> print p1.returncode
> print "%s -- %s" % (stdoutdata, stderrdata)
> --
>
> But return code is always 1 and command do not return any result/error
> (stdoutdata, stderrdata are None). If I run this command (/usr/bin/locate -i
> -d /var/www/books/mlocate.db python) from standard shell everything goes
> fine.
>
> Could you please give me an advice what I'm doing wrong?
>
> Thanks
> Cheers
>
> --
> Tom
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sikuli: the coolest Python project I have yet seen...

2010-01-25 Thread Javier Collado
Hello,

I think the site is under maintenance. I tried a couple of hours ago
and it worked fine.

As an alternative, I found that this link also worked:
http://www.sikuli.org/

Unfortunately, it seems it's not working right now.

Best regards,
Javier

2010/1/25 Virgil Stokes :
> On 25-Jan-2010 04:18, Ron wrote:
>>
>> Sikuli is the coolest Python project I have ever seen in my ten year
>> hobbyist career. An MIT oepn source project, Sikuli uses Python to
>> automate GUI tasks (in any GUI or GUI baed app that runs the JVM) by
>> simply drag and dropping GUI elements into Python scripts as function
>> arguments. Download at http://sikuli.csail.mit.edu/ I also did this
>>
>
> This link is broken!
>
> --V
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python or Ant

2010-01-26 Thread Javier Collado
Hello,

One tool that I really like is doit:
http://python-doit.sourceforge.net/

If you need to execute jobs remotely, you may like to take a look at STAF:
http://staf.sourceforge.net/index.php

Best regards,
Javier

2010/1/26 Chris Rebert :
> On Tue, Jan 26, 2010 at 10:58 AM,   wrote:
>> My company is looking at creating a tool to allow us to define and manage a
>> process for each job we run (a typical job may be look on a customers ftp
>> site for a file, download it, decrypt it and load it into our database). We
>> would like something which would allow us to glue together various existing
>> processes we currently use into a single unit with multiple steps. Along the
>> way, this new routine would need to log its progress and be able to report
>> and even handle errors. A coworker has suggested we look at Ant ("Another
>> Neat Tool") and, though it looks promising, I have reservations. If I recall
>> correctly, it was intended as a replacement for "Make" and I worry that we
>> may be trying to force Ant to be something it is not. Also, most of our code
>> base is in Python and I'd really like to stay that way, of possible.
>>
>> Are there any systems out there that will allow me to run multiple programs
>> as one process? We could write our own, of course, and the Twisted package
>> looks like it would be fun to use. Or, is Ant a viable solution to our
>> problem?
>>
>> Your constructive comments would be appreciated
>
> There are several make-replacements written in Python. They could be an 
> option.
>
> Here's a list of some of them (courtesy some googling):
> - Paver (http://www.blueskyonmars.com/projects/paver/)
> - SCons (http://www.scons.org/)
> - Vellum (https://launchpad.net/vellum)
> - Aap (http://www.a-a-p.org/)
>
> (List is in no particular order and likely incomplete; I have not
> tried any of these myself.)
>
> Cheers,
> Chris
> --
> http://blog.rebertia.com
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: scraping with urllib2

2010-01-27 Thread Javier Collado
Hello,

To accept cookies, use the HTTPCookieProcessor as explained here:
http://www.nomadjourney.com/2009/03/automatic-site-login-using-python-urllib2/

Best regards,
Javier

2010/1/27 Andre Engels :
> On Wed, Jan 27, 2010 at 6:26 AM, Patrick  wrote:
>> I'm trying to scrape the attached link for the price listed $99.99:
>> http://bananarepublic.gap.com/browse/product.do?cid=41559&vid=1&pid=692392
>>
>> I can see the price if I view the source(I even turned off java and
>> javascript), but when I use urllib2, the price doesn't show up.
>>
>> Is there another library other than urllib2 that would work?
>
> To see that page you need to accept cookies from the site and send them back.
>
>
>
> --
> André Engels, andreeng...@gmail.com
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help parsing a page with python

2010-01-27 Thread Javier Collado
Hello,

A test case for Windmill might also be used to extract the information
that you're looking for.

Best regards,
Javier

2010/1/27 mierdatutis mi :
> Those videos are generated by javascript.
> There is some parser with python for javascript???
>
> Thanks a lot!
>
>
> 2010/1/27 Simon Brunning 
>>
>> 2010/1/27 mierdatutis mi :
>> > Hi,
>> >
>> > I would like to parse a webpage to can get the url of the video
>> > download. I
>> > use pyhton and firebug but I cant get the url link.
>> >
>> > Example:
>> >
>> > The url where I have to get the video link is:
>> >
>> > http://www.rtve.es/mediateca/videos/20100125/saber-comer---salsa-verde-judiones-25-01-10/676590.shtml";
>> >
>> > The video is
>> > http://www.rtve.es/resources/TE_SSAC011/flv/8/2/1264426362028.flv
>> > Could you help me please?
>>
>> That URL doesn't appear to be in the HTML - it must be being brought
>> in by the JavaScript somehow.
>>
>> --
>> Cheers,
>> Simon B.
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help parsing a page with python

2010-01-27 Thread Javier Collado
Hello,

You can find some advice here:
http://www.packtpub.com/article/web-scraping-with-python-part-2

Best regards,
Javier

2010/1/27 mierdatutis mi :
> Hello again,
>
> What test case for Windmill? Can you say me the link, please?
>
> Many thanks
>
> 2010/1/27 Javier Collado 
>>
>> Hello,
>>
>> A test case for Windmill might also be used to extract the information
>> that you're looking for.
>>
>> Best regards,
>>    Javier
>>
>> 2010/1/27 mierdatutis mi :
>> > Those videos are generated by javascript.
>> > There is some parser with python for javascript???
>> >
>> > Thanks a lot!
>> >
>> >
>> > 2010/1/27 Simon Brunning 
>> >>
>> >> 2010/1/27 mierdatutis mi :
>> >> > Hi,
>> >> >
>> >> > I would like to parse a webpage to can get the url of the video
>> >> > download. I
>> >> > use pyhton and firebug but I cant get the url link.
>> >> >
>> >> > Example:
>> >> >
>> >> > The url where I have to get the video link is:
>> >> >
>> >> >
>> >> > http://www.rtve.es/mediateca/videos/20100125/saber-comer---salsa-verde-judiones-25-01-10/676590.shtml";
>> >> >
>> >> > The video is
>> >> > http://www.rtve.es/resources/TE_SSAC011/flv/8/2/1264426362028.flv
>> >> > Could you help me please?
>> >>
>> >> That URL doesn't appear to be in the HTML - it must be being brought
>> >> in by the JavaScript somehow.
>> >>
>> >> --
>> >> Cheers,
>> >> Simon B.
>> >> --
>> >> http://mail.python.org/mailman/listinfo/python-list
>> >
>> >
>> > --
>> > http://mail.python.org/mailman/listinfo/python-list
>> >
>> >
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a GUI for informing a user of missing dependencies?

2009-05-12 Thread Javier Collado
Hello,

I'm not an expert, but if you use setuptools for your application,
then a 'install_requires' argument would do the job. For more
information, please take a look at:
http://peak.telecommunity.com/DevCenter/setuptools

Best regards,
Javier

2009/5/12 Jason :
> I'm writing a small GUI (Python 2.5/6) using wxPython and pySerial.
> Since these are both 3rd party modules, if a user doesn't have them
> installed and tries to run the GUI from a file browser, the app will
> fail silently. I'm hoping to avoid that.
>
> Sure, I'll have a readme file, but I was wondering if there is an even
> more direct way. I was going to roll my own (eg. very simple Tkinter
> fallback error dialog if wxPython import fails, wxPython error dialog
> if anything else is missing); but I was wondering if such a system
> already exists out there.
>
> — Jason
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Global variables from a class

2009-05-29 Thread Javier Collado
Hello,

First thing is a class variable (one for every instance) and second
one an instance variable (one per instance).

For further information, please take a look at:
http://diveintopython.org/object_oriented_framework/class_attributes.html

Best regards,
   Javier

2009/5/29 Kless :
> I usually use a class to access to global variables. So, which would
> be the correct way to set them --since the following classes--:
>
> 
> class Foo:
>   var = 'lala'
>
> class Bar:
>   def __init__(self):
>      self.var = 'lele'
> 
>
> Or is it the same?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Global variables from a class

2009-05-29 Thread Javier Collado
You're right. I agree on that it's important to use proper words.
Thanks for the correction.

Best regards,
Javier

2009/5/29 Steven D'Aprano :
> On Fri, 29 May 2009 12:04:53 +0200, Javier Collado wrote:
>
>> Hello,
>>
>> First thing is a class variable (one for every instance) and second one
>> an instance variable (one per instance).
>
> One of these things don't belong:
>
> A string variable is a variable holding a string.
> A float variable is a variable holding a float.
> An int variable is a variable holding an int.
> A list variable is a variable holding a list.
> A "class variable" is an attribute of a class object, holding an
>  object of arbitrary type, which is shared by all instances
>  of the class.
>
> Please don't use the term "class variable" to mean class attribute.
>
>
>
> --
> Steven
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PYTHONPATH and multiple python versions

2009-06-05 Thread Javier Collado
Hello,

I think that virtualenv could also do the job.

Best regards,
Javier

2009/6/5 Red Forks :
> maybe a shell script to switch PYTHONPATH, like:
> start-python-2.5
> start-python-2.4 ...
> On Fri, Jun 5, 2009 at 4:56 PM, David Cournapeau  wrote:
>>
>> Hi,
>>
>> As I don't have admin privileges on my main dev machine, I install a
>> good deal of python modules somewhere in my $HOME, using PYTHONPATH to
>> point my python intepreter to the right location. I think PEP370
>> (per-user site-packages) does exactly what I need, but it works only
>> for python 2.6 and above. Am I out of luck for versions below ?
>>
>> David
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Start the interactive shell within an application

2009-06-09 Thread Javier Collado
Take a look either at code.interact or at
IPython.ipapi.launch_new_instance. Basically, the only thing that you
have to provide is a dictionary object that contains the namespace
that you would like to have in your shell once it's launched.

Best regards,
Javier

2009/6/9 eGlyph :
> On Jun 9, 11:49 am, Jean-Michel Pichavant 
> wrote:
>> I'm sometimes tired of adding prints to scan the current namespace so
>> I'd like to pause the execution and give the user the shell prompt.
>> This is obviously for debugging purpose.
>
> This is definitely doable, have look at rhythmbox or gedit - they
> provide an interactive console.
> Also, have a look at IPython, they have a recipe and an example of
> embedding IPython into a user's application.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getop or optparse with option with spaces?

2009-06-10 Thread Javier Collado
Hello,

It's strange behaviour. Have you tried argparse
(http://code.google.com/p/argparse/)? I've been using it for long time
without any problem like that?

Best regards,
Javier

2009/6/10 David Shapiro :
> Hello,
>
> I have been trying to find an example of how to deal with options that have 
> spaces in them.  I am using jython, which is the same I think as python 
> 2.2.3.   I feebly tried to use optparse and argparse with no success (got 
> gettext, locale, and optparse).   The code is as follows:
>
>    try:
>        (opts, args) = getopt.getopt(sys.argv[1:], "hs:p:n:j:d:l:u:c:t:w:q:v",
> ["help", "server=", "port=", 
> "dsName=","jndiName=","driverName=","driverURL=","user=","passWD=","targetServer=","whereProp=","testTableName=","version"])
>    except getopt.GetoptError:
>        usage()
>
>    for opt in opts:
>        (key, value) = opt
>        if (key in ("-v", "--version")):
>                print "Version: " + version
>                sys.exit(1)
>        if (key in ("-h", "--help")):
>                usage()
>        if (key in ("-s", "--server")):
>                server = value
>        if (key in ("-p", "--port")):
>                port = value
>        if (key in ("-n", "--dsName")):
>                dsName = value
>        if (key in ("-j", "--jndiName")):
>                jndiName = value
>        if (key in ("-d", "--driverName")):
>                driverName = value
>        if (key in ("-l", "--driverURL")):
>                driverURL = value
>        if (key in ("-u", "--user")):
>                user = value
>        if (key in ("-c", "--passWD")):
>                passWD = value
>        if (key in ("-t", "--targetServer")):
>                targetServer = value
>        if (key in ("-q", "--testTableName")):
>                testTableName = value
>        if (key in ("-w", "--whereProp")):
>                whereProp = value
>
>
> print "server: " + server
> print "port: " + port
> print "dsName: " + dsName
> print "jndiName: " + jndiName
> print "driverName: " + driverName
> print "driverURL: " + driverURL
> print "user: " + user
> print "passWD: " + passWD
> print "testtable: " + testTableName
> print "targetServer: " + targetServer
> print "whereProp: " + whereProp
>
> The one that gives me trouble is with the -q option, because it can look 
> like: -q "SQL 1 TABLE".  It returns back just SQL.  How do I get it to return 
> the whole thing that is in double quotes?  Another problem is that whereProp 
> value is just not seen. Is there a limit to the size for argv?
>
> If I use optparse instead of getopt, I see that SQL 1 TABLE goes into args 
> instead of values by the way.  A temporary workaround is to use " 
> ".join(args) and assign that to testTableName, but I worry about what will 
> happen if testTableName is blank or has something with no spaces.  Also, it 
> just seem weird I have to do a work around like that.  I could have swore 
> using double quotes should have fixed this issue, but they do not seem to 
> work.
>
> David
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about None

2009-06-12 Thread Javier Collado
Hello,

This should work for you:

In [1]: import types

In [2]: isinstance(None, types.NoneType)
Out[2]: True


Best regards,
Javier

2009/6/12 Paul LaFollette :
> Kind people,
>
> Using Python 3.0 on a Gatesware machine (XP).
> I am building a class in which I want to constrain the types that can
> be stored in various instance variables.  For instance, I want to be
> certain that self.loc contains an int.  This is straightforward (as
> long as I maintain the discipline of changing loc through a method
> rather than just twiddling it directly.
>
>  def setLoc(lo):
>    assert isinstance(lo, int), "loc must be an int"
>    self.loc = lo
>
> does the trick nicely.
>
> However, I also want to constrain self.next to be either an instance
> of class Node, or None.  I would think that the following should work
> but it doesn't.
>
>  def setNext(nxt):
>    assert isinstance(nxt, (Node, NoneType)), "next must be a Node"
>    self.next = nxt
>
> since type(Node) responds with  but the assertion
> above gives "name 'NoneType' is not defined" suggesting that NoneType
> is some sort of quasi-class.
>
>  def setNext(nxt):
>    assert nxt==None or isinstance(nxt, Node), "next must be a Node"
>    self.next = nxt
>
> works ok, but it's uglier than it ought to be.
>
> So, I have three questions.
>
> 1) Why doesn't isinstance(nxt, (Node, NoneType)) work?
> 2) is their a less ugly alternative that what I am using?
> 3) (this is purely philosophical but I am curious)  Would it not be
> more intuitive if
> isinstance(None, ) returned true?
>
> Thank you for your kind attention.
> Paul
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about None

2009-06-12 Thread Javier Collado
Hello,

You're right, types.NoneType is not available in python 3.0, I wasn't
aware of that change. Thanks for pointing it out.

Best regards,
Javier

2009/6/12 Jeff McNeil :
> On Jun 12, 10:05 am, Paul LaFollette 
> wrote:
>> Kind people,
>>
>> Using Python 3.0 on a Gatesware machine (XP).
>> I am building a class in which I want to constrain the types that can
>> be stored in various instance variables.  For instance, I want to be
>> certain that self.loc contains an int.  This is straightforward (as
>> long as I maintain the discipline of changing loc through a method
>> rather than just twiddling it directly.
>>
>>   def setLoc(lo):
>>     assert isinstance(lo, int), "loc must be an int"
>>     self.loc = lo
>>
>> does the trick nicely.
>>
>> However, I also want to constrain self.next to be either an instance
>> of class Node, or None.  I would think that the following should work
>> but it doesn't.
>>
>>   def setNext(nxt):
>>     assert isinstance(nxt, (Node, NoneType)), "next must be a Node"
>>     self.next = nxt
>>
>> since type(Node) responds with  but the assertion
>> above gives "name 'NoneType' is not defined" suggesting that NoneType
>> is some sort of quasi-class.
>>
>>   def setNext(nxt):
>>     assert nxt==None or isinstance(nxt, Node), "next must be a Node"
>>     self.next = nxt
>>
>> works ok, but it's uglier than it ought to be.
>>
>> So, I have three questions.
>>
>> 1) Why doesn't isinstance(nxt, (Node, NoneType)) work?
>> 2) is their a less ugly alternative that what I am using?
>> 3) (this is purely philosophical but I am curious)  Would it not be
>> more intuitive if
>> isinstance(None, ) returned true?
>>
>> Thank you for your kind attention.
>> Paul
>
> 1. The problem is described clearly by that Exception. The 'NoneType'
> name isn't bound to any objects at that current scope.  I know that
> with 2.6, you can import 'types.NoneType' but I don't believe the 3.0
> types module includes NoneType.  Someone else will have to clarify
> that as I don't have 3.0 installed.
>
> 2. A less ugly alternative? You could use the accepted method of
> testing against None:
>
> if var is None:
>    do_stuff()
>
> The use of the 'is' operator checks whether objects are exactly the
> same (id(var) == id(None)) as opposed to 'isinstance' or '==.'
>
> You might also try defining descriptors in order to make your type
> checks slightly more transparent. That might be confusing to other
> users of your class, though. Not many people expect a TypeError from
> an attribute assignment.
>
> 3. None is an instance of NoneType. Why should isinstance return True
> when it's tested against other types?
>
> HTH,
>
> Jeff
> mcjeff.blogspot.com
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling subprocess with arguments

2009-06-19 Thread Javier Collado
Hello,

The problem might be that, aside from creating the Popen object, to
get the command run you need to call 'communicate' (other options, not
used with the Popen object directly, are 'call' or 'waitpid' as
explained in the documentation). Did you do that?

Best regards,
Javier

2009/6/19 Tyler Laing :
> So no one has an answer for why passing flags and the values the flags need
> through subprocess does not work? I would like an answer. I've examined all
> the examples I could find online, which were all toy examples, and not
> helpful to my problem.
>
> On Thu, Jun 18, 2009 at 7:40 PM, Tyler Laing  wrote:
>>
>> I've been trying any variation I can think of to do this properly, but
>> here's my problem:
>>
>> I want to execute this command string: vlc -I rc
>>
>> This allows vlc to be controlled via  a remote interface instead of the
>> normal gui interface.
>>
>> Now, say, I try this from subprocess:
>>
>> >>>p=subprocess.Popen('vlc -I rc test.avi'.split(' '), shell=False,
>> >>> stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>
>> But I don't get the remote interface. I get the normal gui interface. So
>> how do I do it? I've tried passing ['vlc', '-I', 'rc'], I've tried ['-I',
>> 'rc'] with executable set to 'vlc'. I've had shell=True, I've had
>> shell=False. I've tried all these combinations.
>>
>> What am I doing wrong?
>>
>> --
>> Visit my blog at http://oddco.ca/zeroth/zblog
>
>
>
> --
> Visit my blog at http://oddco.ca/zeroth/zblog
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Making code run in both source tree and installation path

2009-06-29 Thread Javier Collado
Hello,

I would like to be able to run the main script in a python project
from both the source tree and the path in which it's installed on
Ubuntu. The script, among other things, imports a package which in
turns makes use of some data files that contains some metadata that is
needed in xml format.

The source tree has an structure such as this one:
setup.py
debian/ (packaging files)
src/ (source code)
src/lib (package files)
src/data (data files)
src/bin (main script)

However, when the project is installed using setup.py install, the
directory structure is approximately this way:
/usr/local/bin (main script)
/usr/local/share/ (data files)
/usr/local/lib/python2.x/dist-packages/ (library files)

And when installing the code through a package, the structure is the
same one, but removing "local".

Hence, the data files aren't always in the same relative directories
depending on we're executing code from the source tree or from the
installation. To make it possible to run the code from both places,
I've seen different approaches:
- distutils trick in setup.py to modify the installed script (i.e.
changing a global variable value) so that it has a reference to the
data files location.
- Heuristic in the package code to detect when it's being executed
from the source tree and when it has been the installed
- Just using an environment variable that the user must set according
to his needs

I guess that there are other options, for example, maybe using
buildout. What would you say it's the best/more elegant option to
solve this problem?

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


Re: packaging apps

2009-06-30 Thread Javier Collado
Hello,

Regarding packaging for debian (.deb), the best reference I've found is:
https://wiki.ubuntu.com/PackagingGuide/Python

However, all that mess probably won't be needed anymore once this is finished:
https://blueprints.edge.launchpad.net/ubuntu/+spec/desktop-karmic-automagic-python-build-system

Best regards,
   Javier

2009/6/30 Ronn Ross :
> I have a simple application that has a glade file and a .py file. How would
> I package that into an installer for Windows, Mac, and a deb file? Can
> anyone point me in the right direction?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Config files with different types

2009-07-03 Thread Javier Collado
Hello,

Have you considered using something that is already developed?

You could take a look at this presentation for an overview of what's available:
http://us.pycon.org/2009/conference/schedule/event/5/

Anyway, let me explain that, since I "discovered" it, my favourite
format for configuration files is yaml (http://yaml.org/,
http://pyyaml.org/). It's easy to read, easy to write, available in
different programming languagues, etc. In addition to this, type
conversion is already in place so I think it covers your requirement.
For example:

IIn [1]: import yaml

In [2]: yaml.load("""name: person name
   ...: age: 25
   ...: is_programmer: true""")
Out[2]: {'age': 25, 'is_programmer': True, 'name': 'person name'}

Best regards,
Javier

2009/7/2 Zach Hobesh :
> Hi all,
>
> I've written a function that reads a specifically formatted text file
> and spits out a dictionary.  Here's an example:
>
> config.txt:
>
> Destination = C:/Destination
> Overwrite = True
>
>
> Here's my function that takes 1 argument (text file)
>
> the_file = open(textfile,'r')
> linelist = the_file.read().split('\n')
> the_file.close()
> configs = {}
> for line in linelist:
>       try:
>              key,value = line.split('=')
>              key.strip()
>              value.strip()
>              key.lower()
>              value.lower()
>              configs[key] = value
>
>       except ValueError:
>              break
>
> so I call this on my config file, and then I can refer back to any
> config in my script like this:
>
> shutil.move(your_file,configs['destination'])
>
> which I like because it's very clear and readable.
>
> So this works great for simple text config files.  Here's how I want
> to improve it:
>
> I want to be able to look at the value and determine what type it
> SHOULD be.  Right now, configs['overwrite'] = 'true' (a string) when
> it might be more useful as a boolean.  Is there a quick way to do
> this?  I'd also like to able to read '1' as an in, '1.0' as a float,
> etc...
>
> I remember once I saw a script that took a string and tried int(),
> float() wrapped in a try except, but I was wondering if there was a
> more direct way.
>
> Thanks in advance,
>
> Zach
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


string.Template issue

2009-07-30 Thread Javier Collado
Hello,

In the string.Template documentation
(http://docs.python.org/library/string.html) it's explained that if a
custom regular expression for pattern substitution is needed, it's
possible to override idpattern class attribute (whose default value is
[_a-z][_a-z0-9]*).

However, if the custom pattern that is needed is just uppercase
letters something like [A-Z]+ won't work because of the following line
in the _TemplateMetaclass class __init__ method:
cls.pattern = _re.compile(pattern, _re.IGNORECASE | _re.VERBOSE)

I would say that this is an error (IGNORECASE just shouldn't be there)
and that the line above should be:
cls.pattern = _re.compile(pattern, _re.VERBOSE)
and the default value for idpattern:
[_a-zA-Z][_a-zA-Z0-9]*

Do you agree on this? Is there any reason for the IGNORECASE option to
be passed to re.compile?

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


Re: Non-blocking read with popen subprocess

2009-07-31 Thread Javier Collado
Hello,

According to my experience and from what I've read in other threads,
subprocess isn't easy to use for interactive tasks. I don't really
know, but maybe it wasn't even designed for that at all.

On the other hand, pexpect seems to work fine for interactive use and
even provides a method for nonblocking reads, so I think that you
should consider to take a look at it:
http://pexpect.sourceforge.net/pexpect.html#spawn-read_nonblocking

Best regards,
Javier

2009/7/31 Dhanesh :
> Hi ,
>
> I am trying to use subprocess popen on a windows command line
> executable with spits messages on STDOUT as well as STDIN. Code
> snippet is as below :-
> ##
> sOut=""
>    sErr=""
>    javaLoaderPath = os.path.join("c:\\","Program Files","Research In
> Motion","BlackBerry JDE 4.7.0","bin","Javaloader.exe")
>    cmd = [javaLoaderPath,'-u','load','helloworld.jad']
>    popen = subprocess.Popen
> (cmd,bufsize=256,shell=False,stdout=subprocess.PIPE,
> stderr=subprocess.PIPE)
>    while True:
>        sErr = sErr + popen.stderr.read(64)
>        sOut = sOut + popen.stdout.read(64)--> Blocks
> here
>        if None != popen.poll():
>            break;
> ##
>
> I observed that python scripts blocks at stdout read on the other hand
> when I do not create a child stdout PIPE  say  " stdout=None" , things
> seems to be working fine.
>
> how can I we have a non blocking read ?
> And why does stdout block even where data is available to be read
> ( which seem to be apparent when stdout=None, and logs appear on
> parents STDOUT) ?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OptionParser How to: prog [options] [arguments]

2009-08-14 Thread Javier Collado
Hello,

I think that this isn't possible with optparse library.

However, it's possible with argparse (http://code.google.com/p/argparse/):
 http://argparse.googlecode.com/svn/trunk/doc/other-methods.html#sub-commands

It's not a standard library, but it's worth to take a look at it.

Best regards,
Javier

2009/8/14 Steven Woody :
> Hi,
> I am using OptionParser, but I've not managed figure out a way to support
> what I wanted command line format "prog  [options] [arguments]".
> E.g., "svn ls -r123 http://hello.world".   Can I do this using OptionParser?
> Thanks.
> --
> Life is the only flaw in an otherwise perfect nonexistence
>    -- Schopenhauer
>
> narke
> public key at http://subkeys.pgp.net:11371 (narkewo...@gmail.com)
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lambda functions

2009-08-31 Thread Javier Collado
Hello,

This page has some advice about how to avoid some of the lambda
functions limitations:
http://p-nand-q.com/python/stupid_lambda_tricks.html

In particular, it suggests to use map function instead of for loops.

Best regards,
Javier

2009/8/31 Pierre :
> Hello,
>
> I would like to know if it is possible to define a loop in a lambda
> function
>
> How to manage the indents ? Example :
> s_minus_1 = lambda s : for index in range(0, len(s)) : s[index] = s
> [index]-1
>
>
> Thanks !
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python and http POST

2010-02-12 Thread Javier Collado
Hello,

I haven't used httplib2, but you can certainly use any other
alternative to send HTTP requests:
- urllib/urllib2
- mechanize

With regard to how do you find the form you're looking for, you may:
- create the HTTP request on your own with urllib2. To find out what
variables do you need to post, you can use tamperdata Firefox addon as
suggested (I haven't used that one) or httpfox (I have and it works
great).
- use mechanize to locate the form for you, fill the data in and click
on the submit button.

Additionally, you may wan to scrape some data that may be useful for
your requests. For that BeautifulSoup is good solution (with some
Firebug help to visually locate what you're looking for).

Best regards,
Javier

P.S. Some examples here:
http://www.packtpub.com/article/web-scraping-with-python
http://www.packtpub.com/article/web-scraping-with-python-part-2

2010/2/11 galileo228 :
> Hey All,
>
> Been teaching myself Python for a few weeks, and am trying to write a
> program that will go to a url, enter a string in one of the search
> fields, submit the search, and return the contents of the search
> result.
>
> I'm using httplib2.
>
> My two particular questions:
>
> 1) When I set my 'body' var, (i.e. 'body = {'query':'search_term'}),
> how do I know what the particular key should be? In other words, how
> do I tell python which form on the web page I'm visiting I'd like to
> fill in? Do I simply go to the webpage itself and look at the html
> source? But if that's the case, which tag tells me the name of the
> key?
>
> 2) Even once python fills in the form properly, how can I tell it to
> 'submit' the search?
>
> Thanks all!
>
> Matt
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Are there in Python some static web site generating tools like webgen, nanoc or webby in Ruby ?

2010-03-09 Thread Javier Collado
> I'm only aware of Hyde (http://ringce.com/hyde)

There are also jekyll and cyrax:
http://github.com/mojombo/jekyll/
http://pypi.python.org/pypi/cyrax/0.1.5

I haven't tried any of them, but it looks like cyrax is in active
development and its design was inspired in both jekyll and hyde.

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


associative array

2010-03-31 Thread Javier Montoya
Dear all,

I'm a newbie in python and would be acknowledge if somebody could shed
some light on associative arrays.
More precisely, I would like to create a multi-dimensional associative
array. I have for example a list of students which are identified
uniquely by their student IDs. Additionally, for each student I have
some information: FirstName, LastName, etc.

The array would have then the following form:
[StudentID] => [FirstName][LastName][Telephone]...[ ... ]

I would like to be able to access a field directly by using a
StudentID
[StudentID][FirstName]
[StudentID][LastName]

How could I manipulate such an array (create the array, add elements,
access data)?

Best wishes


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


Re: associative array

2010-04-01 Thread Javier Montoya
On Mar 31, 7:36 pm, Gary Herron  wrote:
> JavierMontoyawrote:
> > Dear all,
>
> > I'm a newbie in python and would be acknowledge if somebody could shed
> > some light on associative arrays.
> > More precisely, I would like to create a multi-dimensional associative
> > array. I have for example a list of students which are identified
> > uniquely by their student IDs. Additionally, for each student I have
> > some information: FirstName, LastName, etc.
>
> > The array would have then the following form:
> > [StudentID] => [FirstName][LastName][Telephone]...[ ... ]
>
> > I would like to be able to access a field directly by using a
> > StudentID
> > [StudentID][FirstName]
> > [StudentID][LastName]
>
> > How could I manipulate such an array (create the array, add elements,
> > access data)?
>
> > Best wishes
>
> Create a class for student with attributes for ID, FirstName, LastName, etc.
>
>   class Student:
>       def __init__(self, id, FirstName, ...):
>           self.id = id
>           self.FirstName = FirstName
>           ...
>
> then whenever you create a student object, use a dictionary to associate
> the object with its is
>   AA = {} # An empty dictionary
>   s = Student(...)
>   AA[s.id] = s
>   ... and repeat for many students...
>
> Then to access a student's object given an id:
>   s = AA[id]
>   print s.id, s.FirstName, s.LastName, ...
>
> I'd *not* call this a multi-dimension association, but rather just an
> association between student objects and their ids.
>
> Hope that helps,
>
> Gary Herron
>
> --
> Gary Herron, PhD.
> Department of Computer Science
> DigiPen Institute of Technology
> (425) 895-4418

Dear all,

Thanks for your suggestions, it worked! As Gary suggested, I created a
'student' class and mapped its objects to a dictionary.
Is it possible to sort the dictionary by the student's grades in
descending order?

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


Re: fast regex

2010-05-06 Thread Javier Collado
Hello,

2010/5/6 james_027 :
> I was working with regex on a very large text, really large but I have
> time constrained. Does python has any other regex library or string
> manipulation library that works really fast?

re2 (http://code.google.com/p/re2/) is suppossed to be faster than the
standard library in python. Unfortunately, it's implemented in C++ and
there isn't an official python wrapper for it. However, you can find a
wrapper that can be useful for you here:
http://github.com/facebook/pyre2

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


Re: Parsing markup.

2010-11-25 Thread Javier Collado
Hello,

2010/11/26 Joe Goldthwaite :
> I’m attempting to parse some basic tagged markup.
>
>  Elementree and lxml seem to want a full formatted
> page, not a small segment like this one.

BeautifulSoup (http://www.crummy.com/software/BeautifulSoup/) could
help in the parsing:

>>> from BeautifulSoup import BeautifulSoup as Soup
>>> s = Soup(text)
>>> print s.prettify()

 This is a paragraph with
 
  bold
 
 and
 
  italic
 
 elements in it


 It can be made up of multiple lines separated by pagagraph tags.

>>> s.findAll('b')
[bold]
>>> s.findAll('i')
[italic]
>>> s.findAll('p')
[This is a paragraph with bold and italic elements in it,
 It can be made up of multiple lines separated by pagagraph tags.]

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


Re: os.path.isfile and wildcard for directory name

2010-12-30 Thread Javier Collado
Hello,

2010/12/30  :
> How can i do the same thing (wildcard in a directory name) in python please ?

You can get the contents of a directory with os.listdir and filter
with fnmatch.fnmatch more or less as in the example from the
documentation:
-
import fnmatch
import os

for file in os.listdir('.'):
if fnmatch.fnmatch(file, '*.txt'):
print file
-----

Regards,
Javier
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: parse html rendered by js

2011-02-12 Thread Javier Collado
Hello,

2011/2/11 yanghq :
>    but for some pages rendered by js, like:

You could use selenium or windmill to help you reproduce the contents
of the web page in a browser so you can get the data from the DOM tree
once the page has been rendered instead of by parsing the js.

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


remove elements incrementally from a list

2010-05-19 Thread Javier Montoya
Dear all,

I've a list of float numbers and I would like to delete incrementally
a set of elements in a given range of indexes, sth. like:

for j in range(beginIndex, endIndex+1):
   print ("remove [%d] => val: %g" % (j, myList[j]))
   del myList[j]

However, since I'm iterating over the same list, the indexes (range)
are not valid any more for the new list.
Does anybody has some suggestions on how to delete the elements
properly?

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


Re: remove elements incrementally from a list

2010-05-19 Thread Javier Montoya
On May 19, 4:06 pm, Steven D'Aprano  wrote:
> On Wed, 19 May 2010 03:53:44 -0700, Javier Montoya wrote:
> > Dear all,
>
> > I've a list of float numbers and I would like to delete incrementally a
> > set of elements in a given range of indexes, sth. like:
>
> > for j in range(beginIndex, endIndex+1):
> >    print ("remove [%d] => val: %g" % (j, myList[j])) del myList[j]
>
> > However, since I'm iterating over the same list, the indexes (range) are
> > not valid any more for the new list. Does anybody has some suggestions
> > on how to delete the elements properly?
>
> Just delete the slice:
>
> del myList[beginIndex:endIndex+1]
>
> For small lists where you are deleting small chunks, this is the
> simplest, most straight-forward way.
>
> Alternatively, create a new list excluding the bits you would have
> deleted, and assign it in place:
>
> myList[:] = myList[:beginIndex] + myList[endIndex+1:]
>
> Note carefully that you aren't just re-binding the name "myList", but
> assigning to the slice myList[:].
>
> Then there is the old-fashioned way: iterate over the list backwards,
> deleting from the end towards the front.
>
> for j in range(endIndex, beginIndex-1, -1):
>     del myList[j]
>
> If your list is HUGE and you have very little memory, this is probably
> the least worst way. It might be slow, but it will work.
>
> Finally, we have this:
>
> myList[beginIndex:] = myList[endIndex+1:]
>
> --
> Steven

Hi guys,

A big thanks to everybody, it's amazing!

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


numpy arrays to python compatible arrays

2010-06-10 Thread Javier Montoya
Dear all,

I'm new to python and have been working with the numpy package. I have
some numpy float arrays (obtained from np.fromfile and np.cov
functions) and would like to convert them to simple python arrays.
I was wondering which is the best way to do that? Is there any
function to do that?

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


Re: numpy arrays to python compatible arrays

2010-06-12 Thread Javier Montoya
On Jun 11, 12:29 am, Martin  wrote:
> On Jun 10, 9:02 pm, Philip Semanchuk  wrote:
>
>
>
> > On Jun 10, 2010, at 9:58 AM,JavierMontoyawrote:
>
> > > Dear all,
>
> > > I'm new to python and have been working with the numpy package. I have
> > > some numpy float arrays (obtained from np.fromfile and np.cov
> > > functions) and would like to convert them to simple python arrays.
> > > I was wondering which is the best way to do that? Is there any
> > > function to do that?
>
> > HiJavier,
> > Since you are new to Python I'll ask whether you want to convert Numpy  
> > arrays to Python arrays (as you stated) or Python lists. Python lists  
> > are used very frequently; Python arrays see very little use outside of  
> > numpy.
>
> > If you can use a Python list, the .tolist() member of the numpy array  
> > object should do the trick.
>
> > bye
> > P
>
> as Philip said...though I very much doubt you really want to do this?
> Why wouldn't you just keep it in a numpy array?

Thanks for the suggestions! The main reason not to use a numpy array
is because I'm
using a package that doesn't work with numpy arrays.
With the .tolist() conversion it's now working fine, thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


non-uniform distribution

2010-06-12 Thread Javier Montoya
Dear all,

I need to generate a vector of random float numbers between [0,1] such
that their sum equals 1 and that are distributed non-uniformly.
Is there any python function that generates such a vector?

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


Re: non-uniform distribution

2010-06-12 Thread Javier Montoya
On Jun 12, 1:08 pm, Etienne Rousee  wrote:
> Le 12/06/2010 12:05, Javier Montoya a écrit :
>
> > I need to generate a vector of random float numbers between [0,1] such
> > that their sum equals 1 and that are distributed non-uniformly.
> > Is there any python function that generates such a vector?
>
> Let f any function (injective is better).
> Let a1,...,an n numbers uniformly distributed.
> Let s the sum of f(a1),...,f(an).
>
> f(a1)/s, ... , f(an)/s is what you want.
>
> You have to choose f to obtain the distribution you prefer.
>
> --
>
> Etienne

Hi Etienne,

Thanks for your suggestion. I ended with following code:
N=5
a=np.random.random_integers(2*N, size=(1.,N))
a=a/float(sum(a))
However, in some cases, the random numbers are even repeated, for
example, I obtained the following sequence:
[0.03846154,  0.03846154,  0.23076923,  0.34615385,  0.34615385]
This is mainly because in random_integers the integers generated might
be repeated.
One solution, would be to set the first parameter in random_integers
to a larger number.
What do you think? Do you suggest any other function instead of
random_integers?

Best wishes

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


Re: non-uniform distribution

2010-06-12 Thread Javier Montoya
On Jun 12, 1:08 pm, Etienne Rousee  wrote:
> Le 12/06/2010 12:05, Javier Montoya a écrit :
>
> > I need to generate a vector of random float numbers between [0,1] such
> > that their sum equals 1 and that are distributed non-uniformly.
> > Is there any python function that generates such a vector?
>
> Let f any function (injective is better).
> Let a1,...,an n numbers uniformly distributed.
> Let s the sum of f(a1),...,f(an).
>
> f(a1)/s, ... , f(an)/s is what you want.
>
> You have to choose f to obtain the distribution you prefer.
>
> --
>
> Etienne

Hi Etienne,

Thanks for your suggestion. I ended with following code:
N=5
a=np.random.random_integers(2*N, size=(1.,N))
a=a/float(sum(a))
However, in some cases, the random numbers are even repeated, for
example, I obtained the following sequence:
[0.03846154,  0.03846154,  0.23076923,  0.34615385,  0.34615385]
This is mainly because in random_integers the integers generated might
be repeated.
One solution, would be to set the first parameter in random_integers
to a larger number.
What do you think? Do you suggest any other function instead of
random_integers?

Best wishes

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


Re: non-uniform distribution

2010-06-12 Thread Javier Montoya
On Jun 12, 2:09 pm, Steven D'Aprano  wrote:
> On Sat, 12 Jun 2010 03:05:43 -0700, Javier Montoya wrote:
> > Dear all,
>
> > I need to generate a vector of random float numbers between [0,1] such
> > that their sum equals 1 and that are distributed non-uniformly. Is there
> > any python function that generates such a vector?
>
> You haven't explained your requirements in anywhere near enough detail.
> Any of these match your description:
>
> [1.0]
> [0.0, 0.0, 0.0, 0.0, 1.0]
> [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.3]
> [0.01, 0.01, 0.01, 0.01, 0.02, 0.02, 0.02, 0.03, 0.03, 0.84]
>
> and many, many more. What do you mean by "non-uniformly"? Do you have any
> specific distribution in mind? Do you have to have a particular number of
> items?
>
> For instance, you could do this:
>
> L = []
> total = 0.0
> while total < 1:
>     x = random.uniform(0, 1-total)
>     L.append(x)
>     total += x
>
> assert sum(L) == total == 1.0
>
> --
> Steven

Hi Steven,

The number of items in the vector is usually between [4,15]. I was
having in mind sth. like:
[0.25, 0.23, 0.30, 0.22] for the 4 elems case.

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


Re: non-uniform distribution

2010-06-12 Thread Javier Montoya
On Jun 12, 3:21 pm, Ian  wrote:
> On 12/06/10 11:05, Javier Montoya wrote:> Dear all,
>
> > I need to generate a vector of random float numbers between [0,1] such
> > that their sum equals 1 and that are distributed non-uniformly.
> > Is there any python function that generates such a vector?
>
> > Best wishes
>
> Hi Javier,
>
> The answer to your question is "No", and the reason is that your
> requirement is impossible.
>
> Whatever distribution you choose - and you have not said what you
> require - will be altered by any scaling to meet the constraint that the
> total is 1.
>
> What exactly are you trying to achieve?
>
> Regards
>
> Ian

Hi Ian, I found that the Dirichlet distribution is suitable for my
case.
Regards
-- 
http://mail.python.org/mailman/listinfo/python-list


re.sub unexpected behaviour

2010-07-06 Thread Javier Collado
Hello,

Let's imagine that we have a simple function that generates a
replacement for a regular expression:

def process(match):
return match.string

If we use that simple function with re.sub using a simple pattern and
a string we get the expected output:
re.sub('123', process, '123')
'123'

However, if the string passed to re.sub contains a trailing new line
character, then we get an extra new line character unexpectedly:
re.sub(r'123', process, '123\n')
'123\n\n'

If we try to get the same result using a replacement string, instead
of a function, the strange behaviour cannot be reproduced:
re.sub(r'123', '123', '123')
'123'

re.sub('123', '123', '123\n')
'123\n'

Is there any explanation for this? If I'm skipping something when
using a replacement function with re.sub, please let me know.

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


Re: re.sub unexpected behaviour

2010-07-06 Thread Javier Collado
Thanks for your answers. They helped me to realize that I was
mistakenly using match.string (the whole string) when I should be
using math.group(0) (the whole match).

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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-18 Thread Javier Bezos
"Istvan Albert" <[EMAIL PROTECTED]> escribió:

> How about debugging this (I wonder will it even make it through?) :
>
> class 6???
 >   6?? = 0
 >  6? ?? ?=10

This question is more or less what a Korean who doesn't
speak English would ask if he had to debug a program
written in English.

> (I don't know what it means, just copied over some words
> from a japanese news site,

A Japanese speaking Korean, it seems. :-)

Javier
--
http://www.texytipografia.com 


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

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-18 Thread Javier Bezos

>> This question is more or less what a Korean who doesn't
>> speak English would ask if he had to debug a program
>> written in English.
>
> Perhaps, but the treatment by your mail/news software plus the
> delightful Google Groups of the original text (which seemed intact in
> the original, although I don't have the fonts for the content) would
> suggest that not just social or cultural issues would be involved.

The fact my Outlook changed the text is irrelevant
for something related to Python. And just remember
how Google mangled the intentation of Python code
some time ago. This was a technical issue which has
been solved, and no doubt my laziness (I didn't
switch to Unicode) won't prevent non-ASCII identifiers
be properly showed in general.

Javier
-
http://www.texytipografia.com



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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-18 Thread Javier Bezos
<@yahoo.com> escribió:

>> > Perhaps, but the treatment by your mail/news software plus the
>> > delightful Google Groups of the original text (which seemed intact in
>> > the original, although I don't have the fonts for the content) would
>> > suggest that not just social or cultural issues would be involved.
>>
>> The fact my Outlook changed the text is irrelevant
>> for something related to Python.
>
> On the contrary, it cuts to the heart of the problem.  There are
> hundreds of tools out there that programmers use, and mailing lists
> are certainly an incredibly valuable tool--introducing a change that
> makes code more likely to be silently mangled seems like a negative.

In such a case, the Python indentation should be
rejected (quite interesting you removed from my
post the part mentioning it). I can promise there
are Korean groups and there are no problems at
all in using Hangul (the Korean writing).

Javier
-
http://www.texytipografia.com 


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

Re: Python Feature Request: Allow changing base of member indices to 1

2007-04-15 Thread Javier Bezos

> Here is a document giving good reasons for indexing to start at
> zero, as in Python.
> http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html
> The author has done a bit:
> http://en.wikipedia.org/wiki/Dijkstra

Dijkstra's argument is obsolete, as it is based on
how array length was computed many years ago -- if
we have an array a = b..e, then the lenght of a
is e-b (half open range). Good at low level
programming.

But a quarter of a century after we know concepts
are much better than low level programming and
explicit computations -- if we have an array
a = b..e, then the length of a should be a.length()
(or a.length(b,e)), and it is independent of
arbitrary ranges, index bases, or even steps
(eg, {-4, -2, 0, 2, 4}).

Of course, the index base should be always the
same _by default_ (individual lists could require
another index base, and that's fine). Otherwise
it would a mess, as you said.

Javier
-
http://www.texytipografia.com 


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


Re: Python Feature Request: Allow changing base of member indices to 1

2007-04-16 Thread Javier Bezos
Paddy,

>> Dijkstra's argument is obsolete, as it is based on
>> how array length was computed many years ago -- if
>> we have an array a = b..e, then the lenght of a
>> is e-b (half open range). Good at low level
>> programming.
>>
>> But a quarter of a century after we know concepts
>> are much better than low level programming and
>> explicit computations -- if we have an array
>> a = b..e, then the length of a should be a.length()
>> (or a.length(b,e)), and it is independent of

> Hi Javier,
> You seem to have missed out array *indexing*
> in your argument, or is array indexing obsolete?

Of course, it isn't, but it has evolved over the
past 25 years. When Djikstra wrote that, many
people (including me) was using a Spectrum---
Now we have OO programming to deal with concepts
and a more generic programming. So, to me it's
clear his _argument_ is very outdated and cannot
be applied directly and withot reservations to
modern languages like Python.

Javier
-
http://www.texytipografia.com 


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


Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-15 Thread Javier Bezos
"René Fleschenberg" <[EMAIL PROTECTED]> escribió en el mensaje
news:[EMAIL PROTECTED]

> This is a very weak argument, IMHO. How do you want to use Python
> without learning at least enough English to grasp a somewhat decent
> understanding of the standard library?

By heart. I know a few _very good_ programmers
who are unable to understand an English text.
Knowing English helps, of course, but is not
required at all. Of course, they don't know how
to name identifiers in English, but it happens
they _cannot_ give them proper Spanish names,
either (I'm from Spain).

+1 for the PEP, definitely.

> But having, for example, things like open() from the stdlib in your code
> and then öffnen() as a name for functions/methods written by yourself is
> just plain silly. It makes the code inconsistent and ugly without
> significantly improving the readability for someone who speaks German
> but not English.

Agreed. I always use English names (more or
less :-)), but this is not the PEP is about.

Javier
--
http://www.texytipografia.com




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

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-16 Thread Javier Bezos
"Eric Brunel" <[EMAIL PROTECTED]> escribió en el mensaje

> Funny you talk about Japanese, a language I'm a bit familiar with and for
> which I actually know some input methods. The thing is, these only work if
> you know the transcription to the latin alphabet of the word you want to
> type, which closely match its pronunciation. So if you don't know that ??
> ? is pronounced "uriba" for example, you have absolutely no way of
> entering the word.

Actually, you can draw the character (in XP, at
least) entirely or in part and the system shows a
list of them with similar shapes. IIRC, there is
a similar tool on Macs. Of course, I'm not saying
this allows to enter kanji in a easy and fast way,
but certainly it's not impossible at all, even if
you don't know the pronunciation.

Javier
---
http://www.texytipografia.com




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

PersistenceDict Question

2006-09-24 Thread Javier Subervi
Hi;I'm trying to get a module to work in a Plone product. I am running Python 2.3.5. Here is the error I'm getting:2006-09-23T14:11:43 ERROR(200) Zope Could not import Products.ExternalSiteCatalogTraceback (most recent call last):  File "/usr/local/zope/278/lib/python/OFS/Application.py", line 673, in import_product    product=__import__(pname, global_dict, global_dict, silly)  File "/usr/local/zope/instance2/Products/ExternalSiteCatalog/__init__.py", line 36, in ?    from Products.ExternalSiteCatalog.tool import ExternalSiteCatalog  File "/usr/local/zope/instance2/Products/ExternalSiteCatalog/tool.py", line 57, in ?    from Products.ExternalSiteCatalog.content import ExternalSiteCatalogTaskProperties  File "/usr/local/zope/instance2/Products/ExternalSiteCatalog/content/__init__.py", line 27, in ?    import ExternalSiteCatalogTask  File
 "/usr/local/zope/instance2/Products/ExternalSiteCatalog/content/ExternalSiteCatalogTask.py", line 32, in ?    from persistent.dict import PersistentDictImportError: No module named persistent.dictI find no "persistent.dict" anywhere. However, I do find a "PersistentDict.py", and it appears that it is not in my version of Python. I went ahead and added it, then rebooted my server since I couldn't figure out how to restart Python (please tell me how to do that). But my Zope still threw the same error. How do I deal with this?TIA,Javier 2 
		Do you Yahoo!? 
Get on board. You're invited to try the new Yahoo! Mail.-- 
http://mail.python.org/mailman/listinfo/python-list

AttributeError Question

2006-09-24 Thread Javier Subervi
Hi;I'm new to troubleshooting scripts. This came up when trying to load a Zope product:    * Module Products.PageTemplates.ZRPythonExpr, line 47, in __call__  __traceback_info__: field.Vocabulary(here)    * Module Python _expression_ "field.Vocabulary(here)", line 1, in <_expression_>    * Module Products.Archetypes.Field, line 432, in Vocabulary    * Module Products.Archetypes.utils, line 145, in mapply    * Module Products.EasyDocument.content.EasyDocument, line 112, in _list_templates    * Module OFS.Traversable, line 161, in unrestrictedTraverse  __traceback_info__: ([], 'EasyDocumentTemplates')    * Module Products.Archetypes.BaseObject, line 1072, in __bobo_traverse__AttributeError: EasyDocumentTemplatesCan you tell me what I should do with
 Attribute Errors in general? The docs say an AttributeError is "Raised when an attribute reference or assignment fails." Okay, fine...where do I go from here?TIA,beno2 
		Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls.  Great rates starting at 1¢/min.-- 
http://mail.python.org/mailman/listinfo/python-list

Problem Coordinating Python and OpenLDAP

2006-09-26 Thread Javier Subervi
Hi;I'm on FreeBSD 6.1. In order to integrate Python into LDAP I have to intstall an interpreter called py-ldap2 (in my case). I installed it from the ports but when I go to my python interpreter and enter "import ldap" it tells me the module can't be found. What am I doing wrong? I got this at the end of my installation of py-ldap2:===>   Registering installation for py24-ldap2-2.2.0cyrus-sasl-2.1.22: "/usr/ports/1" non-existent -- dependency list incompleteopenldap-sasl-client-2.3.27: "/usr/ports/1" non-existent -- dependency list incompletepy24-ldap2-2.2.0: "/usr/ports/1" non-existent -- dependency list incompleteIs this a problem? I've tried installing those ports, the first is in, the second I couldn't find and the third is the one I thought I just finished installing! What gives?TIA,Javier3 
		 All-new Yahoo! Mail - Fire up a more powerful email and get things done faster.-- 
http://mail.python.org/mailman/listinfo/python-list

Upgrading Problems

2006-09-30 Thread Javier Subervi
Hi;I have python 2.3.5 and I'd like to upgrade to 2.5.0. I've tried installing from FreeBSD ports and the oldfashioned way from source code, with the "configure && make && make install" dance, and still when I call up my python interpreter it tells me I'm in 2.3.5! Why? I didn't do "altinstall"! What gives?TIA,Javier2 
		Do you Yahoo!? 
Get on board. You're invited to try the new Yahoo! Mail.-- 
http://mail.python.org/mailman/listinfo/python-list

Working w/ Yield

2006-12-14 Thread Javier Subervi
Hi;
I'm trying to tweak a script I found here:
http://zopelabs.com/cookbook/1118667115
to get it to do what I want. I'm no wizard at Python, much less newfangled 
tools like yield. I understand that one cannot use "return" when working with 
yield, but I don't understand how to achieve the same result. Here's my code:

from random import randrange

def getRandomQuote(top, topdown=True):
  objs = top.objectValues()
  num = 1
  numAndQuote, quotes = [], []
  for obj in objs:
if isdir(obj):
  dirs.append(obj)
else:
  quotes.append(obj)
  if topdown:
yield top, dirs, quotes
  for obj in dirs:
for x in getRandomQuote(obj, topdown):
  yield x
  if not topdown:
yield top, dirs, quotes
  for q in quotes:
numAndQuote.append(num, q)
num += num

def isdir(obj):
  if obj.meta_type == 'Folder':
return True
  else:
return False

def demo(self):
  root = self.restrictedTraverse('/theSite/en-us/Books')
  num = randrange(1, len(num), 1)
  luckyWinner = numAndQuote.pop(num)
  path = '/'.join(luckyWinner.getPhysicalPath()) or '/'
  return path

How can I stitch all this together to return the path? Or, how do I call the 
demo after executing the yield?
TIA,
Javier


 

Want to start your own business?
Learn how on Yahoo! Small Business.
http://smallbusiness.yahoo.com/r-index-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Grouping code by indentation - feature or ******?

2005-03-26 Thread Javier Bezos

"Tim Tyler" <[EMAIL PROTECTED]> escribió en el mensaje
news:[EMAIL PROTECTED]
> What do you guys think about Python's grouping of code via indentation?
>
> Is it good - perhaps because it saves space and eliminates keypresses?
>
> Or is it bad - perhaps because it makes program flow dependent on
> invisible, and unpronouncable characters - and results in more
> manual alignment issues by preventing code formatters from managing
> indentation?

I particularly hate it, but Python has lots of good
things which compesate that (another annoying point
of Python are slices -- mine are always off by 1).
I always write explicitly ends as #end, so that I
can reorganice the code easily if necessary. Maybe
in the future, when Ruby matures, I could change
my mind, but currently Python is still my favourite
scripting language (as formerly was Tcl).

Javier
_______
Javier Bezos| TeX y tipografía
jbezos at wanadoo dot es| http://perso.wanadoo.es/jbezos
|...
CervanTeX (Spanish TUG) | http://www.cervantex.org




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


Re: Grouping code by indentation - feature or ******?

2005-03-27 Thread Javier Bezos

"Jacob Lee" <[EMAIL PROTECTED]> escribió en el mensaje

>> things which compesate that (another annoying point
>> of Python are slices -- mine are always off by 1).

>About slices:

Thank you, but I knew the motivations for this
odd behaviour, which can be found as well in, for
example, MetaFont. However, I disagree.

> satisfy some handy properties, the first of which being:
>   l[:n] + l[n:] = l

I don't think l[:5] + l[5:] = l is a handy property
and to me is clearly counterintuitive. Further,
I don't understand why l[a:b] has a behaviour which
does't depend on its own logic but on that of certain
constructs containing slices but which aren't the
slices themselves. If you have to add or substract
1 in an expression containing slices (or contained
in a slice), this belongs to the logic of the
expression, not to the slices syntax.

MetaFont explains this by saying that the index
doesn't refer to a character but to a position
between characters, which when traslated to Python
would mean:

   s   t   r   i   n   g
 ^   ^   ^   ^   ^   ^   ^
 0   1   2   3   4   5   6

so that [1:2] is "t".

Javier
___
Javier Bezos| TeX y tipografía
jbezos at wanadoo dot es| http://perso.wanadoo.es/jbezos
|...
CervanTeX (Spanish TUG) | http://www.cervantex.org





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


Re: Grouping code by indentation - feature or ******?

2005-03-27 Thread Javier Bezos

"Reinhold Birkenfeld" <[EMAIL PROTECTED]> escribió en el mensaje
news:[EMAIL PROTECTED]

>>s   t   r   i   n   g
>>  ^   ^   ^   ^   ^   ^   ^
>>  0   1   2   3   4   5   6
>>
>> so that [1:2] is "t".
>
> Incidentally, the Python Tutorial tells us exactly the same...

Ah! I've just forgotten that...

Javier
___
Javier Bezos | Mem. A multilingual system for LaTeX
jbezos at wanadoo dot es | http://mem-latex.sourceforge.net
.|:


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


Re: Grouping code by indentation - feature or ******?

2005-03-28 Thread Javier Bezos

"Dennis Lee Bieber" <[EMAIL PROTECTED]> escribió en el mensaje
news:[EMAIL PROTECTED]

> > I don't think l[:5] + l[5:] = l is a handy property
> > and to me is clearly counterintuitive. Further,
[snipped in the reply]

Please, don't remove parts of my post which are
relevant to the discussion. I said:

>Further,
>I don't understand why l[a:b] has a behaviour which
>does't depend on its own logic but on that of certain
>constructs containing slices but which aren't the
>slices themselves.

You give a counterexample:

> st = "This i a string with typo, for example"
> pos = st.find("i ") + 1 # "+ 1" to get the space after "i"
> new_st = st[:pos] + "s" + st[pos:]

but that shows clearly what I was saying --
this tricky syntax means that you have not
to write st[:pos-1] in this particular code
(but you still have to "write" it in your
mind since it forms part of the logic of the
problem). These kind of hacks look perlish
to me.

Of course, the danger of being off-by-one would
be still present, but I would like to note that
if you change the syntax to avoid it in some
expressions you will find problems in another
expressions where otherwise it wouldn't be
present (counting from the end with negatives
values is particularly funny). The same applies
if the first element is 1 instead of 0, for
example.

Then, why not to leave that to the logic of
the problem and not to tricky syntaxes? A pity,
given that Python has a quite straighforward
syntax.

Javier



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


Re: Grouping code by indentation - feature or ******?

2005-03-30 Thread Javier Bezos
"Myles Strous" <[EMAIL PROTECTED]> escribió en el mensaje
news:[EMAIL PROTECTED]
>>> satisfy some handy properties, the first of which being:
>>>   l[:n] + l[n:] = l
>>
>> I don't think l[:5] + l[5:] = l is a handy property
>> and to me is clearly counterintuitive. Further,
>
> It can be quite useful for inserting something into a list (or string),
> after finding the position where you wish to insert it.
> improvedList = l[:n] + [new stuff] + l[n:]

As I answered in another post this is not more
useful than writing l[:n-1]. Of course, I'm aware
of the case where n=0, but this would require only
a bit of extra code (and, after all, I'm just saying
that half-open ranges are not a panacea and that I
don't like their side effects).

> I vaguely remember hearing at one stage that the
> sequence[position:position+length] notation is also potentially useful
> for indexing into large strings or buffers.

Right, to some extent it's useful, but at the cost
of introducing tricky syntaxes for very specific
cases, like this one, and unexpected off-by-one
errors in other cases, which is my point. For
example, recently I had to get a value from a
list preceded by the two previous values:
lst[n-2:n+1] and not the more logical (at last
to my eyes) lst[n-2:n].

Instead of giving further examples I would like
to cite three cases:

1) You have a starting point (s) and a
   length (t): lst[s:s+t].
2) You have an ending point (e) and a
   length: lst[e-t+1:e+1].
3) You have a starting point and an ending
   point: lst[s:e+1].

What's odd is that Python applies the syntax of
case 3 to the logic of case 1. While something
like lst[s:s+t-1] for the first case could be
explained in simple mathematical terms (in other
words, it's an integral part of the algorithms),
I cannot find a way to explain the e+1 in cases
2 and 3 (and the inconsistency with e-t+1 in case
2 vs. s+t in case 1) except the Python syntax.

Javier
___
Javier Bezos | Mem. A multilingual system for LaTeX
jbezos at wanadoo dot es | http://mem-latex.sourceforge.net
.|




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


Re: Grouping code by indentation - feature or ******?

2005-04-01 Thread Javier Bezos
"Steve Holden" <[EMAIL PROTECTED]> escribió en el mensaje
news:[EMAIL PROTECTED]

  [Discussion on Python slices and the off-by-one issue
   deleted]

> While this may be an interesting philosophical (or should that be
> philological) discussion, since Python has worked this way for donkey's
> years, and since a change would break 30% of the existing codebase, you
> clearly can't be advocating change.
>
> So, what's the point of this thread now?

None. In fact, I sent my last post a couple
of days ago, so I don't see the point of your
message. This thread began when some people
thought that I had to be convinced about how
wonderful slices are, after I said _incidentally_
I didn't like Python slices (and then I had to
explain in turn why I don't like them). Perhaps
you should ask those people, not me.

Javier
___
Javier Bezos | Mem. A multilingual system for LaTeX
jbezos at wanadoo dot es | http://mem-latex.sourceforge.net
.|




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


Re: Why Python does *SLICING* the way it does??

2005-04-20 Thread Javier Bezos

<[EMAIL PROTECTED]> escribió en el mensaje
news:[EMAIL PROTECTED]
> Many people I know ask why Python does slicing the way it does.
>
> Can anyone /please/ give me a good defense/justification???
>
> I'm referring to why mystring[:4] gives me
> elements 0, 1, 2 and 3 but *NOT* mystring[4] (5th element).
>
> Many people don't like idea that 5th element is not invited.
>
> (BTW, yes I'm aware of the explanation where slicing
> is shown to involve slices _between_ elements.  This
> doesn't explain why this is *best* way to do it.)

Recently there was a short (sub)thread about that.
One of my messages (against half-open slices) is,
for example

http://groups-beta.google.com/group/comp.lang.python/msg/5532dd50b57853b1

Javier

___
Javier Bezos| TeX y tipografía
jbezos at wanadoo dot es| http://perso.wanadoo.es/jbezos
|...
CervanTeX (Spanish TUG) | http://www.cervantex.org







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


Re: Why Python does *SLICING* the way it does??

2005-04-20 Thread Javier Bezos

"James Stroud" <[EMAIL PROTECTED]> escribió en el mensaje
news:[EMAIL PROTECTED]
> I like this, it works for any integer.
> >>> str="asdfjkl;"
> >>> i=-400
> >>> print str[:i]+str[i:]
> asdfjkl;
> >>> i = 65534214
> >>> print str[:i]+str[i:]
> asdfjkl;

Actually, this has no relation with the half-open
slices but with the fact that if i goes beyond
the limit of the string then Python, wisely, doesn't
raise an error but instead return the string until
the end. When people say that half-open slices work
for every i, they are tinking in the case i=0.

Javier

___
Javier Bezos| TeX y tipografía
jbezos at wanadoo dot es| http://perso.wanadoo.es/jbezos
|...
CervanTeX (Spanish TUG) | http://www.cervantex.org






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


Connecting Google News

2017-07-16 Thread Javier Bezos
Google News used to fail with the high level functions provided by httplib 
and the like. However, I found this piece of code somewhere:


def gopen():
  http = httplib.HTTPSConnection('news.google.com')
  http.request("GET","/news?ned=es_MX" ,
headers =
   {"User-Agent":"Mozilla/5.0 (X11; U; Linux i686; es-MX) 
AppleWebKit/532.8 (KHTML, like Gecko) Chrome/4.0.277.0 Safari/532.8",

   "Host":'news.google.com',
   "Accept": "*/*"})
  return http.getresponse()

A few days ago, Google News has been revamped and it doesn't work any more 
(2.6/Win7, 2.7/OSX and, with minimal changes, 3.6/Win7), because the page 
contents is empty. The code itself doesn't raise any errors. Which is the 
proper way to do it now? I must stick to the standard libraries.


The returned headers are:

--
[('Content-Type', 'application/binary'),
 ('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate'),
 ('Pragma', 'no-cache'),
 ('Expires', 'Mon, 01 Jan 1990 00:00:00 GMT'),
 ('Date', 'Thu, 13 Jul 2017 16:37:48 GMT'),
 ('Location', 'https://news.google.com/news/?ned=es_mx&hl=es'),
 ('Strict-Transport-Security', 'max-age=10886400'),
 ('P3P',
  'CP="This is not a P3P policy! See '
 'https://support.google.com/accounts/answer/151657?hl=en for more 
info."'),

 ('Server', 'ESF'),
 ('Content-Length', '0'),
 ('X-XSS-Protection', '1; mode=block'),
 ('X-Frame-Options', 'SAMEORIGIN'),
 ('X-Content-Type-Options', 'nosniff'),
 ('Set-Cookie', 
'NID=107=qwH7N2hB12zVGfFzrAC2CZZNhrnNAVLEmTvDvuSzzw6mSlta9D2RDZVP9t5gEcq_WJjZQjDSWklJ7LElSnAZnHsiF4CXOwvGDs2tjrXfP41LE-6LafdA86GO3sWYnfWs;Domain=.google.com;Path=/;Expires=Fri, 
'

 '12-Jan-2018 16:37:48 GMT;HttpOnly'),
 ('Alt-Svc', 'quic=":443"; ma=2592000; v="39,38,37,36,35"')]
---

`read()` is empty string ('' or b''). `status` is 302. `reason` is `Found`.

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


Re: Connecting Google News

2017-07-16 Thread Javier Bezos

Chris,


(Also, please upgrade your Windows box to run Python 2.7.)


It's not /my/ Windows box. I'm allowed to run my script, that's
all. My Windows box is actually that with 3.6.


  http = httplib.HTTPSConnection('news.google.com')
  http.request("GET","/news?ned=es_MX" ,



  ('Location', 'https://news.google.com/news/?ned=es_mx&hl=es'),

...


See that Location header? The web server wants to redirect you
somewhere. Your low-level HTTP library does not handle redirects
automatically, so you’d need to take care of that yourself.


I didn't notice the bar just before ?ned ! I don't know how many
times I've compared the URLs without realizing it was added. Silly
me!

Thank you
Javier


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


Re: Connecting Google News

2017-07-16 Thread Javier Bezos

Peter,


  http.request("GET","/news/headlines?ned=es_mx&hl=es" ,


Thank you. It works, too.

Javier

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


Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Javier Collado
Hello,

2011/8/31 T. Goodchild :
> But one of the things that bugs me is the requirement that all class
> methods have 'self' as their first parameter.  On a gut level, to me
> this seems to be at odds with Python’s dedication to simplicity.

I think the answer to this question is part of the zen of python:
<>

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

Regards,
Javier
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CSV to matrix array

2013-04-12 Thread Javier Miranda
Keep the flattened data array others suggested, and then just split it like
this: *(replace `example_data`, `_array`, and `columns`)*

>>> example_data = range(15)

>>> split_array = lambda _array, colums: \

. . .[_array[i:i + colums] for i in \

. . .xrange(0, len(_array), colums)]

 >>> print split_array(example_data, 5)

[[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14]]

Gist <https://gist.github.com/anonymous/f9064e4c8790ae037ec6>

What do you guys think?


On Fri, Apr 12, 2013 at 12:46 PM, Dave Angel  wrote:

> On 04/12/2013 01:29 PM, Ana Dionísio wrote:
>
>> That only puts the data in one column, I wanted to separate it.
>>
>> For example:
>> data in csv file:
>>
>> 1 2 3 4 5
>> 7 8 9 10 11
>> a b c d e
>>
>> I wanted an array where I could pick an element in each position. In the
>> case above if I did print array[0][3] it would pick 4
>>
>>
> I know nothing about numpy.
>
> How about something like:
> import csv
> myreader = csv.reader()
> mylist = list(myreader)
>
>
> Presumably you can fill in the details.  Anyway, I think this will give
> you a list of lists, and perhaps you can convert that to a numpy array, if
> you really need one of those.
>
>
> --
> DaveA
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>



-- 
Javier Miranda
Mobile: +52 333 129 20 70
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Reading by positions plain text files

2010-12-01 Thread Javier Van Dam

Ok. I will try it and let you know. Thanks a lot!!

J

> Date: Tue, 30 Nov 2010 20:32:56 -0600
> From: python.l...@tim.thechases.com
> To: javiervan...@gmail.com
> CC: python-list@python.org
> Subject: Re: Reading by positions plain text files
> 
> On 11/30/2010 08:03 PM, javivd wrote:
> > On Nov 30, 11:43 pm, Tim Harig  wrote:
> >>> VARIABLE NAME  POSITION (COLUMN) IN FILE
> >>> var_name_1 123-123
> >>> var_name_2 124-125
> >>> var_name_3 126-126
> >>> ..
> >>> ..
> >>> var_name_N 512-513 (last positions)
> >>
> > and no, MRAB, it's not the similar problem (at least what i understood
> > of it). I have to associate the position this file give me with the
> > variable name this file give me for those positions.
> 
> MRAB may be referring to my reply in that thread where you can do 
> something like
> 
>OFFSETS = 'offsets.txt'
>offsets = {}
>f = file(OFFSETS)
>f.next() # throw away the headers
>for row in f:
>  varname, rest = row.split()[:2]
>  # sanity check
>  if varname in offsets:
>print "[%s] in %s twice?!" % (varname, OFFSETS)
>  if '-' not in rest: continue
>  start, stop = map(int, rest.split('-'))
>  offsets[varname] = slice(start, stop+1) # 0-based offsets
>  #offsets[varname] = slice(start+1, stop+2) # 1-based offsets
>f.close()
> 
>def do_something_with(data):
>  # your real code goes here
>  print data['var_name_2']
> 
>for row in file('data.txt'):
>  data = dict((name, row[offsets[name]]) for name in offsets)
>  do_something_with(data)
> 
> There's additional robustness-checks I'd include if your 
> offsets-file isn't controlled by you (people send me daft data).
> 
> -tkc
> 
> 
> 
> 
  -- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >