Re: socket programming

2013-05-06 Thread Pedro
On Saturday, May 4, 2013 5:37:42 AM UTC-4, Irmen de Jong wrote:
> On 4-5-2013 4:13, Pedro wrote: > SERVER: > > import socket # Import socket 
> module > > s = socket.socket() # Create a socket object > host = 
> socket.gethostname() # Get local machine name > port = 12345 # Reserve a port 
> for your service. > s.bind((host, port)) # Bind to the port This won't always 
> work as expected, particularly on machines with multiple network interfaces. 
> Depending on what your situation requires, a simpler s.bind(('', port)) can 
> be more suitable. (empty string means INADDR_ANY) > > s.listen(5) # Now wait 
> for client connection. > while True: > c, addr = s.accept() # Establish 
> connection with client. > print 'Got connection from', addr > c.send('Thank 
> you for connecting') The send() call returns the number of bytes actually 
> sent. This number can be LESS than the length of the buffer you wanted to 
> send! So you will need a loop here to make sure all data is actually 
> transmitted. The easiest way out is to use this instead: c.sendall('Thank you 
> for connecting') However, t
 his might fail due to some I/O error and then it leaves your socket in an 
undetermined state because you can't tell how much of the data was actually 
transmitted. (Recovering from errors is problematic if not impossible with 
sendall, as far as I know the only thing you can do is just close the bad 
socket and create a new one) > c.close() # Close the connection > > CLIENT: > 
import socket # Import socket module > > s = socket.socket() # Create a socket 
object > host = socket.gethostname() # Get local machine name > port = 12345 # 
Reserve a port for your service. > > s.connect((host, port)) > print 
s.recv(1024) While this usually seems to work (especially with small buffer 
sizes) it has the same problem as pointed out above with send(): recv() might 
not retrieve all data at once. It returns the amount of data actually received 
in that call. [warning, hairy details below] You HAVE to make a loop here to 
get all chunks of data until they add up to the total data size that you 
expected. 
 (There's a flag MSG_WAITALL you can pass to recv to get around this. But it is 
not available on all systems, and on some systems where it is provided, it 
doesn't work correctly.) Also you need to be careful with the buffer size 
passed to recv, too large and it causes problems on some systems. Around 60kb 
seems a good upper bound here. This usually also means you need to somehow tell 
the receiving end of the socket how much data is to be expected, and only then 
send that actual data. One way to do this is to send the length first as a 
struct-packed integer (4 bytes), and the data after that. Note that even 
reading the 4 bytes on the receiving side to determine the expected length 
might be broken up in multiple chunks: you can't even expect recv(4) to always 
return those 4 bytes. So even that needs to be in a loop... Other ways to know 
on the receiving end when to stop reading from the socket is to standardize on 
some sort of termination character (such as '\0' or perhaps '\n'), fixed
  length buffers, or to always close the socket after every single message (but 
that is hugely inefficient if you need to send multiple messages). > s.close # 
Close the socket when done > Oh, you forgot the parentheses here: s.close() 
Bottom line: Socket programming on this level is hugely complicated. It doesn't 
seem too bad if you start of with these simple example programs, but that's 
false hope. If at all possible, avoid direct socket programming, and use a 
high-level protocol or library instead (ftp/http/some IPC library/Twisted). Let 
them deal with the complexity of the socket layer. Regards Irmen de Jong

Thanks for the reply. I'm sending short strings as commands to my server 
machine so the socket module seems to be doing the trick reliably. I'll try to 
add Twisted to my arsenal though. 
Cheers
-- 
http://mail.python.org/mailman/listinfo/python-list


testing - do not reply

2013-11-15 Thread Pedro

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


socket programming

2013-05-03 Thread Pedro
I'm writing a simple app that uses socket programming, I'm using the following 
from tutorialspoint as a framework but I'm having a couple of issues 
implementing it. 

First - this code constantly loops around an open socket. Is there a way to use 
something like an interrupt so I don't have to loop constantly to monitor the 
socket?

Second, if any part of the program fails execution (crashes) the port often 
remains open on my windows machine and the only way to close it that i know of 
is through task manager or by rebooting the machine. Is there an easy way 
around this problem ? If I don't close the port the program can't open it again 
and crashes.

Thanks for looking



SERVER:

import socket   # Import socket module

s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345# Reserve a port for your service.
s.bind((host, port))# Bind to the port

s.listen(5) # Now wait for client connection.
while True:
   c, addr = s.accept() # Establish connection with client.
   print 'Got connection from', addr
   c.send('Thank you for connecting')
   c.close()# Close the connection

CLIENT:
import socket   # Import socket module

s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345# Reserve a port for your service.

s.connect((host, port))
print s.recv(1024)
s.close # Close the socket when done
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: socket programming

2013-05-03 Thread Pedro
On Friday, May 3, 2013 10:23:38 PM UTC-4, Chris Angelico wrote:
> On Sat, May 4, 2013 at 12:13 PM, Pedro  wrote:
> 
> > First - this code constantly loops around an open socket. Is there a way to 
> > use something like an interrupt so I don't have to loop constantly to 
> > monitor the socket?
> 
> 
> 
> The accept() call should block. It's not going to spin or anything. If
> 
> you need to monitor multiple sockets, have a look at select().
> 
> 
> 
> > Second, if any part of the program fails execution (crashes) the port often 
> > remains open on my windows machine and the only way to close it that i know 
> > of is through task manager or by rebooting the machine. Is there an easy 
> > way around this problem ? If I don't close the port the program can't open 
> > it again and crashes.
> 
> 
> 
> It remains for a short time to ensure that there's no lurking
> 
> connections. You can bypass this check by setting the SO_REUSEADDR
> 
> option - lemme hunt that down in the Python docs, haven't done that in
> 
> Python for a while...
> 
> 
> 
> http://docs.python.org/3.3/library/socket.html#socket.socket.setsockopt
> 
> 
> 
> s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
> 
> 
> 
> That should do the job.
> 
> 
> 
> ChrisA

Thanks Chris, can you elaborate on the accept() call should block?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: socket programming

2013-05-03 Thread Pedro
On Friday, May 3, 2013 11:56:01 PM UTC-4, Chris Angelico wrote:
> On Sat, May 4, 2013 at 1:37 PM, Pedro  wrote:
> 
> > On Friday, May 3, 2013 10:23:38 PM UTC-4, Chris Angelico wrote:
> 
> >> The accept() call should block. It's not going to spin or anything. If
> 
> >>
> 
> >> you need to monitor multiple sockets, have a look at select().
> 
> >
> 
> > Thanks Chris, can you elaborate on the accept() call should block?
> 
> 
> 
> When you call accept(), your program stops running until there's a
> 
> connection. It's like calling input() (or raw_input()) and your
> 
> program stopping until you type something. You can disable that by
> 
> setting the socket nonblocking, but I don't think you're doing that
> 
> here (and you probably don't want to).
> 
> 
> 
> Consider the accept() call to be, effectively, like reading from the
> 
> bound socket. In many ways it functions that way.
> 
> 
> 
> ChrisA

Brilliant explanation Chris, I swear I read three different docs on that 
question and could not deduce what you just wrote. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Tkinter, toplevel and images

2008-08-22 Thread Pedro
Hi

I'm trying to build a small application that can display some images
in a toplevel window. I have this code:

def Results(master):
from Tkinter import Toplevel, Button, Label
from PIL import ImageTk

figures = ['first.png', 'second.png']

ResultsWindow = Toplevel(master)
ResultsWindow.title('Results')

picts = [ImageTk.PhotoImage(file = x) for x in figures]

butRW = Button(ResultsWindow, text = 'CLOSE', command =
ResultsWindow.destroy)
butRW.pack()

height = sum([x.height() for x in picts])
width = picts[0].width()

y = 0
for pict in picts:
label = Label(ResultsWindow,image=pict).pack()
y += pict.height()

from Tkinter import Tk
root = Tk()
Results(root)
root.mainloop()

and I just can see a grey window with a "close" button... However,
when I try the same code with the root I can see both images... Can
anyone give me a tip?

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


C++ to python with boost.python: Exposing virtual bool operator()(int )=0

2006-03-29 Thread Pedro
Hello pythonians! ;-D ,

I have a little problem when I expose (assisted by boost.python) classes 
with virtual functions, specially with operator().
In the C++ code below I test two different implementations of a member 
function of A that
takes as an argument the abstract class Base (see Option 1 / Option 2):
- Both compile without problems
- Only the second works in python (see python program below).

It seems like if the problem is in the way I expose operator()... but I 
do not understand it very well
Any clue about why this is happening?I would appreciate any comment on this.
Thank you very much in advance. :-D

Pedro.


//...
// C++ code..
//...
#include 
#define OPTION1
//#undef OPTION1

struct Base
{
virtual ~Base() {}
virtual int f() = 0;// Like in 
Boost.python tutorial
virtual int g(int) = 0;   // With 1 argument
virtual bool operator()(int ii) =0;//  __call__ - type function
};

class A{
private:
int v_;
public: A(int v): v_(v){}
   #ifdef OPTION1
/* Option 1 */ int fun(Base& c) const { return 
c(v_)?(c.g(v_)+c.f()):33; }
#else
/* Option 2 */ int fun(Base& c) const { return (c.g(v_)+c.f()); }
#endif
};

//:::BOOST::PYTHON in 
action:::
using namespace boost::python;

struct BaseWrap : Base, wrapper
{
int f(){return call(this->get_override("f").ptr());}
int g(int ii){return call(this->get_override("g").ptr(),ii);}
bool operator()(int ii){ return 
call(this->get_override("operator()").ptr(),ii);}
};

BOOST_PYTHON_MODULE(test2py)
{
class_("A",init())
.def("fun",&A::fun);

class_("Base")
.def("f", pure_virtual(&Base::f))
.def("g", pure_virtual(&Base::g))
.def("__call__", pure_virtual(&Base::operator())) ;
};


//...
// Python code...
//...

from test2py import *


## Extension of C++ class in python
class Derived(Base):
def f(self):
return 44
def g(self,n):
return n
def __call__(self, v):
return (v<23)


d=Derived()
print d.f()
print d.g(3)
print "is 20<23 and 24<23", d(20), d(24)


a=A(20)
print a.fun(d)

b=A(24)
print b.fun(d)


//..
// Executing Python code..
//.


With Option 1 IS NOT WORKING!!
...
int fun(Base& c) const { return c(v_)?(c.g(v_)+c.f()):33; }
...

 >>>
44
3
is 20<23 and 24<23 True False
Traceback (most recent call last):
  File "d:\My_Documents\src\pysource\test.py", line 29, in ?
print a.fun(d)
TypeError: 'NoneType' object is not callable


With Option 2 IS WORKING!!
...
int fun(Base& c) const { return (c.g(v_)+c.f()); }
...

 >>>
44
3
is 20<23 and 24<23 True False
64
68
 >>>


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


[ANN] pyknon: Simple Python library to generate music in a hacker friendly way.

2012-07-30 Thread Pedro Kroger
Pyknon is a simple music library for Python hackers. With Pyknon you
can generate Midi files quickly and reason about musical proprieties.
It works with Python 2.7 and 3.2.

Pyknon is very simple to use, here's a basic example to create 4 notes
and save into a MIDI file::

from pyknon.genmidi import Midi
from pyknon.music import NoteSeq

notes1 = NoteSeq("D4 F#8 A Bb4")
midi = Midi(1, tempo=90)
midi.seq_notes(notes1, track=0)
midi.write("demo.mid")


It's available on PyPI and its homepage is
http://kroger.github.com/pyknon/

Best regards,

Pedro
-
http://pedrokroger.net
http://musicforgeeksandnerds.com

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


Re: [ANN] pyknon: Simple Python library to generate music in a hacker friendly way.

2012-07-30 Thread Pedro Kroger

On Jul 30, 2012, at 3:33 PM, Ethan Furman  wrote:

> Pedro Kroger wrote:
>> Pyknon is a simple music library for Python hackers.
> 
> Sounds cool.  How is 'Pyknon' pronounced?

I pronounce it similarly as google translate does:

http://translate.google.com/#English|English|Pyknon

It's a musical Greek term, but since it's a Python package, I think it's 
acceptable
to pronounce the Py part as "pie" ;-)

>> It's available on PyPI and its homepage is
>> http://kroger.github.com/pyknon/
> 
> I would suggest you change the theme -- using Firefox 3.6 the page is very 
> difficult to read.

Thanks for the report. Do you mind if I ask why you are using such an old 
version?
(It looks fine with Firefox 14.0.1)

Cheers,

Pedro
-
http://pedrokroger.net
http://musicforgeeksandnerds.com

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


Re: docx/lxml

2012-07-31 Thread Pedro Kroger

On Jul 31, 2012, at 10:36 AM, [email protected] wrote:

> - Do you know any *easy to use*, *easy to deploy* package to generate ".doc 
> like" documents ?
> - Do you have any suggestion to do it differently (maybe with native packages 
> ?)
> 
> - As a python newby, I don't understand why you have to go through the pain 
> of installing packages since they should be able to work with just the 
> __init__.py files ? 
> 
> Regards,
> 
> Cyrille

Hi,

May I suggest you use pip and, possibly, virtualenv?
pip makes it easy to install Python packages while virtualenv creates an 
isolated Python environment

For instance, I just installed docx and its dependencies with:

pip install docx lxml datutils PIL

And I did that inside a testing virtualenv, so I wouldn't mess up my Python 
setup.

pip and virtualenv make it really easy and painless to install Python packages.

Cheers,

Pedro
-
http://pedrokroger.net
http://musicforgeeksandnerds.com

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


Re: [ANN] pyknon: Simple Python library to generate music in a hacker friendly way.

2012-07-31 Thread Pedro Kroger
On Aug 1, 2012, at 12:19 AM, Peter Billam  wrote:

> I'll check it out.  It probably fits into a whole software
> ecosystem that you're putting together …

yes, I use it for my book, Music for Geeks and Nerds and for teaching.

> It's a crowded area, e.g. my midi stuff is at:
>  http://www.pjb.com.au/midi/index.html

You have very interesting stuff, I'll check them out.

> and I'd probably do the above example by:
>  ~> muscript -midi <demo.mid
>  | 3/4 2.0
>  =1 treble 4 D 8 [F# A] 4 Bb
>  EOT

Nice. This reminded me to include a less simple example. After all,
the whole point of pyknon is to be able to generate music programmatically
using Python:

http://kroger.github.com/pyknon/

> You could consider posting Pyknon to comp.music.midi ;
> it's very low traffic, but some real gurus lurk there.

Good idea, thanks for the suggestion.

Cheers,

Pedro
-
http://pedrokroger.net
http://musicforgeeksandnerds.com

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


Re: Keep getting this in PyDev "TypeError: quiz() takes exactly 1 argument (0 given)"

2012-08-10 Thread Pedro Kroger

On Aug 10, 2012, at 3:52 PM, Chuck  wrote:

>if __name__ == '__main__':
> 
>quiz()
> 
> 

You need to instantiate your class:

foo = ElementsQuiz()
foo.quiz()


Pedro
-
http://pedrokroger.net
http://musicforgeeksandnerds.com

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


Re: protobuf + pypy

2012-08-24 Thread Pedro Larroy
_with pypy_

On Wed, Aug 22, 2012 at 12:16 AM, Mark Lawrence  wrote:
> On 21/08/2012 22:55, Pedro Larroy wrote:
>>
>> Hi
>>
>> Anyone knows if it's possible to use protobuffers with pypy?   Seems
>> there isn't much info on the web about this.
>>
>> Pedro.
>>
>
> Did you mean this, in which case there loads on the web
> http://code.google.com/p/protobuf/ ?
>
> --
> Cheers.
>
> Mark Lawrence.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.6 and Sqlite3 - Slow

2012-08-28 Thread Pedro Larroy
Try incrementing the variable cursor.arraysize a lot.

Pedro.

On Tue, Aug 28, 2012 at 11:20 PM, Dennis Lee Bieber
 wrote:
> On Tue, 28 Aug 2012 10:25:35 -0700 (PDT), [email protected]
> declaimed the following in gmane.comp.python.general:
>
>>
>> Doesn't the last paragraph imply that SQLite can operate on a network drive.
>>
>
> Most anything "can operate" on a network drive... But should it?
>
> The main thing the documentation is explaining is that one
> application accessing the database FILE does NOT LOCK OTHERS from
> accessing the file. Nothing about how the file is accessed. A
> low-activity web service would allow lots of people to concurrently
> access it -- but the processes that are doing said access are all local
> to the database file.
>
> Technically, M$ Access/JET (which is also file server database) also
> permits multiple clients -- but the locking becomes a pain.
> --
> Wulfraed Dennis Lee Bieber AF6VN
> [email protected]://wlfraed.home.netcom.com/
>
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a string to list for submission to easygui multenterb​ox

2012-05-01 Thread Pedro Kroger
Have you tried to use the function list?:

foo = (1,2,3)
list(foo)

Cheers,

Pedro

--
http://pedrokroger.net



On May 1, 2012, at 5:18 PM, ksals wrote:

> Please help a newbe.  I have a string returned from an esygui
> multchoicebox that looks like
>  this:  ('ksals', '', 'alsdkfj', '3', '') I need to convert this to
>  this:  ['ksals', '', 'alsdkfj', '3', '']
> 
> This is so I can submit this to a multenterbox with 5 fields
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Re: set PYTHONPATH for a directory?

2012-05-04 Thread Pedro Larroy
Isn't virtualenv for this kind of scenario?


Pedro.

On Fri, May 4, 2012 at 3:46 PM, Dave Angel  wrote:
> On 05/04/2012 08:21 AM, Neal Becker wrote:
>> I'm testing some software I'm building against an alternative version of a
>> library.  So I have an alternative library in directory L.  Then I have in an
>> unrelated directory, the test software, which I need to use the library 
>> version
>> from directory L.
>>
>> One approach is to set PYTHONPATH whenever I run this test software.  Any
>> suggestion on a more foolproof approach?
>>
> Simply modify  sys.path  at the beginning of your test software.  That's
> where import searches.
>
>
>
> --
>
> DaveA
>
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Real time event accuracy

2012-05-09 Thread Pedro Kroger
I don't know the details of how Kontakt works, but you can try pygame.midi:

pygame.midi - is a portmidi wrapper orginally based on the pyportmidi wrapper. 
Also pygame.music can play midi files. Can get input from midi devices and can 
output to midi devices. For osx, linux and windows. New with pygame 1.9.0. 
python -m pygame.examples.midi --output
(http://wiki.python.org/moin/PythonInMusic)


Pedro

--
http://pedrokroger.net
http://musicforgeeksandnerds.com/


On May 9, 2012, at 1:33 PM, Toby wrote:

> On 05/09/2012 09:13 AM, Dave Angel wrote:
>> On 05/09/2012 11:52 AM, Tobiah wrote:
>>> I'd like to send MIDI events from python to another
>>> program.  I'd like advice as to how to accurately
>>> time the events.  I'll have a list of floating point
>>> start times in seconds for the events, and I'd like to send them
>>> off as close to the correct time as possible.
>>> 
>>> I'd also appreciate suggestions and pointers to a 
>>> suitable python MIDI library, and maybe an outline
>>> of what must be done to get the MIDI events to 
>>> the other program's MIDI in.
>>> 
>>> Thanks,
>>> 
>>> Tobiah
>> 
>> You really need to specify the OS environment you're targeting, as well
>> as telling what program you're intending to feed MIDI into, if you've
>> already picked one.
> 
> I'm using Kontakt on Windows 7.  The MIDI file think would be good, but
> (not having that computer in front of me) I don't think that Kontakt
> had the ability to open a MIDI file.
> 
> Now, I know that I could load the file into Reaper, and use Kontakt
> as a plugin.  My problem is that I can't afford to mess with GUI menus
> during my composition process.  I need to edit a python program in
> Vi, then slap it out to python, hearing the music, then edit again.
> The cycle has to be very quick in order to get anything done.
> 
> Loading Kontakt with a bunch of samples is very time consuming, so
> it needs to keep running.  Now, if I could find a program that would
> interpret the MIDI file and send events off to Kontakt either as a plugin
> or standalone, then the MIDI file generation idea would be perfect.
> 
> 
> 
>> Also, the midi file format has timing information, and that timing
>> should be much better than trying to do it in python before sending
>> commands to some external program.  In other words, instead of sleeping
>> in your code and then issuing one midi event, use the midi file format
>> to send a stream of commands that will be played according to the timing
>> information included.
>> 
>> 
>> 
>> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Re: Real time event accuracy

2012-05-09 Thread Pedro Kroger
> I'd also appreciate suggestions and pointers to a 
> suitable python MIDI library, and maybe an outline
> of what must be done to get the MIDI events to the other program's MIDI in.

Mark Wirt's MidiUtil is a nice library for MIDI. It doesn't do exactly what you 
want (it generates MIDI files) but it's a nice library and it may be a good 
starting point:

http://code.google.com/p/midiutil/

Pedro

--
http://pedrokroger.net
http://musicforgeeksandnerds.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Print encoding problems in console

2011-07-15 Thread Pedro Abranches
Hello everyone.

I'm having a problem when outputing UTF-8 strings to a console.
Let me show a simple example that explains it:

$ python -c 'import sys; print sys.stdout.encoding; print u"\xe9"'
UTF-8
é

It's everything ok.
Now, if you're using your python script in some shell script you might have
to store the output in some variable, like this:

$ var=`python -c 'import sys; print sys.stdout.encoding; print u"\xe9"'`

And what you get is:

Traceback (most recent call last):
  File "", line 1, in 
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position
0: ordinal not in range(128)

So, python is not being able to detect the encoding of the output in a
situation like that, in which the python script is called not directly but
around ``.

Why does happen? Is there a way to solve it either by python or by shell
code?

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


monotonically increasing memory usage

2011-07-28 Thread Pedro Larroy
Hi

pickling

Just crossposting this from stackoverflow:

http://stackoverflow.com/questions/6857006/python-monotonically-increasing-memory-usage-leak

Any hints?


Pedro.

-- 
Pedro Larroy Tovar   |    http://pedro.larroy.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Can't Uninstall !

2018-02-12 Thread Pedro Crescencio
 

 

Hello, 

 

I tried to uninstall Python, but it is not possible.

Even when message say it is uninstalled : 



 

The software is still on applications menu: 



 

How do I do to uninstall it ?

I have the same problem with booth python versions (3.6.4 and 3.7.0b1) and
the Sourcetree of Atlassian.

 

Best regards, 

 

Pedro

 

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


RE: Can't Uninstall !

2018-02-13 Thread Pedro Crescencio
Hello Michael, 

Here my answers

1. Why do you want to uninstall it? What are you trying to accomplish by
uninstalling it?
-> I installed Python to test a software. Now I do not need python any more.

2. What operating system are you using?
-> Windows 10 Familly 64b

3. How did you try to uninstall it?
Using Windows standard uninstall procedure 
https://www.windowscentral.com/how-to-uninstall-apps-windows-10

4. What messages did you get when you tried to uninstall it?
The message says : "Uninstalled". But I still have the icon over the App
list. 

5. How did you install two different 3.x versions?
I tried to reinstall to do a proper uninstall. I tried with the latest
version that might fix some bugs. 




-Message d'origine-
De : Python-list [mailto:[email protected]]
De la part de Michael F. Stemper
Envoyé : mardi 13 février 2018 01:07
À : [email protected]
Objet : Re: Can't Uninstall !

On 2018-02-12 11:54, Pedro Crescencio wrote:

> Hello,

> I tried to uninstall Python, but it is not possible.
> 
> Even when message say it is uninstalled :

> The software is still on applications menu:

> How do I do to uninstall it ?
> 
> I have the same problem with booth python versions (3.6.4 and 3.7.0b1) 
> and the Sourcetree of Atlassian.

A few questions:

1. Why do you want to uninstall it? What are you trying to
accomplish by uninstalling it?
2. What operating system are you using?
3. How did you try to uninstall it?
4. What messages did you get when you tried to uninstall it?
5. How did you install two different 3.x versions?

--
Michael F. Stemper
Indians scattered on dawn's highway bleeding; Ghosts crowd the young child's
fragile eggshell mind.
--
https://mail.python.org/mailman/listinfo/python-list

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


RE: Can't Uninstall !

2018-02-13 Thread Pedro Crescencio
RESOLVED

To answer Jerry, I found solution.

Point 3.
First try: uninstall using Windows 10 interface to uninstall 
Like this 
https://malwaretips.com/blogs/wp-content/uploads/2015/07/Uninstall-Application-from-Windows-10.jpg
Second try: right click over the program bouton on Start Menu
1st option of this link 
https://www.windowscentral.com/how-to-uninstall-apps-windows-10
It send to "Windows 7" like interface menu : 
http://www.uninstalltips.net/wp-content/uploads/2014/04/uninstall-program.png

The second works!
Can not explain why, but it does.
It's good enough. 

Thanks




-Message d'origine-
De : Python-list [mailto:[email protected]] De 
la part de Jerry Hill
Envoyé : mardi 13 février 2018 19:01
À : python-list (General) 
Objet : Re: Can't Uninstall !

On Tue, Feb 13, 2018 at 10:30 AM, Pedro Crescencio 
wrote:

3. How did you try to uninstall it?
> Using Windows standard uninstall procedure
> https://www.windowscentral.com/how-to-uninstall-apps-windows-10
>

​That page describes two different ways of uninstalling programs (from the 
start screen, or from the Apps & Features control panel).  I don't know if it 
matters, but it might help someone to know which one you used.​


> 4. What messages did you get when you tried to uninstall it?
> The message says : "Uninstalled". But I still have the icon over the 
> App list.
>

​You say you have "the" icon.​

​What icon is that? A normal python install should have a bunch of different 
stuff on the start menu -- on the Windows 7 installation ​I have in front of 
me, I have a "Python 3.6" folder, with four different links nested inside - 
"IDLE (Python 3.6 32-bit)", "Python 3.6 (32-bit)", "Python
3.6 Manuals (32-bit)", and "Python 3.6 Module Docs (32-bit)".  What do you have?

​When you installed python, do you remember if you installed it for "All Users" 
or "Just Me"?​

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

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


Re: Character Sequence Generation

2005-09-22 Thread Pedro Werneck
On Thu, 22 Sep 2005 23:26:58 -0400
Jeff Schwab <[EMAIL PROTECTED]> wrote:

> What's the best way to generate a sequence of characters in Python? 
> I'm  looking for something like this Perl code: 'a' .. 'z' .

If you want arbitrary sequences, you may use something like:


>>> [chr(x) for x in xrange(ord('a'), ord('z') + 1)]
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

>>> [chr(x) for x in xrange(ord('d'), ord('p') + 1)]
['d', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p']

>>> [chr(x) for x in xrange(ord('A'), ord('Z') + 1)]
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

etc... 

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


Re: Wrapping classes

2005-09-23 Thread Pedro Werneck

I agree this is a case for using metaclasses. What about an
implementation like this ? Seems like checking if init was already
called will slow down all attribute access significantly, but, I don't
like this approach of changing the __init__ method. 


class LazyInit(type):
def __new__(self, name, bases, dict):

def __getattribute__(self, attr):
attrs = object.__getattribute__(self, "__dict__")
init = attrs["_init"]
if not init:
args = attrs["_args"]
kwds = attrs["_kwds"]
__init__ = object.__getattribute__(self, "__init__")
__init__(*args, **kwds)
attrs["_init"] = True

return object.__getattribute__(self, attr)

dict['__getattribute__'] = __getattribute__
return type.__new__(self, name, bases, dict)

def __call__(cls, *args, **kwds):
o = object.__new__(cls, *args, **kwds)
o._args = args
o._kwds = kwds
o._init = False

return o


And some simple testing:

>>> class Foo:
... __metaclass__ = LazyInit
... def __init__(self, x, y):
... print "init was called", x, y 
... self.x = x
... self.y = y
... 
>>> o = Foo(1, None)
>>> o
<__main__.Foo object at 0x402cc96c>
>>> o.x
init was called 1 None
1
>>> o.y
>>> 


Regards,

Pedro

On Fri, 23 Sep 2005 10:28:42 +0200
Paolino <[EMAIL PROTECTED]> wrote:

> Jeremy Sanders wrote:
> > Is it possible to implement some sort of "lazy" creation of objects
> > only when the object is used, but behaving in the same way as the
> > object?
> > 
> A generic approach would override __getattribute__ to let it perform
> the 
>   __init__ method on not initialized objects.This is a case for using 
> metaclasses as even __init__ method must be overridden ad hoc to 
> register the arguments for the lazy initialization.
> Probably you want to fine-tune the triggering (specifing which
> attribute  should make it happen ),as every look up would trigger.
> 
> class NotInitializedObjects(type):
>def __init__(cls,*_):
>  realInit=cls.__init__
>  def __newInit__(self,*pos,**key):
>def _init():
>  realInit(self,*pos,**key)
>self._init=_init
>  cls.__init__=__newInit__
>  def __getattribute__(self,attr):
>def getter(attr):
>  return object.__getattribute__(self,attr)
>if '_init' in getter('__dict__'):
>  getter('_init')()
>  del self._init
>return getter(attr)
>  cls.__getattribute__=__getattribute__
> 
> 
> if __name__=='__main__':
>class Class:
>  __metaclass__=NotInitializedObjects
>  def __init__(self,*pos,**key):
>self.initialized=True
>print 'initializing with',pos,key
>a=Class('arg',key='key') # a fake initialization
> 
>try:
> object.__getattribute__(a,'initialized')
>except AttributeError: # should raise
> print 'not initialized'
>else:
> raise
>try:
> a.initialized  #every look up would do ,even a print
>except AttributeError:
> raise
>else:
> print 'initialized'
> 
> 
> Have fun Paolino
> 
>   
> 
>   
>   
> ___ 
> Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB 
> http://mail.yahoo.it
> -- 
> http://mail.python.org/mailman/listinfo/python-list


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


Re: TypeError error on tkinter.createfilehandler dummy example

2005-01-21 Thread Pedro Werneck

Hi,

The createfilehandler is not supported on Windows since Tcl/TK 8.0.
tkinter.createfilehandler is None, so you get the NoneType is not
callable error.


I wrote a simple module with a mix-in class to solve this problem. I had
a lote of code using it on linux and needed to run it on Windows. I can
send it to you in pvt, if you want.



Pedro Werneck


On Fri, 21 Jan 2005 10:27:20 +0100
David <[EMAIL PROTECTED]> wrote:

> Hi,
> 
> I'm getting the following error:
> 
> 
> Traceback (most recent call last):
>   File "..\kk.py", line 37, in ?
> tkinter.createfilehandler(filex, tkinter.READABLE, _dispatch)
> TypeError: 'NoneType' object is not callable
> 
> 
> when executing this code on my Windows box:
> 
> 
> from Tkinter import *
> 
> def _dispatch(self, *args):
>   print "voila"
> 
> filex = open('d:\\zz.txt', 'r')
> tkinter.createfilehandler(filex, tkinter.READABLE, _dispatch)
> 
> 
> Any ideas? What am I missing? I've been searching for something like 
> this with no luck. I cannot imagine a simpler code for testing 
> tkinter.createfilehandler functionality but it does not work :(
> 
> 
> TIA
> 
> -- 
> David Santiago
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Asynchronous event handling...?

2005-01-24 Thread Pedro Werneck
Hi,

Maybe something like this...



from Tkinter import *
import itertools

class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.grid()
self.createWidgets()
def createWidgets(self):
self.stop = Button(self,text='Emergency Stop!',command=self.stop)
self.count = Button(self,text='Count',command=self.count)
self.count.grid(row=0,column=0)
self.stop. grid(row=0,column=1)

def count(self):
self._counter = itertools.count()
self._id = self.after(0, self._count)

def _count(self, event=None):
i = self._counter.next()
print i
self.update_idletasks()
self._id = self.after(0, self._count)

def stop(self):
self.after_cancel(self._id)


app = Application()
app.mainloop()


On Mon, 24 Jan 2005 16:52:51 +1100
"Chris Line" <[EMAIL PROTECTED]> wrote:

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


Re: TCP server

2005-01-24 Thread Pedro Werneck

A quick example for you:

###
import SocketServer


class EchoRequestHandler(SocketServer.BaseRequestHandler):
def setup(self):
print self.client_address, 'connected!'
self.request.send('hi ' +  str(self.client_address) + '\n')

def handle(self):
while 1:
data = self.request.recv(1024)
self.request.send(data)
if data.strip() == 'bye':
return

def finish(self):
print self.client_address, 'disconnected!'
self.request.send('bye ' +  str(self.client_address) + '\n')

#server host is a tuple ('host', port)
server = SocketServer.ThreadingTCPServer(('', 5000), EchoRequestHandler)
server.serve_forever()

###

Telnet to localhost 5000 and any data you sent will be echoed back to you... 
send 'bye' and the connection is closed




On 24 Jan 2005 06:25:18 -0800
"assaf" <[EMAIL PROTECTED]> wrote:

> i am try to create a server
> what am i suppose to send to SocketServer.TCPServer
> what is the client_address ("127.0.0.1:80" ?)
> and BaseRequestHandler = ?
> 
> thanks
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tuple slices

2005-01-24 Thread Pedro Werneck
On Mon, 24 Jan 2005 18:45:46 +0100
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote:

> George Sakkis wrote:
> 
> > Why does slicing a tuple returns a new tuple instead of a view of
> > the existing one, given that tuples are immutable ?
> 
> really?

Well... seems like this case is optimized to return the original tuple
just incrementing its reference count and returning

tupleobject.c, 330-335

if (ilow == 0 && ihigh == a->ob_size && PyTuple_CheckExact(a)) {
Py_INCREF(a);
return (PyObject *)a;
}


> 
> >>> a = 1, 2, 3
> >>> b = a[:]
> >>> a is b
> True
> 
>  
> 
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tuple slices

2005-01-24 Thread Pedro Werneck
On Mon, 24 Jan 2005 18:45:46 +0100
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote:

> George Sakkis wrote:
> 
> > Why does slicing a tuple returns a new tuple instead of a view of
> > the existing one, given that tuples are immutable ?
> 
> really?


Well... seems like this case (slicing the whole tuple) is optimized to
return the original tuple just incrementing its reference count and returning


tupleobject.c, 330-335

if (ilow == 0 && ihigh == a->ob_size && PyTuple_CheckExact(a)) {
Py_INCREF(a);
return (PyObject *)a;
}


> 
> >>> a = 1, 2, 3
> >>> b = a[:]
> >>> a is b
> True
> 
>  
> 
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter socket client ?

2005-01-27 Thread Pedro Werneck
On Tue, 25 Jan 2005 13:44:32 +
Martin Franklin <[EMAIL PROTECTED]> wrote:

> > thanks for this info - I had to abandon the createfilehandler() method
> > as it is not supported in windows and the GUI "might" be used there at
> > some time ...

Take a look here: 
http://www.pythonbrasil.com.br/moin.cgi/MonitorandoSocketsComTkinter

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


Re: type() takes one or *three* arguments!?

2005-01-30 Thread Pedro Werneck
Hi,

Up to Python 2.2, type() was just a function to return an object type.
>From 2.2 on, type have this behavior when called with only one argument
and is used to create a new type when called with 3 arguments.


>From http://www.python.org/2.2/descrintro.html :

"The signature of type() requires an explanation: traditionally, type(x)
returns the type of object x, and this usage is still supported.
However, type(name, bases, methods) is a new usage that creates a brand
new type object. (This gets into metaclass programming, and I won't go
into this further here except to note that this signature is the same as
that used by the Don Beaudry hook of metaclass fame.)"



So, an example:

Foo = type('Foo', (object,), {})

and...

class Foo(object):
   pass

Are the same thing... 




On 30 Jan 2005 11:57:23 -0800
[EMAIL PROTECTED] wrote:

> I was looking at Simon Burton's Povray.py code (part of pypov) and saw
> this line:
> globals()[name] = type( name, (KWItem,), {} ) # nifty :)
> 
> where 'KWItem' was a class. It did seem nifty, but it was unclear to
> me what was happening.
> 
> I went to python.org's online documentation which said that type()
> takes one argument. So I fired up python:
> >>> type(42)
> 
> >>> type("x", (type(42),), {})
> 
> 
> OK, It appears that type() with 3 arguments constructs a class. Is
> this documented somewhere? If not can someone explain what is going
> on? james
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how do i create such a thing?

2005-01-30 Thread Pedro Werneck
Hi,

If you need direct access to some atribute, use object.__getattribute__.


>>> class DefaultAttr(object):
... def __init__(self,  default):
... self.default = default
... def __getattribute__(self, name):
... try:
... value = object.__getattribute__(self, name)
... except AttributeError:
... value = self.default
... return value
... 
>>> x = DefaultAttr(99)
>>> 
>>> print x.a
99
>>> x.a = 10
>>> print x.a
10
>>> 



On Sun, 30 Jan 2005 13:54:38 -0800
Lowell Kirsh <[EMAIL PROTECTED]> wrote:

> I want to create a class called DefaultAttr which returns a default 
> value for all attributes which haven't been given values yet. It will 
> work like this:
> 
>  >> x = DefaultAttr(99)
>  >> print x.foo
> 99
>  >> print x.bar
> 99
>  >> x.foo = 7
>  >> print x.foo
> 7
> 
> I already have a similar class called DefaultDict which works
> similarly  which I assume would be a good thing to use.
> 
> Lowell
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is this sort method the same as the one in python 2.4

2005-01-30 Thread Pedro Werneck

What about this ?


#
if sys.version_info >= (2,4):
def sorted(iterable, *args, **kwds):
seq = list(iterable)
seq.sort(*args, **kwds)
return seq
#

It worked against the TestSorted in lib/test/test_builtins.py





On Sun, 30 Jan 2005 08:30:17 +0100
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote:

> Raymond Hettinger wrote:
> 
> >> I'm trying to emulate the sorted() method introduced in python 2.4. The
> >> only difference is that it takes a sequence as one of its arguments
> >> rather than being a method of the sequence class. Does my method do the
> >> same as the sorted()?
> >
> > Almost.  This is closer to the mark:
> >
> > def sorted(iterable, cmp=None, key=None, reverse=False):
> >"return a sorted copy of its input"
> >if sys.version_info >= (2,4):
> >return sorted(iterable, cmp, key, reverse)
> 
> with your code
> 
> print sorted([1, 2, 3])
> 
> gives me a traceback that ends with
> 
>   File "test.py", line 6, in sorted
> return sorted(iterable, cmp, key, reverse)
>   File "test.py", line 6, in sorted
> return sorted(iterable, cmp, key, reverse)
>   File "test.py", line 6, in sorted
> return sorted(iterable, cmp, key, reverse)
>   File "test.py", line 5, in sorted
> if sys.version_info >= (2,4):
> RuntimeError: maximum recursion depth exceeded in cmp
> 
> the recursion isn't really that hard to explain, but the runtime error doesn't
> really seem right...
> 
> :::
> 
> to fix the recursion, move the if-statement so you only define the function
> if needed:
> 
>  if sys.version_info < (2,4):
> def sorted(...):
> 
> 
>  
> 
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trouble converting hex to decimal?

2005-02-05 Thread Pedro Werneck
Hi

The problem is that '\x00' is a escape sequence... 

Try something like this:


>>> x = '\x00'
>>> int(repr(x)[3:-1], 16)
0
>>> x = '\x15'
>>> int(repr(x)[3:-1], 16)
21
>>> 



On Sat, 05 Feb 2005 06:51:32 -0700
Earl Eiland <[EMAIL PROTECTED]> wrote:

> I'm trying to process the IP packet length field, as recorded by pcap
> (Ethereal) and recovered using pcapy.  When I slice out those bytes, I
> get a value that shows in '\x00' format, rather than '0x00'.  Neither
> int() nor eval() are working.  How do I handle this?
> 
> Earl Eiland
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Supporting << and >> operators in C extension type

2005-07-27 Thread Pedro Werneck

Hi list


I'm trying to implement a new type in a C extension and it must support
some binary operators, like &, |, ^, << and >>. With &, | and ^, the
method must receive another object of the same type, perform the
operation with an attribute of both, create a new object with the result
as the attribute and return it. 

Everything works perfectly with &, | and ^, but with << and >> I need
to, pass an integer as argument, not an object of the same type. The
method should receive an integer, perform the shift with the attribute,
create the new object and return it. The problem is that it only works
with another object of the same type.

It's strange because obj.__lshift__ returns the method; when I call
obj.__lshift__(a) or obj << a, when a is an object of the same type, the
call suceeds (but the object returned has the wrong value, of course),
but with obj.__lshift__(i) where i is an integer, the call returns
NotImplemented and with obj << i it raises TypeError: unsupported
operand types for <<.

I searched the Objects/ directory in the interpreter source code, but
could not find any solution for this. Seems like it does some kind of
type-checking somewhere when using these binary operators. Do I need to
implement the __coerce__ method or use some wrapper with the method
function ?

Here is the relevant piece of my source code:

The __lshift__ method:

/* Pin.__lshift__() */
static PyObject *
Pin_oplshift(PinObject *self, PyObject *args){

  PinObject *result;
  int shift;

  if (!PyArg_ParseTuple(args, "i", &shift))
   return NULL;

  result = PyObject_NEW(PinObject, &PinType);
  result->pin = self->pin << shift;

  Py_INCREF(result);
  return (PyObject *) result;
};

The part of the PyNumberMethods struct:

/* Pin number methods */
static PyNumberMethods PinAsNumber[] = {
...

  (inquiry)Pin_nonzero,  /*nb_nonzero*/
  0, /*nb_invert*/
  (binaryfunc)Pin_oplshift,  /*nb_lshift*/
  (binaryfunc)Pin_oprshift,  /*nb_rshift*/
  (binaryfunc)Pin_and,   /*nb_and*/
  (binaryfunc)Pin_xor,   /*nb_xor*/
  (binaryfunc)Pin_or,    /*nb_or*/
  0, /*nb_coerce*/

...
};


Thanks for any help...

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


Possible bug in "metaclass resolution order" ?

2005-09-16 Thread Pedro Werneck

Hi

I have a class A, with metaclass M_A, and class B, subclass of A, with
metaclass M_B, subclass of M_A.

A class C, subclass of B must have M_B or a subclass of it as metaclass,
but what if I need to 'disable' the code in M_B on C ? The correct way
to do that seems to be with a M_C metaclass, subclass of M_B,
implementing but not calling parent class methods, or calling 'type'
methods. 

But if I try to do that using other metaclass, not related to M_B, I get a
"TypeError: metaclass conflict exception" as expected.

Python 2.4.1 (#1, Sep 16 2005, 17:47:47) 
[GCC 3.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class M_A(type): pass
... 
>>> class A: __metaclass__ = M_A
... 
>>> class M_B(M_A): pass
... 
>>> class B(A): __metaclass__ = M_B
... 
>>> class M_C(type): pass
... 
>>> class C(B): __metaclass__ = M_C
... 
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: Error when calling the metaclass bases
metaclass conflict: the metaclass of a derived class must be a
(non-strict) subclass of the metaclasses of all its bases
>>>


The problem is, if I try to do the same thing with 'type' the
interpreter use M_B and I don't get an exception, warning or anything
else. In fact, the __metaclass__ attribute of the C class points to
'type' but the __class__ to M_B!

>>> class C(B): __metaclass__ = type
... 
>>> C.__metaclass__

>>> C.__class__

>>> type(C)



Since the explicit __metaclass__ attribute has priority over parent
classes, a case like this is an error and should raise an exception like
the metaclass conflict, right ?

Regards,

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


Re: Possible bug in "metaclass resolution order" ?

2005-09-17 Thread Pedro Werneck
On 17 Sep 2005 02:04:39 -0700
"Simon Percivall" <[EMAIL PROTECTED]> wrote:

> Have you read the "Metaclasses" part of "Unifying types and classes in
> Python 2.2"? (http://www.python.org/2.2.3/descrintro.html#metaclasses)

Yes, I read. Have you read and understood my message ? :)

A class B, subclass of class A, with a metaclass M_A should have M_A or
a subclass of it as metaclass. If you try with anything else, you get a
TypeError exception as expected. OK. But if you try with 'type', nothing
happens. 

Python 2.4.1 (#1, Sep 16 2005, 17:47:47) 
[GCC 3.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class M_A(type): pass
... 
>>> class A: __metaclass__ = M_A
... 
>>> class B(A): __metaclass__ = type
... 
>>> B.__class__

>>> B.__metaclass__



Regards,

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


Re: Possible bug in "metaclass resolution order" ?

2005-09-17 Thread Pedro Werneck
On 17 Sep 2005 08:51:50 -0700
"Michele Simionato" <[EMAIL PROTECTED]> wrote:

Hi

> I think this is more of a documentation issue than of a bug.

No... I don't think it's a documentation issue. What's the problem with
the documentation in this case ? Trying to use 'type' as a metaclass
with a subclass of another class using a custom metaclass is an error
and should raise the same exception the metaclass conflict does. In
fact, is the same error.

> It may seems strange at first, but __metaclass__ and __class__ may be
> different.
> 
> For instance, if M is metaclass
> 
> >>> class C(object): pass
> 
> >>> C.__metaclass__ = M
> 
> you get a class with metaclass hook equal to M, but C.__class__ is
> still 'type'.

But in this case, it's a __metaclass__ attribute defined after class
creation, after the call to the metaclass found in object.__class__, not
dict["__metaclass__"] which have priority over object.__class__. The
interpreter is not aware of this __metaclass__ attribute during class
creation, since it's not in the dict passed on the type(name, bases,
dict) call.

> In you example, setting the __metaclass__ to 'type' does not change
> the metaclass of the created class, which is inherited from the base
> class. 

Yes, but, as I said, dict["__metaclass__"] has priority over the base
class __class__. If I use a metaclass which is not a subclass of my base
classes metaclass I get a TypeError: metaclass conflict exception. If I
use 'type' which is also not a subclass of my base classes metaclass, I
was supposed to get the same exception, but the interpreter ignores
dict["__metaclass__"] and use the metaclass in base class __class__. 

Seems like the problem is in Objects/typeobject.c, PyType_IsSubtype
(814-846) or the for loop in 1604-1621. Seems like PyType_IsSubtype is
returning true for a type being a subtype of it's own subtypes and it
never reaches the exception and return NULL. The problem seems to be the
third if statement and after it, when the winner and metatype are
exchanged if different.

It's more evident using 'type' because it's the base of all types, but
after looking the source code, I tested with this code:

Python 2.4.1 (#1, Sep 16 2005, 17:47:47) 
[GCC 3.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
c>>> class M_A(type): pass
... 
>>> class A: __metaclass__ = M_A
... 
>>> class M_B(M_A): pass
... 
>>> class B(A): __metaclass__ = M_B
... 
>>> class C(B): __metaclass__ = M_A
... 
>>> C.__class__

>>> C.__metaclass__

>>> 

Is this supposed to happen ? C's metaclass must be a subclass of M_B. If
I try with any other class not related to this hierarchy, I will get a
metaclass conflict error. But with M_A, the error is ignored, probably
because PyType_IsSubtype is returning 1 for M_A being a subtype of M_B
and the winner and metatype are exchanged later, so we end with M_B as
C's real type.


> I suggest you to file a documentation bug. Unfortunately the basic
> documentation about metaclasses is a bit lacking and you have to
> discover many things by trial and errors.

I still think this is a bug, not a documentation issue. 

Regards

-- 
Pedro Werneck

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


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


Re: Possible bug in "metaclass resolution order" ?

2005-09-17 Thread Pedro Werneck
On Sat, 17 Sep 2005 15:07:01 -0400
"Terry Reedy" <[EMAIL PROTECTED]> wrote:

> If, after any further responses, you still think you have discovered a
> bug, do file a report on SourceForge.  

Thanks... report id 1294232, Error in metaclass search order

http://sourceforge.net/tracker/index.php?func=detail&aid=1294232&group_id=5470&atid=105470


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


Re: Possible bug in "metaclass resolution order" ?

2005-09-18 Thread Pedro Werneck
On 18 Sep 2005 00:39:31 -0700
"Michele Simionato" <[EMAIL PROTECTED]> wrote:

> Remember that given a class C, its metaclass is given by C.__class__,
> not by > C.__metaclass__, despite the name.

Of course. Seems you think I'm arguing that C.__class__ and
__metaclass__ should always be the same. The metaclass is given by
C.__class__ after class creation. At the end of the 'class' statement,
searching for the 'winner' metatype, dict["__metaclass__"] is supposed
to have priority over B.__class__, and this over global __metaclass__.
Not only this is the behavior documented on GvR essay but is on the
source code I mentioned too.

> You argue that in this case an error should be raised, since "errors
> should never pass silently". May be. 

Exactly... and the behaviour is inconsistent. I get an exception when
the metaclass is not related to the M_A-M_B hierarchy, like X below, and
the same error was supposed to be raised when using M_A or type, which
do not follow the same rule of being a "subclass of the metaclasses of
all its bases". In fact, I lost a lot of time trying to find an error
related to this in my code a few weeks ago.

>>> class X(type): pass
... 
>>> class C(B): __metaclass__ = X
... 
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: Error when calling the metaclass bases
metaclass conflict: the metaclass of a derived class must be a
(non-strict) subclass of the metaclasses of all its bases
>>> class C(B): __metaclass__ = M_A
... 
>>> C.__metaclass__

>>> C.__class__


> You are free to post the bug report and look at the opinions of the
> developers. 

I posted a few hours ago. 

Thank you.

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


Re: Possible bug in "metaclass resolution order" ?

2005-09-18 Thread Pedro Werneck
On 18 Sep 2005 10:33:11 -0700
"Simon Percivall" <[EMAIL PROTECTED]> wrote:

> Isn't that exactly what you are doing?

Yes, and that example has the same inconsistency. 

>>> class X(type): pass
... 
>>> class D2(C3, C2): __metaclass__ = X
... 
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: Error when calling the metaclass bases

For class D2, the explicit metaclass X is not a subclass of the base
metaclasses, just like M1 with D in the example, but with X you get a
metaclass conflict error, and with M1 doesn't. Choosing M3 satisfies the
constraint, but why it is choosen when you use M1 but not with X ?

That's exactly my point. If I wanted M3 or M2, I would be using an
explicit dict['__metaclass__'] = M3 or M2. Since I am trying to do it
with M1, which does not satisfy the constraint, it is an error, and
according to Python design concepts it was supposed to raise the same
exception. 

I don't know if it was a deliberate decision to go silently for the base
class metaclass if the explicit metaclass does not satisfy the
constraint but is a base class of any of the base classes metaclass, but
if it was, the same should happen when the explicit metaclass has no
relation to the base classes metaclass, which seems a very strange
design decision, and not only from Python "explicity and simplicity"
standpoint.

If this is really not an error, just a documentation issue like Mr.
Simionato argues, the first rule for determining M a few lines above
your quote is much more complex and should be changed from:

* if dict['__metaclass__'] exists, it is used.

to something more like:

* if dict['__metaclass__'] exists and is equal to, or a subclass of,
each of the metaclasses of the bases, it is used; if it exists and is a
base class of any of the metaclasses of the bases, the first base class
metaclass is used. If it exists and doesn't satisfies any of these
constraints, TypeError is raised.

If I am right and this is a bug, althought I am not very familiar with
Python internals my speculations on what may be wrong are on the bug
report I filled yesterday. If it's not a bug and this was the intended
behaviour, I think it's not consistent with Python design concepts,
especially "errors should never pass silently" and "explicit is better
than implicit". If it's just a documentation issue, the first rule in
search order is much more complex than documented. If I am completely
wrong in all of this, maybe it's better stop wasting our time. :)


Thank you

-- 
Pedro Werneck

http://sourceforge.net/tracker/index.php?func=detail&aid=1294232&group_id=5470&atid=105470
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Possible bug in "metaclass resolution order" ?

2005-09-18 Thread Pedro Werneck
On 18 Sep 2005 12:58:22 -0700
"Simon Percivall" <[EMAIL PROTECTED]> wrote:

> I definitely think that it's the intended behaviour: the example shows
> how and why it works; and I definitely agree that it should be
> documented better.

Yes. I finally understood the decision and now I agree it's not a bug,
it's the intended behaviour. If the explicit class is part of the
hierarchy but not a subclass of base classes metaclass, it will search
for the more specialized metaclass and use it, since it will have
anything the class need and conforms to the metaclass I set explicitly.

I will change the bug report and add some of the suggested
documentation.

Thanks
-- 
Pedro Werneck
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Possible bug in "metaclass resolution order" ?

2005-09-19 Thread Pedro Werneck
On Mon, 19 Sep 2005 05:22:09 GMT
[EMAIL PROTECTED] (Bengt Richter) wrote:

> 
> And the something returned, whatever it is, if no checking is
> triggered by normal use, gets bound to the class name, e.g.,

Yes... this is the intended behaviour. In fact, the issue is already
solved and is really just a documentation problem.

Check the comments on the bug report here:

http://sourceforge.net/tracker/index.php?func=detail&aid=1294232&group_id=5470&atid=105470

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


Re: the Gravity of Python 2

2014-01-08 Thread Pedro Larroy
I think for new projects one should go with 3.x this is the right thing to
do. If you require a module that's 2.x only it's easy enough to port it
unless it depends on some monster like protobuf which doesn't have
python3.x support


Pedro.


On Wed, Jan 8, 2014 at 3:30 PM, Mark Lawrence wrote:

> On 08/01/2014 14:15, Roy Smith wrote:
>
>> As somebody who is still firmly in the 2.x world, I'm worried about the
>> idea of a 2.x fork.  While I have my doubts that 3.x was a good idea,
>> the fact is, it's here.  Having the community fractured between the two
>> camps is not good.  Let's say I'm somebody who wants to contribute some
>> OSS.  I have three basic choices:
>>
>> 1) I can make it 3.x only.  Now, (nominally) half of the python
>> community is unable to realize value from my contribution.
>>
>> 2) I can make it 2.x only.  Same thing in reverse.
>>
>> 3) I can make it work on both 2.x and 3.x, which means I'm investing
>> more effort than I had to if it were single platform.
>>
>> Any of those alternatives is worse than ideal.  Forking 2.x to create an
>> unofficial 2.8 release would just prolong the situation.  As I've stated
>> before, I don't see any urgency in moving to 3.x, and don't imagine
>> doing there for another couple of years, but I absolutely can't imagine
>> moving to a 2.8 fork.
>>
>>
> The above strikes me as common sense.  Surely that's out of place on this
> list? :)
>
> But to be serious why not stick with 2.x if there's no compelling reason
> to move?  Whatever happened to "if it ain't broke, don't fix it"?  And
> before anyone says anything please don't start on about the bytes versus
> string debate, I'm fairly certain that there are a substantial number of
> application areas that don't run into these problems.
>
>
> --
> My fellow Pythonistas, ask not what our language can do for you, ask what
> you can do for our language.
>
> Mark Lawrence
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: reading from a txt file

2015-11-26 Thread Pedro Vincenty
All were really helpful thanks a lot.  Now I'm interested in identifying a 
particular index after being able to print out each word.  Printing each word 
to the console I have : 

['METEOSAT-7']
['1', '24932U', '97049B', '15319.57839525', '.0058', '0-0', '0+0', 
'0', '9994']
['2', '24932', '9.9015', '42.7484', '0001500', '224.8381', '52.7416', 
'1.00266716', '66645']

It seems awkward because I was expecting to have brackets only outside of all 
the words.  I would like to identify one of these words.  Thanks again!
-- 
https://mail.python.org/mailman/listinfo/python-list


appending a line to a list based off of a string found in a previous list

2015-12-12 Thread Pedro Vincenty
Hello, I'm wondering how to append a line from a file onto a list(easy part) 
provided that the line contains strings specific to a previous list I've 
already made(hard part).  I have this right now, 
for line in satellite_dataread:
if any(i in line for i in list2):
line= line.strip()
satellite, country= line.split(',')
satellite_origin_list.append(country)

the statement if statement seems to work as I take it out of the for loop, but 
not as I have it presented. Thanks a bunch!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: appending a line to a list based off of a string found in a previous list

2015-12-12 Thread Pedro Vincenty
On Saturday, December 12, 2015 at 4:48:46 PM UTC-5, Pedro Vincenty wrote:
> Hello, I'm wondering how to append a line from a file onto a list(easy part) 
> provided that the line contains strings specific to a previous list I've 
> already made(hard part).  I have this right now, 
> for line in satellite_dataread:
> if any(i in line for i in list2):
> line= line.strip()
> satellite, country= line.split(',')
> satellite_origin_list.append(country)
> 
> the statement if statement seems to work as I take it out of the for loop, 
> but not as I have it presented. Thanks a bunch!!
I was able to get it it you guys were right.  Thanks a bunch!
-- 
https://mail.python.org/mailman/listinfo/python-list


pickle.dump (obj, conn)

2014-03-13 Thread Pedro Izecksohn
  Shouldn't pickle.dump (obj, conn) raise an Exception if conn is a TCP 
connection that was closed by the remote host?
-- 
https://mail.python.org/mailman/listinfo/python-list


Proposal of an API to deal with fingerprints on Python

2014-05-29 Thread Pedro Izecksohn
  Today I wrote the following API. It was not implemented on C yet. Do you have 
any comment? Could you help me to implement it?

http://www.izecksohn.com/pedro/python/fingerprint/fingerprint.001.py

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


Lines on a tkinter.Canvas

2014-06-11 Thread Pedro Izecksohn
  The code available from:
http://izecksohn.com/pedro/python/canvas/testing.py
  draws 2 horizontal lines on a Canvas. Why the 2 lines differ on thickness and 
length?

  The Canvas' method create_line turns on at least 2 pixels. But I want to turn 
on many single pixels on a Canvas. How should I do this? Canvas has no method 
create_pixel or create_point.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Lines on a tkinter.Canvas

2014-06-12 Thread Pedro Izecksohn
  As Peter Otten did not see the same result that I saw, I prepared an image 
that shows the result on my notebook:
http://izecksohn.com/pedro/python/canvas/tk_window.xcf
  For those that might not know: xcf is the Gimp's file format.


- Original Message -
> From: Peter Otten
> To: [email protected]
> Sent: Thursday, June 12, 2014 4:02 AM
> Subject: Re: Lines on a tkinter.Canvas
> 
> Pedro Izecksohn wrote:
> 
>>  The code available from:
>>  http://izecksohn.com/pedro/python/canvas/testing.py
>>  draws 2 horizontal lines on a Canvas. Why the 2 lines differ on thickness
>>  and length?
>> 
>>  The Canvas' method create_line turns on at least 2 pixels. But I want 
> to
>>  turn on many single pixels on a Canvas. How should I do this? Canvas has
>>  no method create_pixel or create_point.
> 
>>  #!/usr/bin/python3
>> 
>>  import tkinter as tk
>> 
>>  class Point ():
>>    def __init__ (self, x, y):
>>      self.x = x
>>      self.y = y
>> 
>>  class Board (tk.Frame):
>>    def __init__ (self, bg, dimensions):
>>      tk.Frame.__init__ (self, tk.Tk())
>>      self.pack()
>>      self.canvas = tk.Canvas (self, bd = 0, bg = bg, width = dimensions.x, 
> height = dimensions.y)
>>      self.canvas.pack (side = "top")
>>    def drawLine (self, pa, pb, color):
>>      self.canvas.create_line (pa.x, pa.y, pb.x, pb.y, fill = color)
>>    def drawPoint (self, p, color):
>>      self.canvas.create_line (p.x, p.y, p.x, p.y, fill = color)
>> 
>>  dimensions = Point (500, 500)
>>  board = Board ('black', dimensions)
>>  color = 'red'
>>  p = Point (0, 250)
>>  while (p.x < dimensions.x):
>>    board.drawPoint (p, color)
>>    p.x += 1
>>  pa = Point (0, 350)
>>  pb = Point (499, 350)
>>  board.drawLine (pa, pb, color)
>>  board.mainloop()
> 
> I just tried your script, and over here the line drawn with
> 
>>    def drawLine (self, pa, pb, color):
>>      self.canvas.create_line (pa.x, pa.y, pb.x, pb.y, fill = color)
> 
> has a width of 1 pixel and does not include the end point. Therefore the 
> "line" drawn with
> 
>>    def drawPoint (self, p, color):
>>      self.canvas.create_line (p.x, p.y, p.x, p.y, fill = color)
> 
> does not show up at all. You could try to specify the line width explicitly:
> 
>    def drawPoint (self, p, color):
>      self.canvas.create_line (p.x, p.y, p.x+1, p.y, fill=color, width=1)
> 
> If that doesn't work (or there's too much overhead) use pillow to 
> prepare an 
> image and show that.
> 
> Another random idea: if you have a high resolution display your OS might 
> blow up everything. In that case there would be no fix on the application 
> level.
> 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Lines on a tkinter.Canvas

2014-06-12 Thread Pedro Izecksohn
- Original Message -

> From: Gregory Ewing
> To: [email protected]
> Sent: Thursday, June 12, 2014 8:38 AM
> Subject: Re: Lines on a tkinter.Canvas
> 
> Pedro Izecksohn wrote:
>>  The Canvas' method create_line turns on at least 2 pixels. But I want 
> to turn
>>  on many single pixels on a Canvas.
> 
> You could try using a 1x1 rectangle instead.

pedro@microboard:~/programming/python/tk/canvas$ diff old/testing.001.py 
testing.py
19c19
< self.canvas.create_line (p.x, p.y, p.x, p.y, fill = color)
---
> self.canvas.create_rectangle (p.x, p.y, p.x, p.y, fill = color)

  The result that I got is: The line drawn by it is not shown.

> However, be aware that either of these will use quite a
> lot of memory per pixel. If you are drawing a very large
> number of pixels, this could cause performance problems.
> In that case, you might want to use a different approach,
> such as creating an image and telling the canvas to display
> the image.

  I did not try this yet.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Lines on a tkinter.Canvas

2014-06-12 Thread Pedro Izecksohn
- Original Message -

> From: Gregory Ewing
> To: [email protected]
> Cc: 
> Sent: Thursday, June 12, 2014 8:38 AM
> Subject: Re: Lines on a tkinter.Canvas
> 
> Pedro Izecksohn wrote:
>>  The Canvas' method create_line turns on at least 2 pixels. But I want 
> to turn
>>  on many single pixels on a Canvas.
> 
> You could try using a 1x1 rectangle instead.
> 
> However, be aware that either of these will use quite a
> lot of memory per pixel. If you are drawing a very large
> number of pixels, this could cause performance problems.
> In that case, you might want to use a different approach,
> such as creating an image and telling the canvas to display
> the image.

  Thank you Greg. Your second approach works and the script became:

#!/usr/bin/python3

import tkinter as tk

BITMAP = '''
#define im_width 1
#define im_height 1
static char im_bits[] = {
0xff
};
'''

class Point ():
  def __init__ (self, x, y):
    self.x = x
    self.y = y

class Board (tk.Frame):
  def __init__ (self, bg, dimensions):
    tk.Frame.__init__ (self, tk.Tk())
    self.pack()
    self.canvas = tk.Canvas (self, bd = 0, bg = bg, width = dimensions.x, 
height = dimensions.y)
    self.canvas.pack (side = "top")
    self.objects_drawn = []
  def drawLine (self, pa, pb, color):
    self.canvas.create_line (pa.x, pa.y, pb.x, pb.y, fill = color)
  def drawPoint (self, p, color):
    bitmap = tk.BitmapImage (data=BITMAP, foreground = color)
    self.objects_drawn.append (bitmap)
    self.canvas.create_image (p.x, p.y, image = bitmap)

dimensions = Point (500, 500)
board = Board ('black', dimensions)
color = 'red'
p = Point (0, 250)
while (p.x < dimensions.x):
  board.drawPoint (p, color)
  p.x += 1
pa = Point (0, 350)
pb = Point (499, 350)
board.drawLine (pa, pb, color)
board.mainloop()
-- 
https://mail.python.org/mailman/listinfo/python-list


1-0.95

2014-07-01 Thread Pedro Izecksohn
pedro@microboard:~$ /usr/bin/python3
Python 3.3.2+ (default, Feb 28 2014, 00:52:16) 
[GCC 4.8.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1-0.95
0.050044
>>> 

  How to get 0.05 as result?

  bc has scale=2 . Has Python some similar feature?

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


Class attributes, instances and metaclass __getattribute__

2006-08-07 Thread Pedro Werneck

Hi all


I noticed something strange here while explaining decorators to someone.
Not any real use code, but I think it's worth mentioning. 

When I access a class attribute, on a class with a custom metaclass with
a __getattribute__ method, the method is used when acessing some
attribute directly with the class object, but not when you do it from
the instance.


>>> class M(type):
... def __getattribute__(cls, attr):
... print cls, attr
... return type.__getattribute__(cls, attr)
... 
>>> class C(object):
... __metaclass__ = M
... 
>>> C.x = 'foo'
>>> C.x
 x
'foo'
>>> o = C()
>>> o.x
'foo'
>>> 



Someone at freenode #python channel involved with python-dev sprint
suggested it might be a bug, worth mentioning... to me it seems like a
decision to avoid some problems with method and descriptors creation,
since someone using metaclasses and custom __getattribute__ at the same
time is asking for trouble, but... I googled for it and tried to find
something on the list but, nothing. From the source it seems like a
generic wrapper is used. What's the real case here ? 


Regards,

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


Re: singleton decorator

2006-08-07 Thread Pedro Werneck
On Tue, 8 Aug 2006 01:33:31 +0200
"Andre Meyer" <[EMAIL PROTECTED]> wrote:

> 
> Am I missing something here? What is the preferred pythonic way of
> implementing singleton elegantly?

I think the most "elegant" is with a metaclass, since I feel like a
singleton is not just an ordinary type (and __init__ must be called only
once)... but, as "practicality beats purity", the most pythonic way is
probably using the __new__ method and inheritance.

Something like this:

>>> class Singleton(object):
... def __new__(cls, *args, **kwds):
... try:
... return cls._it
... except AttributeError:
... cls._it = object.__new__(cls, *args, **kwds)
... return cls._it
... 
>>> class A(Singleton):
... pass
...
>>> x = A()
>>> y = A()
>>> x is y
True

But __init__ will be called once for each time you call A, even if it's
always the same instance returned. If this is a problem, you'll need
another method to use for initialization and call it only once.

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


Re: Class attributes, instances and metaclass __getattribute__

2006-08-08 Thread Pedro Werneck

Hi

On 8 Aug 2006 00:10:39 -0700
"Michele Simionato" <[EMAIL PROTECTED]> wrote:

> To me, it seems consistent. As said in
> http://www-128.ibm.com/developerworks/linux/library/l-pymeta2/
> 
> """The availability of metaclass attributes is not transitive; in
> other words, the attributes of a metaclass are available to its
> instances, but not to the instances of the instances. Just this is the
> main difference between metaclasses and superclasses."""


Well... I'm not talking about metaclass attributes... that's perfectly
consistent, agreed.

I'm saying that when the class implements a custom __getattribute__,
when you try to access the instance attributes from itself, it uses it.
But if the class is a metaclass, instances of its instances have acess
to the attribute anyway, but don't use the custom __getattribute__ you
implemented. 

Like the example I mentioned on the previous mail, or (I think in this
case it's more obvious):

>>> class N(type):
... def __getattribute__(cls, attr):
... print 'using N.__getattribute for "%s"'%(attr)
... return type.__getattribute__(cls, attr)
... 
>>> class M(type):
... __metaclass__ = N
... 
>>> class C(object):
... __metaclass__ = M
... 
>>> M.x = 'foo'
>>> M.x
using N.__getattribute for "x"
'foo'
>>> C.x
'foo'


So, in both cases I have access to the class attribute; but in one case
it's using the bound M.__getattribute__ implemented at the base
metaclass, but not in the other. It was supposed to use it after the
bound 'C.__getattribute__' raises AttributeError as expected, but it
doesn't...

It's inconsistent, but seems a reasonable decision to me since someone
can easily mess with descriptors doing with this... but, someone else
involved with Python dev I talked about thinks it may be a bug.

And, I'm curious anyway... is it possible to customize attribute access
in this case in any other way ? What really happens here ?

>From the typeobject.c source code, seems like when the metaclass
implements __getattribute__, it uses type.__getattribute__ in this case,
but I'm not sure.


> Since this happens for real attributes, it looks natural that the same
> should happen for 'virtual' attributes implemented via '__getattr__'
> or '__getattribute__'.

Well... as I think it's clear now, the case you mentioned is not exactly
what I'm talking about, but it's good you mentioned about 'virtual'
attributes, because in this case we have another problem, it's
inconsistent too and there's no reason for it...

>>> class M(type):
... def __getattr__(cls, attr):
... if attr == 'x':
... return 'foo'
... 
>>> class C(object):
... __metaclass__ = M
... 
>>> C.y = 'bar'
>>> C.x
'foo'
>>> C.y
'bar'
>>> o = C()

>>> o.x 
...
AttributeError: 'C' object has no attribute 'x'
>>> o.y
'bar'
>>> 

So... both 'x' and 'y' are class attributes, but 'x' is a virtual
attribute implemented with M.__getattr__. From the instance I have
access to 'y' but not to 'x'.



Regards,

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


Re: Class attributes, instances and metaclass __getattribute__

2006-08-08 Thread Pedro Werneck
On 8 Aug 2006 07:24:54 -0700
"Ziga Seilnacht" <[EMAIL PROTECTED]> wrote:

> [snip]
> > Well... I'm not talking about metaclass attributes... that's
> > perfectly consistent, agreed.
> >
> > I'm saying that when the class implements a custom __getattribute__,
> > when you try to access the instance attributes from itself, it uses
> > it. But if the class is a metaclass, instances of its instances have
> > acess to the attribute anyway, but don't use the custom
> > __getattribute__ you implemented.
> 
> Attribute lookup for instances of a class never calls metaclass'
> __getattribute__() method. This method is called only when you
> access attributes directly on the class.

Well... thanks for the answer. 

As I said on the first mail, I noticed this when I was explaining
descriptors and methods to someone else... I implemented a pure-python
Method class to show him exactly how it works. 

But, since their __get__ call is available at the class too, my first
thought was that it was implemented at the metaclass __getattribute__,
and when an instance tries to get a class attribute it would fail on its
own __getattribute__, use the bound method at its class and make the
call. 

After implementing a test metaclass I noticed it doesn't work this way,
and even if it's a bit inconsistent (especially in the case of 'virtual'
attributes), it seemed to me the reasonable thing to do, exactly for
what you mentioned on your code... someone could easily break a lot of
stuff doing it the wrong way, instead if not using __dict__.

I mailed the list because someone else thought it might be a bug and I
was in doubt... now it's clear it was the right thing to do.


Regards,

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


Re: singleton decorator

2006-08-09 Thread Pedro Werneck
On Tue, 08 Aug 2006 14:50:39 +0200
Wildemar Wildenburger <[EMAIL PROTECTED]> wrote:

> Or you could always just use the __new__() method instead of
> __init__(),  putting all your initialization into the above
> except-block. If you  replace 'cls._it = ...' with 'self = cls_it =
> ...' you'll feel right at  home too :).
> 
> Anything 'unpythonic' (gosh how I hate that word ;)) about that, BTW?

Yes. :)

You'll have to make a custom Singleton class for each subclass you want
to make a singleton, instead of just creating a custom _init method for
each one of them.

You can use the subclass __new__, but that's definitely 'unpythonic'. 

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


Re: __contains__ vs. __getitem__

2006-08-09 Thread Pedro Werneck
On Wed, 09 Aug 2006 16:51:23 GMT
"David Isaac" <[EMAIL PROTECTED]> wrote:

> Looking forward:
> Can I count on this independence of __getitem__ and __contains__?
> I would like to understand whether it will be safe to count on this
> behavior.


With the builtin 'dict' implementation, dict.__contains__() use the
dict_has_key() C function, and does not touch your subclass __getitem__
python method. I don't think it can be called 'safe'... it may lead to
very inconsistent behavior. It's like overridind both __eq__ and __ge__
with a different behavior. It's better for you to override
__contains__() too.


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


Re: Two Classes In Two Files

2006-08-09 Thread Pedro Werneck
On 9 Aug 2006 12:35:48 -0700
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

> 
> > It's just the way it is. Why worry about it?
> 
> Wasn't so much a worry, just trying to figure out how to think the
> python way.

Seems like you're thinking the Java way... if you don't want to do it,
put both classes in the same file.

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


Help solving Python 2.5 crash: The instruction "0x7c168f1d" referenced memory at "0x00000001c" ...

2006-11-08 Thread Pedro Rodrigues
Hi everyone,
 
recently, I have installed Python 2.5 in a Windows XP (SP2) system, along with the numarray, PIL, and PyWin packages. Since then, I've been getting the following error message whenever I run one of my simulations within PyWin: 

 
The instruction "0x7c168f1d" referenced memory at "0x0001c". The memory could not be "read". 
 
 
If I run the same simulation from the python interactive shell, it still crashes but with a different error message:
 
This application has requested runtime to terminate it in an unusual way. Please contact the application's support team for more information.
 
 
The simulation demands a lot of memory but this shouldn't be the problem as it run in Windows XP before I switched to version 2.5. I've already tried to remove version 2.5 and install version 2.4.3 (the one I had before), but the I get the same problem :( 

 
Has anyone every experienced such a thing? Suggestions on how to solve this?
 
 
greetings,
pedro rodrigues
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Help solving Python 2.5 crash: The instruction "0x7c168f1d" referenced memory at "0x00000001c

2006-11-08 Thread Pedro Rodrigues
Hi Bugra,
 
thanks for your reply. I did try the same code on a Windows 2000 system where I also installed and later removed Python 2.5. There, I obtained the same problem :( That's why I think it has to do with software. I've also searched on the internet and this problem seems to come up also with other sorts of applications. This lead me to think that there might be some inconsistency in the Registry of Windows or some files that have been left behind after uninstall. I've tried to address these two possibilities but so far I did not succeed :(

 
pedro 
On 11/8/06, Bugra Cakir <[EMAIL PROTECTED]> wrote:
Hi,I have came across this like problem in my simulations also. But the case is not for the program structure or
python version, the case is hardware :) . If you have time to try it on some other machine than the current and if the problem arises then there is something different!--
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Interested in a Python User Group in Porto/Portugal?

2006-09-20 Thread Pedro Lima
There is now a list to help put together such a group:
http://groups.google.com/group/python-porto

Regards,
Pedro Lima

PS. please forward this message to people you think that could be
interested.

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


Improving interpreter startup speed

2008-10-25 Thread Pedro Borges
Hi guys,


Is there a way to improve the interpreter startup speed?

In my machine (cold startup) python takes 0.330 ms and ruby takes
0.047 ms, after cold boot python takes 0.019 ms and ruby 0.005 ms to
start.


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


Re: Improving interpreter startup speed

2008-10-26 Thread Pedro Borges
The scripts i need to run but be executed with no apparent delay  
specially when the text transforms are simple.



On Oct 26, 2008, at 11:13 AM, James Mills wrote:

On Sun, Oct 26, 2008 at 11:23 AM, BJörn Lindqvist  
<[EMAIL PROTECTED]> wrote:
How are you getting those numbers? 330 μs is still pretty fast,  
isn't

it? :) Most disks have a seek time of 10-20 ms so it seem implausible
to me that Ruby would be able to cold start in 47 ms.


$ time python -c "pass"

real0m0.051s
user0m0.036s
sys 0m0.008s

$ time python3.0 -c "pass"

real0m0.063s
user0m0.048s
sys 0m0.004s

And yes I agree. the CPython interpreter startup times is
a stupid thing to be worrying about, especially since that
is never the bottleneck.

Python loads plenty fast enough!

--JamesMills

--
--
-- "Problems are solved by method"


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


First script, please comment and advise

2006-03-09 Thread Pedro Graca
I'm sure this isn't very pythonic; comments and advice appreciated


def curious(text):
""" Return the words in input text scrambled except for the first and 
last letter. """
new_text = ""
word = ""
for ch in text:
if ch in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":
word = word + ch
else:
new_text = new_text + scramble(word)
word = ""
new_text = new_text + ch
return new_text

def scramble(word):
""" scramble word """
from random import randint

if len(word) < 4:
return word
new_word = word[0]

### transform "curious" into ['u', 'r', 'i', 'o', 'u']
letters = []
for ch in word:
letters.append(ch)
del letters[0:1]
del letters[-1]

### why doesn't range(len(letters) - 1, 0, -1) work?
for i in range(len(letters) - 1, -1, -1):
j = randint(0, i)
new_word = new_word + letters[j]
del letters[j]
return new_word + word[-1]

print curious(curious.__doc__)


-- 
If you're posting through Google read 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: First script, please comment and advise

2006-03-09 Thread Pedro Graca
Just wrote:
> In article <[EMAIL PROTECTED]>,
>  Pedro Graca <[EMAIL PROTECTED]> wrote:
>
[snip: very un-pythonic code]
>
> def curious(text):
> """ Return the words in input text scrambled except for the
> first and last letter. """
> new_text = ""
> word = ""
> for ch in text:
> if ch.isalpha():

Ah! shorter and clearer than my attempt.

> word += ch
> else:
> new_text += scramble(word)
> word = ""
> new_text += ch
> new_text += scramble(word)

Oops. I failed to test bad input :)
Thanks for the correction.

> return new_text
>
> def scramble(word):
> """ scramble word """
> from random import shuffle
> if len(word) < 4:
> return word
> letters = list(word[1:-1])

list(string) transforms a string in a list ...

> shuffle(letters)
> return word[0] + "".join(letters) + word[-1]

... and delimiter.join(list) transforms a list in a string.

I guess I shouldn't have payed attention to the people who said "Don't
bother with the manual, just try it."

I've just downloaded "Dive Into Python" and will print and read it.


Thank you for your corrections and hints for my code.

-- 
If you're posting through Google read <http://cfaj.freeshell.org/google>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: First script, please comment and advise

2006-03-09 Thread Pedro Graca
[EMAIL PROTECTED] wrote:
> Just:
>> [previous post, hand inserted]
>>> def scramble_text(text):
>>> def scramble_word(word):
>>
>> Btw. I find the use of a nested function here completely bogus: you
>> don't need the surrounding scope.
>
> I don't agree, nested functions are useful to better structure your
> program: to really nest things that are logically nested, to have just
> one thing when you have only one thing to do, and they help you to
> avoid polluting the namespace (those were the main purposes of nested
> functions in Pascal-like languages).

I have never used nested functions before, but I like the idea.
For the code posted earlier I stated the reason I don't like it in
another post to this thread.

-- 
If you're posting through Google read 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: First script, please comment and advise

2006-03-09 Thread Pedro Graca
[EMAIL PROTECTED] wrote:
> My version is similar to Just one:
>
> from random import shuffle
>
> def scramble_text(text):
> """Return the words in input text string scrambled
> except for the first and last letter."""
> def scramble_word(word):

Nice. You can have functions inside functions.
However I think scramble_word() deserves being a callable function by
itself.

Can a "sub-function" be called directly from outside the defining
function?

> if len(word) < 4: return word
> core = list(word[1:-1])
> shuffle(core)
> return word[0] + "".join(core) + word[-1]
>
> return " ".join(map(scramble_word, text.split()))
>
> print scramble_text(scramble_text.__doc__)

Thank you for your version of the scrambler.

-- 
If you're posting through Google read 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to run python script in emacs

2009-12-22 Thread Pedro Insua
On Wed, Nov 25, 2009 at 09:38:54AM -0800, doug wrote:
> 
> When I type C-c C-c my emacs window just hangs.  If I use Task Manager
> to kill cmdproxy I can get emacs back but of course interactivity with
> Python is not accomplished.  By the way, if I do C-c ! then I get a
> functional python shell.  Does anybody know a solution to this?
> 

  run emacs with --debug-init , then see the *Messages* Buffer.

  With Python, I use python-mode, pymacs with rope, pysmell, and
  anything with iPython.

  I prefer iPython like shell.. 

  But see http://www.emacswiki.org/ , there's a lot of documentation.

  And .. Emacs version? Python version? .. etc




> On Oct 13, 7:12 am, rustom  wrote:
> > On Sep 26, 8:54 pm, devilkin  wrote:
> >
> > > I'm just starting learning python, and coding in emacs. I usually
> > > split emacs window into two, coding in one, and run script in the
> > > other, which is not very convenient. anyone can help me with it? is
> > > there any tricks like emacs short cut?
> >
> > > also please recommand some emacs plug-ins for python programming, i'm
> > > also beginner in emacs.currently i'm only using python.el.
> >
> > python.el comes with emacs
> > python-mode.el comes from python  https://launchpad.net/python-mode/
> > Because of some emacs politics the first ships with emacs although
> > most uses prefer the second.
> > Note 1. The key bindings are different
> > Note 2. Does not work with python3. See my 
> > posthttp://groups.google.com/group/comp.lang.python/browse_thread/thread/...
> >
> > > Are any plugins supply code folding and autocomplete?
> >
> > See ropehttp://rope.sourceforge.net/ropemacs.htmlif you want
> > but its an installation headache (requires pymacs bleeding edge
> > version etc)
> > I suggest you just get used to python-mode first (C-c ! and C-c C-c)
> > and then explore these questions a bit later.
> >
> >
> >
> > > BTW, I'm not a english native speaker, any grammer mistakes, please
> > > correct them. :)
> >
> > grammer is spelt grammar :-)
> 

-- 
Porqué loitar e matar, se podes amar e sonhar

/"\
\ /  CAMPANHA DA FITA ASCII - CONTRA MAIL HTML
 X   ASCII RIBBON CAMPAIGN - AGAINST HTML MAIL
/ \
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Imaging libraries in active development?

2012-12-02 Thread Luis Pedro Coelho

Alasdair McAndrew  on Thu, 29 Nov 2012 wrote:
> Probably the combinations of OpenCV, Scipy.ndimage and scikits-image 
> would cover pretty much all of my needs.


Hi,

All of those (+ mahotas, which is the package I wrote & imread which 
might be useful for microscopy file formats) will work on numpy arrays 
(openCV requires a bit of conversion back and forth, but it will work). 
Therefore, it is not much of a bother to mix&match functions from one or 
the other library::


import mahotas as mah
import imread
import skimage
import pylab

image = imread.imread("my-fancy-image.jpeg")
filtered = mah.gaussian_filter(image, 4.)
segmented = skimage.segmentation.quickshift(filtered)
pylab.imshow(segmented)
...

I just mixed 4 different packages seamlessly in this example. This will 
work flawlessly.


mahotas & skimage are both under very active development, but neither is 
unstable (i.e., we keep adding new features, but the existing code is 
very reliable). scipy.ndimage is sort of dead: I scavenged its code for 
good bits and pieces for mahotas, but nobody is developing ndimage.


If you run into specific issues, the mailing list pythonvision at

https://groups.google.com/forum/#!forum/pythonvision

is a good forum. Plenty of people from different projects lurk there.

HTH,
Luis
--
http://mail.python.org/mailman/listinfo/python-list


Import a file to namespace

2008-03-20 Thread Pedro Machado Santa
Hi all,

I'm really a newbie in Python, and I wanted to do a tricky thing. I
don't know if it is possible but my intention was: I have a package
(namely breve) and I want to alter (override?) some of it's functions
preserving the original library/package - in order if I update it, I
do not lose my "hacks".

Until now I was overriding the functions directcly on my script and
adding them to the package namespace, like this:

import testpackage

class testClass():
#...

testpackage.testClass =  testClass


But this has a problem. If I wanna use that code over many files, I
have to update it manually on all of them every time I update my
"hack". I was thinking if it is possible to keep that code on a file -
namely testpackageaddon.py and import it on my work file so that by
doing that it will automatically override the classes. Like so:

import testpackage
import testpackageaddon

testpackage.testClass() #my hacked class defined on
testpackageaddon.py


And on testpackageaddon.py:

import testpackage

class testClass():
#...

testpackage.testClass =  testClass


Any tips, ideas on how to do this?

Many thanks.

Pedro Machado Santa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Import a file to namespace

2008-03-20 Thread Pedro Machado Santa
On Mar 20, 5:24 pm, Jeffrey Froman <[EMAIL PROTECTED]> wrote:
> This method should work fine. Modules are effectively singletons, so running
> this code one time anywhere in your application will cause the changes to
> appear in all references to the original module.

Yhea. I got it now. :) It already works. I wasn't putting the module
on my working dir.

(I created the module testpackageaddon.py and I did the "override" on
it, then imported it after the import testpackage on my working
script.)

Thanks.

Pedro Machado Santa
-- 
http://mail.python.org/mailman/listinfo/python-list


Convert points to polygon shapefile

2009-07-24 Thread Luis Pedro Almeida

Dear all,



I would like to know how to convert a list of points into a polygon 
shapefile (esri).




Thanks!



Best regards,



Luis Pedro Almeida

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


Re: Software Engineer -

2012-03-13 Thread Pedro H. G. Souto

On 2012-03-13 12:44 PM, Paul Rudin wrote:

Just out of interest why do people object to job adverts here? Seems
harmless enough...
Wannabe list admins... Or list admins with a need to proof themselves... 
Or none of the above.

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


what is happening in panda "where" clause

2017-09-22 Thread Exposito, Pedro (RIS-MDW)
This code does a "where" clause on a panda data frame...

Code:
import pandas as pd;
col_names = ['Name', 'Age', 'Weight', "Education"];
# create panda dataframe
x = pd.read_csv('test.dat', sep='|', header=None, names = col_names);
# apply "where" condition
z = x[ (x['Age'] == 55) ]
# prints row WHERE age == 55
print (z);

What is happening in this statement:
z = x[ (x['Age'] == 55) ]

Thanks,
Pedro Exposito




 The information contained in this 
e-mail message is intended only for the personal and confidential use of the 
recipient(s) named above. This message may be an attorney-client communication 
and/or work product and as such is privileged and confidential. If the reader 
of this message is not the intended recipient or an agent responsible for 
delivering it to the intended recipient, you are hereby notified that you have 
received this document in error and that any review, dissemination, 
distribution, or copying of this message is strictly prohibited. If you have 
received this communication in error, please notify us immediately by e-mail, 
and delete the original message.  
-- 
https://mail.python.org/mailman/listinfo/python-list


Can signal.alarm be safely cleared in python?

2016-11-17 Thread Pedro Franco de Carvalho
Assume a python program sets a handler function for the
`signal.SIGALRM` signal, and then schedules an alarm in T seconds with
`signal.alarm(T)`.

Assume the program later cancels any scheduled alarm with `signal.alarm(0)`.

Can the program safely assume that after the call to `signal.alarm(0)`
completes no alarm handling function will be called?

The reason I ask is that the signal module documentation [1] says that:

"A Python signal handler does not get executed inside the low-level
(C) signal handler. Instead, the low-level signal handler sets a flag
which tells the virtual machine to execute the corresponding Python
signal handler at a later point(for example at the next bytecode
instruction)."

Since this "later point" is not specified, could it be that a the
alarm is triggered and calls the low-level C handler shortly before
the call to `signal.alarm(0)`, but the python signal handler is only
executed at some point after this call?

[1]: 
https://docs.python.org/3.6/library/signal.html#execution-of-python-signal-handlers)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Total newbie question: Best practice

2011-11-30 Thread Pedro Henrique G. Souto

On 30/11/2011 06:50, Shambhu Rajak wrote:

Collins Congratulations for your first step into Python Programming.
You can call them script or programs(not necessarily but depends on what your 
coding for).
Yaa..it's always a good practice to call it through main(), but it doesn't 
really matter you
can call the method in way

Regards,
Shambhu

-Original Message-
From: Colin Higwell [mailto:[email protected]]
Sent: 30/11/2011 1:37 AM
To: [email protected]
Subject: Total newbie question: Best practice

Hi,

I am just starting to learn Python (I have been at it only a few hours),
so please bear with me. I have a few very small scripts (do you call them
scripts or programs?) which work properly, and produce the results
intended.

However, they are monolithic in nature; i.e. they begin at the beginning
and finish at the end. Having done a little reading, I note that it seems
to be quite common to have a function main() at the start (which in turn
calls other functions as appropriate), and then to call main() to do the
work.

Is that standard best practice?

Thanks


Congratulations on becoming a Pythonist!

Like Shambhu said, it doesn't matter where do you put the code, but is 
interesting to have a main() function when you have a program, and you 
want to differentiate if it is running directly (i.e. python program.py) 
or if it is running as a  module, imported by other program (i.e. import 
program).


To do so, you do this:

main():
# blablabla

if __name__ == '__main__':
main()


If the program is running directly, the variable __name__ will be 
'__main__', if not, __name__ will be the name of the module ('program', 
in this case).


Att;
Pedro
--
http://mail.python.org/mailman/listinfo/python-list


Re: Complete beginner, any help appreciated :) - For Loops

2011-12-01 Thread Pedro Henrique G. Souto


On 01/12/2011 08:53, Mark wrote:

Hi there,

I'm a complete beginner to Python and, aside from HTML and CSS, to coding in 
general. I've spent a few hours on it and think I understand most of the syntax.

However, I'm wondering a bit about For Loops. I know that the basic syntax for 
them is to define a list, and then to use something like:

for x in y

However, what does "for" and "in" mean in this context? Can anyone help me to 
understand this? I know it's a really basic question, but hopefully it will see me on my way to 
coding properly :)

Thanks a lot.


That means (in a free translation)

"For each one of 'x' in 'y', do this"

'y' is a list, for example, then it means: "For each one of the elements 
of the list 'y' (the element on the current iteration is named 'x'), do 
this"


Good Luck!

Att;
Pedro Henrique G. Souto

╔═╗
║ ²²²d○_○b²²² ║
╚═╝

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


Re: Install Python on Windows without Start Menu icons?

2011-12-03 Thread Pedro Henrique G. Souto

On 02/12/2011 16:34, snorble wrote:

Is it possible to automate the Python installation on Windows using
the MSI file so it does not add a Start Menu folder? I would like to
push out Python to all of my office workstations, but I'd like for it
to be relatively silent from the user's point of view.


If you just want to run python scripts in those machines (not developing 
in it), you can use something like py2exe [http://www.py2exe.org/].


It converts a python script to a standalone executable.

Good luck!
--
Att;
Pedro Henrique G. Souto

╔═╗
║ ²²²d○_○b²²² ║
╚═╝
--
http://mail.python.org/mailman/listinfo/python-list


Re: whitespace cleanup

2011-12-06 Thread Pedro Henrique G. Souto

On 06/12/2011 09:28, Andrea Crotti wrote:
> Now on Emacs I have a hook before every save that cleans up all the
> "wrong" white spaces,
> with the 'whitespace-cleanup' function.
>
> I would like that also for my non emacsers colleagues, and possibly with
> a Python script.
> I looked up around but I can't find anything useful, any advice?

You can use the strip() method: 
[http://docs.python.org/release/2.3/lib/module-string.html]


While reading the file as strings, the strip() method rips out all of 
the extra whitespace.


> Thanks,
> Andrea
>

Good luck!

--
Att;
Pedro Henrique G. Souto

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


Re: whitespace cleanup

2011-12-06 Thread Pedro Henrique G. Souto

On 06/12/2011 10:06, Chris Angelico wrote:

On Tue, Dec 6, 2011 at 10:59 PM, Andrea Crotti
  wrote:

Well it's not so simple, I clearly don't want to strip out whitespace in the
beginning of the line,
or my nice code will break miserably ;)


The question is: What is "wrong" whitespace? Whatever you declare to
be wrong, you can probably come up with a regexp or other spec that
will catch it (or conversely, declare some pattern to be "right" and
look for anything else).

ChrisA


Something like PythonTidy does what you want?

http://pypi.python.org/pypi/PythonTidy

If you like to write your own script, or if what you want is similar, 
but not the same, the source code is a good place to start:


http://lacusveris.com/PythonTidy/PythonTidy-1.20.python

--
Att;
Pedro Henrique G. Souto

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


Re: text to html

2011-12-13 Thread Pedro Henrique Guedes Souto
On Tue, Dec 13, 2011 at 3:22 PM, prakash jp  wrote:
>
> Hi All,
>
> Want to publish a log file as a web page, is there a parser to retain the 
> format of the text as is and then convert to html. Please provide the 
> relevant pointers


Hey, You can use this: http://txt2tags.org/

Att;
Pedro Henrique Guedes Souto
[[email protected]]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NoSQL Movement?

2010-03-04 Thread Juan Pedro Bolivar Puente
On 04/03/10 16:21, ccc31807 wrote:
> On Mar 3, 4:55 pm, toby  wrote:
>>>  where you have to store data and
>>
>> "relational data"
> 
> Data is neither relational nor unrelational. Data is data.
> Relationships are an artifact, something we impose on the data.
> Relations are for human convenience, not something inherent in the
> data itself.
> 

No, relations are data. "Data is data" says nothing. Data is
information. Actually, all data are relations: relating /values/ to
/properties/ of /entities/. Relations as understood by the "relational
model" is nothing else but assuming that properties and entities are
first class values of the data system and the can also be related.

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


Re: NoSQL Movement?

2010-03-05 Thread Juan Pedro Bolivar Puente
On 04/03/10 19:52, ccc31807 wrote:
> On Mar 4, 11:51 am, Juan Pedro Bolivar Puente 
> wrote:
>> No, relations are data.
> 
> This depends on your definition of 'data.' I would say that
> relationships is information gleaned from the data.
> 
>> "Data is data" says nothing. Data is
>> information.
> 
> To me, data and information are not the same thing, and in particular,
> data is NOT information. To me, information consists of the sifting,
> sorting, filtering, and rearrangement of data that can be useful in
> completing some task. As an illustration, consider some very large
> collection of ones and zeros -- the information it contains depends on
> whether it's views as a JPEG, an EXE, XML, WAV, or other sort of
> information processing device. Whichever way it's processed, the
> 'data' (the ones and zeros) stay the same, and do not constitute
> 'information' in their raw state.
> 
>> Actually, all data are relations: relating /values/ to
>> /properties/ of /entities/. Relations as understood by the "relational
>> model" is nothing else but assuming that properties and entities are
>> first class values of the data system and the can also be related.
> 
> Well, this sort of illustrates my point. The 'values' of 'properties'
> relating to specific 'entities' depends on how one processes the data,
> which can be processed various ways. For example, 1001 can either
> be viewed as the decimal number 65 or the alpha character 'A' but the
> decision as to how to view this value isn't inherent in the data
> itself, but only as an artifact of our use of the data to turn it into
> information.
> 

Well, it depends as you said on the definition of information; actually
your definition of data fits into the information-theorical definition
of information as sequence of symbols... But I understand that in other
context /information/ can also mean the next level of abstraction on top
of /data/, in the same way as /knowledge/ is the next level of
abstraction on top of information; lets ground or basis on that.

In any case, your definition and George's still support my point of view
where relations are data: they are stored in the computer as a sequence
of ones and zeroes and is indistinguishable from any other thing in the
data space in that sense. Of course, it is a key data to be able to
recover information and specially to add new information consistently to
the data storage... That SQL includes special syntax for manipulating
relations should not hide this fact; and one can still query the
relational information in the same way one would query non-relational
data in most DBMS anyway...

Anyway I'm sorry for drifting the conversation away... Going back to the
main topic, I agree with the general view on this thread that relational
databases (information-bases ? ;) and non-relational ones are there to
do some different jobs. It is just by carefully examining a problem that
we can define which one fits it better; with relational databases having
the clear advantage that is mathematically grounded basis makes its
fitness for most problems quite clear, while the preference for
non-relational systems is a more technical and empirical problem of the
trade-offs of consistency vs scalability and so on.

JP

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


Help in language development

2010-11-16 Thread pedro igor sampaio avelino
Hello, my name Pedro Igor, I am a student and develop applications in
python for 1 year. I enrolled in the group to contribute in developing
this wonderful language that helps me both in day-to-day, but I'm
going through some difficulties because they do not know where to
start, can someone please give me some steps so that I can contribute
at once development for all, where do I start, if the documentation or
a book. I know that most people have more important issues to address
in other posts but assistance does not cost anything.

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