Re: Checking if a text file is blank

2008-04-20 Thread David
>
>  import os
>  print os.lstat("friends.txt")[6]
>

I prefer os.lstat("friends.txt").st_size
-- 
http://mail.python.org/mailman/listinfo/python-list


Noadware.net - Spyware/Adware Remover

2008-04-20 Thread yuxuy501
Noadware.net - Spyware/Adware Remover  http://zoneweb.freeweb7.com/noadware.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finally had to plonk google gorups.

2008-04-20 Thread Gabriel Genellina
En Wed, 16 Apr 2008 14:23:57 -0300, Steve Holden <[EMAIL PROTECTED]> escribió:
> Torsten Bronger wrote:

>> The admistrative overhead of mailing lists is tedious.  Fortunately,
>> most important computer-related lists are on gmane.org.  We could
>> list c.l.py there, too.  ;-)
>>
> c.l.py has been on gmane for years, as comp.python.general (why they
> have to have their own naming hierarchy i have never understood).

Because "someone" chose that name when he/she asked for the list to be added; 
the name gmane.comp.lang.python *could* have been used, but wasn't.
(gmane uses its own hierarchy because not all mirrored lists exist as a 
newsgroup outside gmane, and there are potential name conflicts)

-- 
Gabriel Genellina

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


Re: Checking for unique fields: performance.

2008-04-20 Thread Gabriel Genellina
En Fri, 18 Apr 2008 12:23:08 -0300, Shawn Milochik <[EMAIL PROTECTED]> escribió:

> I'm looping through a tab-delimited file to gather statistics on fill rates,
> lengths, and uniqueness.
>
> For the uniqueness, I made a dictionary with keys which correspond to the
> field names. The values were originally lists, where I would store values
> found in that field. Once I detected a duplicate, I deleted the entire
> element from the dictionary. Any which remained by the end are considered
> unique. Also, if the value was empty, the dictionary element was deleted and
> that field considered not unique.
>
> A friend of mine suggested changing that dictionary of lists into a
> dictionary of dictionaries, for performance reasons. As it turns out, the
> speed increase was ridiculous -- a file which took 42 minutes to run dropped
> down to six seconds.

A dictionary with keys is perfectly reasonable. But a *list* of values has to 
be searched linearly for every value: a O(n) process. As your friend suggested, 
searching a dictionary requires O(1) time. A set is even better in this case, 
because you don't have any use for the values in the inner dictionary (sets and 
dictionaries are very similar in the implementation).

> Here is the excerpt of the bit of code which checks for uniqueness. It's
> fully functional, so I'm just looking for any suggestions for improving it
> or any comments. Note that fieldNames is a list containing all column
> headers.
>
> #check for unique values
> #if we are still tracking that field (we haven't yet
> #found a duplicate value).
> if fieldUnique.has_key(fieldNames[index]):
> #if the current value is a duplicate
> if fieldUnique[fieldNames[index]].has_key(value):
> #sys.stderr.write("Field %s is not unique. Found a
> duplicate value after checking %d values.\n" % (fieldNames[index], lineNum))
> #drop the whole hash element
> fieldUnique.__delitem__(fieldNames[index])
> else:
> #add the new value to the list
> fieldUnique[fieldNames[index]][value] = 1
>

- Instead of using fieldNames[index] all along the place, save it in a variable.
- Your code doesn't show it, but if you are traversing the fieldNames vector 
like this:
 for index in range(len(fieldNames)):
 ... using fieldNames[index] ...
it's better to use:
 for fieldName in fieldNames:
 ... using fieldName all along the place ...

- Instead of a.has_key(b), use: b in a
- Instead of fieldUnique.__delitem__(fieldNames[index]) use: del 
fieldUnique[fieldName]
   (In normal code, __special__ methods are never used)

 #check for unique values
 #if we are still tracking that field (we haven't yet
 #found a duplicate value).
 if fieldName in fieldUnique:
 #if the current value is a duplicate
 if value in fieldUnique[fieldName]:
 #drop the whole field as it's not unique
 del fieldUnique[fieldName]
 else:
 #add the new value to the set
 fieldUnique[fieldName].add(value)
 else:
 # use a set to store the unique values
 fieldUnique[fieldName] = set([value])

-- 
Gabriel Genellina

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


Re: random.random(), random not defined!?

2008-04-20 Thread Gabriel Genellina
En Sat, 19 Apr 2008 16:28:37 -0300, globalrev <[EMAIL PROTECTED]> escribió:

> do i need to import something to use random?

Let me guess: you have a script named random.py? Perhaps the same one you're 
executing?
In that case when you write "import random", you're importing *your* script 
instead of the standard one.

-- 
Gabriel Genellina

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


Re: Calling Java Class from python

2008-04-20 Thread Gabriel Genellina
En Wed, 16 Apr 2008 07:37:55 -0300, Good Z <[EMAIL PROTECTED]> escribió:

> We have developed a website in python and we need to integrate few features 
> of third party website. They have provided us Base64EncoderDecoder Java Class 
> and would like us to use it to encode the data before sending it to their 
> site and decode it when received anything from their site.
>
> I have no idea/knowledge of  Java. Can you please guide me  how can i call 
> Java class from  Python  scripts? Or what is the best way to handle this 
> condition.
>
> Is Base64  library provided by python is compatible to  Base64EncoderDecoder 
> Java Class?

If the Java class implements Base64 as defined in RFC 3548, it should be 
compatible with the Python base64 module.
Try with some examples, including the corner cases (empty, one byte, two bytes, 
three bytes, length = 3n, 3n+1, 3n+2, including bytes outside the ASCII 
range...)

-- 
Gabriel Genellina

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


Re: python memory leak only in x86 64 linux

2008-04-20 Thread Gabriel Genellina
En Wed, 16 Apr 2008 13:10:42 -0300, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 
escribió:

> This is the code that is causing memory leak in 64 bit python [but not
> in 32 bit python].. is something wrong in the code?
>
> [... Python code using the datetime module ...]

>> the memory usage of a python app keeps growing in a x86 64 linux
>>  continuously, whereas in 32 bit linux this is not the case. Python
>>  version in both 32 bit and 64 bit linux - 2.6.24.4-64.fc8
>>  Python 2.5.1 (r251:54863, Oct 30 2007, 13:45:26)
>>
>>  i isolated the memory leak problem to a function that uses datetime
>>  module extensively. i use datetime.datetime.strptime,
>>  datetime.timedelta, datetime.datetime.now methods...

In principle pure Python code should have no memory leaks - if there are, 
they're on Python itself.
Maybe this is an allocation problem, not an actual leak; if you can write a 
program that reproduces the problem, post a bug at http://bugs.python.org


-- 
Gabriel Genellina

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


Re: why function got dictionary

2008-04-20 Thread Gabriel Genellina
En Thu, 17 Apr 2008 11:06:08 -0300, AlFire <[EMAIL PROTECTED]> escribió:

> Q: why function got dictionary? What it is used for?

If you want more details, see PEP 232 that introduced function writable 
attributes in Python 2.1: http://www.python.org/dev/peps/pep-0232/

-- 
Gabriel Genellina

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


???Python Memory Management S***s???

2008-04-20 Thread Hank @ITGroup
Hi, people!

Greetings~
These days I have been running a text processing program, written by 
python, of cause.
In order to evaluate the memory operation, I used the codes below:

"""
 > string1 = ['abcde']*99# this took up an obvious memory space...
 > del string1  # this freed the memory 
successfully !!

"""
For primary variants, the *del* thing works well. However, challenge the 
following codes, using class-instances...

"""
 > from nltk import FreqDist # nltk stands for Natural Language Tool 
Kit (this is not an advertisement ~_~)
 > instance = FreqDist()
 > instanceList = [instance]*9
 > del instanceList # You can try: nothing is freed by this
"""
??? How do you people control python to free the memory in python 2.5 or 
python 2.4 ???
Cheers!!!


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


Re: Any reliable obfurscator for Python 2.5

2008-04-20 Thread Gabriel Genellina
En Sun, 20 Apr 2008 01:55:51 -0300, Banibrata Dutta <[EMAIL PROTECTED]> 
escribió:

> Wanted to check if there is any known, reliable, FOSS/Libre -- Obfurscator
> for Python 2.5 code.

Why do you want to do that in the first place?
There is very few you can do to obfuscate Python code. You can't rename classes 
nor methods nor global variables nor argument names due to the dynamic nature 
of Python. All you can safely do is to remove comments and join simple 
statements using ;
If you remove docstrings, some things may break. Even renaming local variables 
isn't safe in all cases.

-- 
Gabriel Genellina

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


Re: Request a short code review

2008-04-20 Thread Gabriel Genellina
En Fri, 18 Apr 2008 15:10:09 -0300, <[EMAIL PROTECTED]> escribió:

> lessons = self.lesson_data["lessons"]
> if lesson_type:
> lessons = [x for x in lessons if x["type"] == lesson_type]
>
> Changes:
>  - generator expression instead of filter

The above is not a generator expression, it's a list comprehension. They look 
similar.
This is a list comprehension:

py> a = [x for x in range(10) if x % 2 == 0]
py> a
[0, 2, 4, 6, 8]

Note that it uses [] and returns a list. This is a generator expression:

py> g = (x for x in range(10) if x % 2 == 0)
py> g

py> g.next()
0
py> g.next()
2
py> for item in g:
...   print item
...
4
6
8

Note that it uses () and returns a generator object. The generator is a block 
of code that runs lazily, only when the next item is requested. A list is 
limited by the available memory, a generator may yield infinite items.

> Cheers again.  This is very valuable for me.  I am a true believer
> that if one takes care in the smallest of methods then the larger code-
> base will be all the better.

Sure.

-- 
Gabriel Genellina

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


Re: ???Python Memory Management S***s???

2008-04-20 Thread Daniel Fetchinson
On 4/20/08, Hank @ITGroup <[EMAIL PROTECTED]> wrote:
> Hi, people!
>
> Greetings~
> These days I have been running a text processing program, written by
> python, of cause.
> In order to evaluate the memory operation, I used the codes below:
>
> """
>  > string1 = ['abcde']*99# this took up an obvious memory space...
>  > del string1  # this freed the memory
> successfully !!
>
> """
> For primary variants, the *del* thing works well. However, challenge the
> following codes, using class-instances...
>
> """
>  > from nltk import FreqDist # nltk stands for Natural Language Tool
> Kit (this is not an advertisement ~_~)
>  > instance = FreqDist()
>  > instanceList = [instance]*9
>  > del instanceList # You can try: nothing is freed by this
> """
> ??? How do you people control python to free the memory in python 2.5 or
> python 2.4 ???
> Cheers!!!

I don't know about the others, I personally let the garbage collector
take care of it.

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


Re: Python 2.5 adoption

2008-04-20 Thread Lie
On Apr 19, 1:08 am, Joseph Turian <[EMAIL PROTECTED]> wrote:
> How widely adopted is python 2.5?
>
> We are doing some development, and have a choice to make:
> a) Use all the 2.5 features we want.
> b) Maintain backwards compatability with 2.4.
>

There is another choice: Develop with future in mind because it's
possible that when you finished version 1, what seemed to be future
would become the present. This is especially if the project is big and
requires years to complete.

On Apr 19, 5:13 pm, Graham Breed <[EMAIL PROTECTED]> wrote:
> My web host uses 1.5.2.  That is painful.

If them using 1.5.2 is painful for you ask the host to install
something newer (AFAIK it is possible to run several python versions
side-by-side) or prepare yourself to move to other host.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: installing MySQLdb module

2008-04-20 Thread martin . laloux
search, search, search

http://groups.google.be/group/comp.lang.python/browse_thread/thread/d75a491b8dbc3880/7d4f8eea29e23992?hl=fr&lnk=gst&q=MySQLdb+mac#7d4f8eea29e23992

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


Re: ???Python Memory Management S***s???

2008-04-20 Thread Marc 'BlackJack' Rintsch
On Sun, 20 Apr 2008 18:40:26 +1000, Hank @ITGroup wrote:

> In order to evaluate the memory operation, I used the codes below:
> 
> """
>  > string1 = ['abcde']*99# this took up an obvious memory space...
>  > del string1  # this freed the memory 
> successfully !!

Indirectly.  ``del`` does not delete objects but just names, so you
deleted the name `string1` and then the garbage collector kicked in and
freed the list object as it was not reachable by other references anymore.

> """
> For primary variants, the *del* thing works well. However, challenge the 
> following codes, using class-instances...
> 
> """
>  > from nltk import FreqDist # nltk stands for Natural Language Tool 
> Kit (this is not an advertisement ~_~)
>  > instance = FreqDist()
>  > instanceList = [instance]*9
>  > del instanceList # You can try: nothing is freed by this
> """

How do you know this?  And did you spot the difference between 99 and
9!?  Are you aware that both lists contain many references to a
*single* object, so the memory consumption has very little to do with the
type of object you put into the list?

In the second case you still hold a reference to that single instance
though.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python setup.py install on Vista?

2008-04-20 Thread Lie
On Apr 19, 6:29 am, globalrev <[EMAIL PROTECTED]> wrote:
> type "python setup.py install"
>
> that is used in most "addons" for python.
>
> well using windows vista, where the h*** am i supposed to type this?
>
> if it is not doable in windows, what do i have to do instead? just
> clicking the setup.py-file never works.

It seems that quite a lot of people wondered why python doesn't set
the environment variable to Python Path in the default installation.
While most Windows users that are flattered with GUI (IDLE) doesn't
really care about it, they'd have trouble when trying to run python
from command prompt.

To set your environment variable:
1. Right-click the Computer icon
2. Choose "Properties" from the context menu
3. Click the "Advanced system settings" link
4. Click the "Environment Variables" button
5. Add Python's installation path (usually C:\PythonXX where XX is the
Python version) to System Variables to the end of the path lists
6. Test it, try opening a command prompt and type "python" or "python
filename.py" outside Python installation directory
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ???Python Memory Management S***s???

2008-04-20 Thread Arnaud Delobelle
On Apr 20, 9:40 am, "Hank @ITGroup" <[EMAIL PROTECTED]> wrote:
> Hi, people!
>
> Greetings~
> These days I have been running a text processing program, written by
> python, of cause.
> In order to evaluate the memory operation, I used the codes below:
>
> """
>  > string1 = ['abcde']*99    # this took up an obvious memory space...
>  > del string1                              # this freed the memory
> successfully !!
>
> """
> For primary variants, the *del* thing works well. However, challenge the
> following codes, using class-instances...
>
> """
>  > from nltk import FreqDist     # nltk stands for Natural Language Tool
> Kit (this is not an advertisement ~_~)
>  > instance = FreqDist()
>  > instanceList = [instance]*9
>  > del instanceList             # You can try: nothing is freed by this
> """
> ??? How do you people control python to free the memory in python 2.5 or
> python 2.4 ???
> Cheers!!!

You mistyped your subject line; it should have read:

"Help needed - I don't understand how Python manages memory"

--
Arnaud

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


Re: 2's complement conversion. Is this right?

2008-04-20 Thread Peter Otten
Bob Greschke wrote:

> On 2008-04-18 23:35:12 -0600, Ivan Illarionov <[EMAIL PROTECTED]>
> said:
> 
>> On Sat, 19 Apr 2008 04:45:54 +, Ivan Illarionov wrote:
>> 
>>> On Fri, 18 Apr 2008 22:30:45 -0500, Grant Edwards wrote:
>>> 
 On 2008-04-18, Bob Greschke <[EMAIL PROTECTED]> wrote:
 
> However, in playing around with your suggestion and Grant's code I've
> found that the struct stuff is WAY slower than doing something like
> this
> 
> Value = (ord(Buf[s])*65536)+(ord(Buf[s+1])*256)+ord(Buf[s+2]) if
> Value
>> = 0x80:
> Value -= 0x100
> 
> This is almost twice as fast just sitting here grinding through a few
> hundred thousand conversions (like 3sec vs. ~5secs just counting on my
> fingers - on an old Sun...it's a bit slow).  Replacing *65536 with
> <<16 and *256 with <<8 might even be a little faster, but it's too
> close to call without really profiling it.
 
 I didn't know speed was important.  This might be a little faster
 (depending on hardware):
 
 Value = (ord(Buf[s])<<16) | (ord(Buf[s+1])<<8) | ord(Buf[s+2])
 
 It also makes the intention a bit more obvious (at least to me).
 
 A decent C compiler will recognize that <<16 and <<8 are special and
 just move bytes around rather than actually doing shifts.  I doubt the
 Python compiler does optimizations like that, but shifts are still
 usually faster than multiplies (though, again, a good compiler will
 recognize that multiplying by 65536 is the same as shifting by 16 and
 just move bytes around).
>>> 
>>> So why not put it in C extension?
>>> 
>>> It's easier than most people think:
>>> 
>>> 
>>> from3bytes.c
>>> 
>>> #include 
>>> 
>>> PyObject*
>>> from3bytes(PyObject* self, PyObject* args) {
>>> const char * s;
>>> int len;
>>> if (!PyArg_ParseTuple(args, "s#", &s, &len))
>>> return NULL;
>>> long n = (s[0]<<16) | (s[1]<<8) | s[2]; if (n >= 0x80)
>>> n -= 0x100;
>>> return PyInt_FromLong(n);
>>> }
>>> 
>>> static PyMethodDef functions[] = {
>>> {"from3bytes",(PyCFunction)from3bytes, METH_VARARGS}, {NULL,
>>> NULL, 0, NULL},
>>> };
>>> 
>>> 
>>> DL_EXPORT(void)
>>> init_from3bytes(void)
>>> {
>>> Py_InitModule("_from3bytes", functions);
>>> }
>>> 
>>> buildme.py
>>> ==
>>> import os
>>> import sys
>>> from distutils.core import Extension, setup
>>> 
>>> os.chdir(os.path.dirname(os.path.abspath(__file__))) sys.argv =
>>> [sys.argv[0], 'build_ext', '-i'] setup(ext_modules =
>>> [Extension('_from3bytes', ['from3bytes.c'])]) 
>>> 
>>> 'python buildme.py' will create '_from3bytes.so' file 'from _from3bytes
>>> import from3bytes' will import C-optimized function
>>> 
>>> Hope this helps.
>> 
>> Sorry,
>> the right code should be:
>> 
>> PyObject* from3bytes(PyObject* self, PyObject* args)
>> {
>> const char * s;
>> int len;
>> if (!PyArg_ParseTuple(args, "s#", &s, &len))
>> return NULL;
>> long n = unsigned char)s[0])<<16) | (((unsigned
>> char)s[1])<<8) |
>> ((unsigned char)s[2]));
>> if (n >= 0x80)
>> n -= 0x100;
>> return PyInt_FromLong(n);
>> }
> 
> No thanks.  Being able to alter and install these programs on whatever
> computer they are installed on is more important than speed.  I went
> down the C-extension path years ago and it turned into a big mess.
> Everything has to run on Sun's, Mac's, Linux and Windows without any
> major hassels if they have to be changed.  I can't reley on everything
> the program needs to be rebuilt being installed beyond Python and
> Tkinter (and pySerial and PIL for a couple of programs), which they
> need to run.  So no compiling and everything is in one file, in case a
> new version has to be upgraded by a user by emailing it to them while
> they're sitting on some mountain in Tibet.  Just unzip, stick the .py
> somewhere logical, (usually) double-click, and they are off and running.
> 
> Bob

Just for fun, here's a way to convert lots of 3-byte integers using PIL:

from PIL import Image
import array

def int3_pil(s, trafo="\x00"*128+"\xff"*128):
n = len(s)//3
im = Image.new("RGB", (n, 1))
im.fromstring(s)
hi, mid, lo = im.split()
sign = Image.new("L", (n, 1))
sign.fromstring(hi.tostring().translate(trafo))
im = Image.merge("RGBA", (lo, mid, hi, sign))
a = array.array("i")
a.fromstring(im.tostring())
return a.tolist()

Not as fast as I had hoped, though. Also, it needs some work to make it
independent of the processor architecture.  

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


Re: Checking if a text file is blank

2008-04-20 Thread prashanth
Hi

[EMAIL PROTECTED] wrote:
> Greetings!
> 
>  Is there any way in python to check if a text file is blank?


obviously there are many ways, one simple way is to check length if its 
None then the file is blank.


> 
> What I've tried to do so far is:
> 
> f = file("friends.txt", "w")
>   if f.read() is True:
>   """do stuff"""
>   else:
>   """do other stuff"""
>   f.close()

If checking the file is blank is what you are tying to do then why do 
you open the file in the write mode.




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


Re: from __future__ import print

2008-04-20 Thread Lie
On Apr 13, 7:23 pm, Roy Smith <[EMAIL PROTECTED]> wrote:
> In article
> <[EMAIL PROTECTED]>,
>
>  Lie <[EMAIL PROTECTED]> wrote:
> >  I wish py3k
> > would make it an option whether to treat print as statement or
> > function though.
>
> Arrrggh!  No, don't even go there.  If you want optional parens, use
> Perl :-)

Not optional parens, but a simple print statement coupled with a
powerful print function. This print statement would only have basic
printing functionality such as :

print "Hello"
print var
print var, "Hello too"

specifically, these would be removed:
print var,
print >> unstdout, var

This is because it is sometimes annoying to type this:
print("Hello")
print("World")
print("This")
print("is")
print("Captain")
print("Kirk")

because of the double enclosement (parens () and quotes ""),
especially when you're just slipping a simple debugging statement.

This also eases transition between older codes, because while you uses
regular print statements everyday, you don't do print redirection and
comma-ended printing everyday, and it would be easier to just convert
those advanced printing functionality rather than converting all
printing statements.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any reliable obfurscator for Python 2.5

2008-04-20 Thread David
On Sun, Apr 20, 2008 at 6:55 AM, Banibrata Dutta
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> Wanted to check if there is any known, reliable, FOSS/Libre -- Obfurscator
> for Python 2.5 code.
>

What might work is to put all your code in python modules, generate
.pyc, and then only distribute those. But you have to be careful that
eg: target python interpreter version is the same that you compiled
with and so on.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Help needed - I don't understand how Python manages memory"

2008-04-20 Thread Hank @ITGroup
Apology for the previous offensive title~~
:)
Thanks, Rintsch, Arnaud and Daniel, for replying so soon.

I redid the experiment. What following is the record -

``starting python``# == Windows Task Manager: 
Python.exe  *4,076 *K memory-usage ==
 >>> st1='abcdefg'*99 # == 10,952 K ==
 >>> del st1 # == *4,104*K ==
 >>> st1='abcdefg'*99 # == 10,952 K ==
 >>> del st1 # == 4,104 K ==

 >>> li = ['abcde']*99  # == 8,024 K ==
 >>> del li# == *4,108* K ==

 >>> from nltk import FreqDist # == 17,596 ==
 >>> fd = FreqDist()# == 17,596 ==
 >>> for i in range(99):fd.inc(i)  # == 53,412 ==
 >>> del fd   # == *28,780* ==
 >>> fd2 = FreqDist()   # == 28,780 ==
 >>> for i in range(99):fd2.inc(i)  # == 53,412 ==
 >>> del fd2# == 28,780 K ==

 >>> def foo():
... fd3 = FreqDist()
... for i in range(99):fd3.inc(i)

 >>>  foo() # == *28,788* K ==

 >>> def bar():
... fd4 = FreqDist()
... for i in range(99):fd4.inc(i)
... del fd4
 # == 28,788 K ==
 >>> bar() # == 28,788 K ==


That is my question, after ``del``, sometimes the memory space returns 
back as nothing happened, sometimes not... ...
What exactly was happening???

Best regards to all PYTHON people ~~
!!! Python Team are great !!!

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


Re: from __future__ import print

2008-04-20 Thread Diez B. Roggisch
Lie schrieb:
> On Apr 13, 7:23 pm, Roy Smith <[EMAIL PROTECTED]> wrote:
>> In article
>> <[EMAIL PROTECTED]>,
>>
>>  Lie <[EMAIL PROTECTED]> wrote:
>>>  I wish py3k
>>> would make it an option whether to treat print as statement or
>>> function though.
>> Arrrggh!  No, don't even go there.  If you want optional parens, use
>> Perl :-)
> 
> Not optional parens, but a simple print statement coupled with a
> powerful print function. This print statement would only have basic
> printing functionality such as :
> 
> print "Hello"
> print var
> print var, "Hello too"
> 
> specifically, these would be removed:
> print var,
> print >> unstdout, var
> 
> This is because it is sometimes annoying to type this:
> print("Hello")
> print("World")
> print("This")
> print("is")
> print("Captain")
> print("Kirk")

You are aware that it is only one character more to type?

It is debatable if print should have gone or not - but once you decide 
to have a print-statement I fail to see why you want to rid it of 
functionality. The costs for a keyword and special parsing rules are 
paid anyway then.

Diez

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


Re: Any reliable obfurscator for Python 2.5

2008-04-20 Thread Banibrata Dutta
On 4/20/08, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
>
> En Sun, 20 Apr 2008 01:55:51 -0300, Banibrata Dutta <
> [EMAIL PROTECTED]> escribió:
>
> > Wanted to check if there is any known, reliable, FOSS/Libre --
> Obfurscator
> > for Python 2.5 code.
>
> Why do you want to do that in the first place?


I need to do to retain the confidentiality for certain core components,
which are not supposed to be open. While I do have the option of
implementing them in C/C++, I'm trying to see if I can avoid that for 2
reasons --
1. Its a fairly large and complex set of components, and doing it in C/C++
'might' take significantly longer.
2. I'd try to avoid having mix of languages if possible. It makes the
developement easier to maintain/manage over a period of time.

There is very few you can do to obfuscate Python code. You can't rename
> classes nor methods nor global variables nor argument names due to the
> dynamic nature of Python. All you can safely do is to remove comments and
> join simple statements using ;


I do not understand the nuances of dynamic languages completely, so this
might be a foolish assumption, but if i make a complete, self-contained
Python application (collection of modules), then just before shipping a
production copy, why can't I replace 'all' symbols i.e. classes, methods,
variables etc ? Esply if I'm compiling the source ?

If you remove docstrings, some things may break. Even renaming local
> variables isn't safe in all cases.


Hmmm... but I'm aware of atleast 2 Obfuscators one commercial and one FOSS,
that seem to exist for Python. The commercial one is what I might try if I
don't find anything FOSS. The FOSS one seems to be a dead project. If they
are (or have been) there, I guess obfuscation is a doable thing, no ?

cheers,
B








































































































































































































































































































































































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



-- 
regards,
Banibrata
http://www.linkedin.com/in/bdutta
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: codec for html/xml entities!?

2008-04-20 Thread Martin Bless
[Stefan Behnel] wrote & schrieb:

>Martin Bless wrote:
>> What's a good way to encode and decode those entities like € or
>> € ?
>
>Hmm, since you provide code, I'm not quite sure what your actual question is.

- What's a GOOD way?
- Am I reinventing the wheel?
- Are there well tested, fast, state of the art, builtin ways?
- Is something like line.decode('htmlentities') out there?
- Am I in conformity with relevant RFCs? (I'm hoping so ...)

>So I'll just comment on the code here.
>
>
>> def entity2uc(entity):
>> """Convert entity like { to unichr.
>> 
>> Return (result,True) on success or (input string, False)
>> otherwise. Example:
>> entity2cp('€')   -> (u'\u20ac',True)
>> entity2cp('€') -> (u'\u20ac',True)
>> entity2cp('€')  -> (u'\u20ac',True)
>> entity2cp('&foobar;') -> ('&foobar;',False)
>> """
>
>Is there a reason why you return a tuple instead of just returning the
>converted result and raising an exception if the conversion fails?

Mainly a matter of style. When I'll be using the function in future
this way it's unambigously clear that there might have been
unconverted entities. But I don't have to deal with the details of how
this has been discovered. And may be I'd like to change the algorithm
in future? This way it's nicely encapsulated.

Have a nice day

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


Re: "Help needed - I don't understand how Python manages memory"

2008-04-20 Thread Marc 'BlackJack' Rintsch
On Sun, 20 Apr 2008 22:46:37 +1000, Hank @ITGroup wrote:

> Apology for the previous offensive title~~
> :)
> Thanks, Rintsch, Arnaud and Daniel, for replying so soon.
> 
> I redid the experiment. What following is the record -
> 
> ``starting python``# == Windows Task Manager: 
> Python.exe  *4,076 *K memory-usage ==
>  >>> st1='abcdefg'*99 # == 10,952 K ==
>  >>> del st1 # == *4,104*K ==
>  >>> st1='abcdefg'*99 # == 10,952 K ==
>  >>> del st1 # == 4,104 K ==
> 
>  >>> li = ['abcde']*99  # == 8,024 K ==
>  >>> del li# == *4,108* K ==
> 
>  >>> from nltk import FreqDist # == 17,596 ==
>  >>> fd = FreqDist()# == 17,596 ==
>  >>> for i in range(99):fd.inc(i)  # == 53,412 ==
>  >>> del fd   # == *28,780* ==
>  >>> fd2 = FreqDist()   # == 28,780 ==
>  >>> for i in range(99):fd2.inc(i)  # == 53,412 ==
>  >>> del fd2# == 28,780 K ==
> 
>  >>> def foo():
> ... fd3 = FreqDist()
> ... for i in range(99):fd3.inc(i)
> 
>  >>>  foo() # == *28,788* K ==
> 
>  >>> def bar():
> ... fd4 = FreqDist()
> ... for i in range(99):fd4.inc(i)
> ... del fd4
>  # == 28,788 K ==
>  >>> bar() # == 28,788 K ==
> 
> 
> That is my question, after ``del``, sometimes the memory space returns 
> back as nothing happened, sometimes not... ...
> What exactly was happening???

Something.  Really it's a bit complex and implementation dependent.  Stop
worrying about it until it really becomes a problem.

First of all there's no guarantee that memory will be reported as free by
the OS because it is up to the C runtime library if it "gives back" freed
memory to the OS or not.  Second the memory management of Python involves
"arenas" of objects that only get freed when all objects in it are freed. 
Third some types and ranges of objects get special treatment as integers
that are allocated, some even preallocated and never freed again.  All
this is done to speed things up because allocating and deallocating loads
of small objects is an expensive operation.

Bottom line: let the Python runtime manage the memory and forget about the
``del`` keyword.  It is very seldom used in Python and if used then to
delete a reference from a container and not "bare" names.  In your `bar()`
function it is completely unnecessary for example because the name `fd4`
disappears right after that line anyway.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Another MySQL Images Question

2008-04-20 Thread Steve Holden
Dennis Lee Bieber wrote:
> On Sat, 19 Apr 2008 03:46:54 +0200, Karl-Heinz Ruskowski
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
> 
>> Hi, 
>>
>>>   cursor.execute('update products set pic1="%s" where id="%s", ;',
>>> (pic1, id))
>> Shouldn't it be something like 
>> cursor.execute('update products set pic1="%s" where id="%s", ;' % (pic1, id))
> 
>   It should be NEITHER...
> 
>   The latter is relying on Python to fill in the parameters. The
> former is relying (preferred) for the DB-API adapter to correctly format
> the parameters (It is a coincidence that MySQLdb internally uses Python
> % formatting, so the place holders are %s, where others use ?)
> 
>   To be fully compliant it should be
> 
>   cursor.execute("update products set pic1=%s where id=%s",
>   (pic1, id))
> 
> NOTE: no trailing ,
>   no trailing ;
>   no embedded "   -- the DB-API spec is that IT will 
> properly
> supply whatever quotes or escapes are needed to ensure the data
> fits the syntax. This is also why most will not function if one tries to
> make the table or field names parameters -- the DB-API will quote them
> too, and
> 
>   update "products" set "pic1" = "something"
> 
> is much different from
> 
>   update products set pic1="something"
> 

Many versions of SQL do actually allow you to quote table names, 
allowing names with otherwise illegal characters like spaces in them. 
Double-quotes are typically used for such quoting (though Microsoft, to 
be different, tends to use brackets).

Single-quotes should be used for string literals, although certain 
sloppy implementations of SQL do also allow double-quotes.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Any reliable obfurscator for Python 2.5

2008-04-20 Thread Steve Holden
Banibrata Dutta wrote:
> 
> 
> On 4/20/08, *Gabriel Genellina* <[EMAIL PROTECTED] 
> > wrote:
> 
> En Sun, 20 Apr 2008 01:55:51 -0300, Banibrata Dutta
> <[EMAIL PROTECTED] > escribió:
> 
>  > Wanted to check if there is any known, reliable, FOSS/Libre --
> Obfurscator
>  > for Python 2.5 code.
> 
> Why do you want to do that in the first place?
> 
>  
> I need to do to retain the confidentiality for certain core components, 
> which are not supposed to be open. While I do have the option of 
> implementing them in C/C++, I'm trying to see if I can avoid that for 2 
> reasons --
> 1. Its a fairly large and complex set of components, and doing it in 
> C/C++ 'might' take significantly longer.
> 2. I'd try to avoid having mix of languages if possible. It makes the 
> developement easier to maintain/manage over a period of time.
> 
> There is very few you can do to obfuscate Python code. You can't
> rename classes nor methods nor global variables nor argument names
> due to the dynamic nature of Python. All you can safely do is to
> remove comments and join simple statements using ;
> 
>  
> I do not understand the nuances of dynamic languages completely, so this 
> might be a foolish assumption, but if i make a complete, self-contained 
> Python application (collection of modules), then just before shipping a 
> production copy, why can't I replace 'all' symbols i.e. classes, 
> methods, variables etc ? Esply if I'm compiling the source ?
> 
> If you remove docstrings, some things may break. Even renaming local
> variables isn't safe in all cases.
> 
>  
> Hmmm... but I'm aware of atleast 2 Obfuscators one commercial and one 
> FOSS, that seem to exist for Python. The commercial one is what I might 
> try if I don't find anything FOSS. The FOSS one seems to be a dead 
> project. If they are (or have been) there, I guess obfuscation is a 
> doable thing, no ?
>  
The Python world isn't particularly paranoid about obfuscation. It's 
quite easy to publish compiled code only (.pyc and/or .pyo files), and 
that offers enough protection for most.

The sad fact is that there seems to be an almost direct inverse 
correlation between the worth of the code and the authors' desire to 
protect it from piracy.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: from __future__ import print

2008-04-20 Thread Roy Smith
"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:

> You are aware that it is only one character more to type?

I'm not arguing for print vs. print(), but I do want to comment on the 
"character count" argument.

I'm a pretty good typist, the result of having been forced in junior high 
school (in the mid 70's) to learn typing the "right way" -- on a typewriter 
with blank keycaps.  It forced you to really learn to touch-type.  I don't 
know if this was some touchy-feely idea that if they girls had to learn to 
type (after all, they were all going to be secretaries) then it's only fair 
to make the boys learn it too.  Or, if they were just amazingly prescient 
about computers taking over the world and typing becoming an important 
high-tech skill.  Either way, I learned to touch type.

That being said, hitting the space bar is pretty much a freebie.  You can 
do it with either thumb(*), and you don't have to move your fingers from 
the home row.  To get the ( and ), you have to reach way up to the top row 
with one hand and down hit the shift key with the opposite pinkie.  A much 
costlier operation in terms of maintaining a good typing speed.

On the other hand, it's a well known (or at least well believed :-)) fact 
that code is read many more times than it's written.  Making something 
easier to read is much more important than making it easy to type.

(*) Oddly enough, as I type this and pay attention to what my fingers are 
doing, I find that I almost exclusively use the *left* thumb, which I never 
noticed before.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: codec for html/xml entities!?

2008-04-20 Thread Stefan Behnel
Martin Bless wrote:
> [Stefan Behnel] wrote & schrieb:
>>> def entity2uc(entity):
>>> """Convert entity like { to unichr.
>>>
>>> Return (result,True) on success or (input string, False)
>>> otherwise. Example:
>>> entity2cp('€')   -> (u'\u20ac',True)
>>> entity2cp('€') -> (u'\u20ac',True)
>>> entity2cp('€')  -> (u'\u20ac',True)
>>> entity2cp('&foobar;') -> ('&foobar;',False)
>>> """
>> Is there a reason why you return a tuple instead of just returning the
>> converted result and raising an exception if the conversion fails?
> 
> Mainly a matter of style. When I'll be using the function in future
> this way it's unambigously clear that there might have been
> unconverted entities. But I don't have to deal with the details of how
> this has been discovered. And may be I'd like to change the algorithm
> in future? This way it's nicely encapsulated.

The normal case is that it could be replaced, and it is an exceptional case
that it failed, in which case the caller has to deal with the problem in one
way or another. You are making the normal case more complicated, as the caller
*always* has to check the result indicator to see if the return value is the
expected result or something different. I don't think there is any reason to
require that, except when the conversion really failed.

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


Re: "Help needed - I don't understand how Python manages memory"

2008-04-20 Thread sturlamolden
On Apr 20, 2:46 pm, "Hank @ITGroup" <[EMAIL PROTECTED]> wrote:

> That is my question, after ``del``, sometimes the memory space returns
> back as nothing happened, sometimes not... ...
> What exactly was happening???

Python has a garbage collector. Objects that cannot be reached from
any scope is reclaimed, sooner or later. This includes objects with
reference count of zero, or objects that participate in unreachable
reference cycles. Since Python uses a reference counting scheme, it
does not tend to accumulate so much garbage as Java or .NET. When the
reference count for an object drops to zero, it is immediately freed.

You cannot control when Python's garbage collector frees an object
from memory.

What del does is to delete the object reference from the current
scope. It does not delete the object from memory. That is, the del
statement decrements the reference count by one, and removes the
reference from the current scope. Whether it should removed completely
depends on whether someone else is using it. The object is not
reclaimed unless the reference count has dropped all the way down to
zero. If there still are references to the object other places in your
program, it is not reclaimed upon your call to del.





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


Re: "Help needed - I don't understand how Python manages memory"

2008-04-20 Thread Steve Holden
Hank @ITGroup wrote:
> Apology for the previous offensive title~~
> :)
> Thanks, Rintsch, Arnaud and Daniel, for replying so soon.
> 
> I redid the experiment. What following is the record -
> 
> ``starting python``# == Windows Task Manager: 
> Python.exe  *4,076 *K memory-usage ==
>  >>> st1='abcdefg'*99 # == 10,952 K ==
>  >>> del st1 # == *4,104*K ==
>  >>> st1='abcdefg'*99 # == 10,952 K ==
>  >>> del st1 # == 4,104 K ==
> 
>  >>> li = ['abcde']*99  # == 8,024 K ==
>  >>> del li# == *4,108* K ==
> 
>  >>> from nltk import FreqDist # == 17,596 ==
>  >>> fd = FreqDist()# == 17,596 ==
>  >>> for i in range(99):fd.inc(i)  # == 53,412 ==
>  >>> del fd   # == *28,780* ==
>  >>> fd2 = FreqDist()   # == 28,780 ==
>  >>> for i in range(99):fd2.inc(i)  # == 53,412 ==
>  >>> del fd2# == 28,780 K ==
> 
>  >>> def foo():
> ... fd3 = FreqDist()
> ... for i in range(99):fd3.inc(i)
> 
>  >>>  foo() # == *28,788* K ==
> 
>  >>> def bar():
> ... fd4 = FreqDist()
> ... for i in range(99):fd4.inc(i)
> ... del fd4
>  # == 28,788 K ==
>  >>> bar() # == 28,788 K ==
> 
> 
> That is my question, after ``del``, sometimes the memory space returns 
> back as nothing happened, sometimes not... ...
> What exactly was happening???
> 
> Best regards to all PYTHON people ~~
> !!! Python Team are great !!!
> 
It doesn't really make that much sense to watch memory usage as you have 
been doing. Your first test case appears to trigger a specific 
pathology, where the memory allocator actually returns the memory to the 
operating system when the garbage collector manages to free all of it.

Most often this doesn't happen - a chunk of memory might be 99.99% free 
but still have one small piece used, and so while there is a large 
amount of "free" memory for Python to allocate without requesting more 
process memory, this won't be reflected in any external measurement.

You are suffering from a pathological condition yourself: the desire to 
optimize performance in an area where you do not have any problems. I 
would suggest you just enjoy using Python (its memory management doesn't 
suck at all, so your title line was inflammatory and simply highlights 
your lack of knowledge) and then start to ask these questions again when 
you have a real issue that's stopping you from getting real work done.

regards
  Steve

-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


deer hunter 2005 crack

2008-04-20 Thread medin0065
deer hunter 2005 crack

http://cracks.00bp.com


F
R
E
E


C
R
A
C
K
S
-- 
http://mail.python.org/mailman/listinfo/python-list


band patch

2008-04-20 Thread medin0065
band patch

http://cracks.00bp.com


F
R
E
E


C
R
A
C
K
S
-- 
http://mail.python.org/mailman/listinfo/python-list


police shoulder patch trade

2008-04-20 Thread medin0065
police shoulder patch trade

http://cracks.00bp.com


F
R
E
E


C
R
A
C
K
S
-- 
http://mail.python.org/mailman/listinfo/python-list


cracked vacuum line heater

2008-04-20 Thread medin0065
cracked vacuum line heater

http://cracks.00bp.com


F
R
E
E


C
R
A
C
K
S
-- 
http://mail.python.org/mailman/listinfo/python-list


nero full version crack

2008-04-20 Thread medin0065
nero full version crack

http://cracks.00bp.com


F
R
E
E


C
R
A
C
K
S
-- 
http://mail.python.org/mailman/listinfo/python-list


active camera crack

2008-04-20 Thread medin0065
active camera crack

http://cracks.00bp.com


F
R
E
E


C
R
A
C
K
S
-- 
http://mail.python.org/mailman/listinfo/python-list


divx keygen

2008-04-20 Thread medin0065
divx keygen

http://cracks.00bp.com


F
R
E
E


C
R
A
C
K
S
-- 
http://mail.python.org/mailman/listinfo/python-list


xbox patch

2008-04-20 Thread medin0065
xbox patch

http://cracks.00bp.com


F
R
E
E


C
R
A
C
K
S
-- 
http://mail.python.org/mailman/listinfo/python-list


dark crusade patch 1.2

2008-04-20 Thread medin0065
dark crusade patch 1.2

http://cracks.00bp.com


F
R
E
E


C
R
A
C
K
S
-- 
http://mail.python.org/mailman/listinfo/python-list


silverfall patch

2008-04-20 Thread medin0065
silverfall patch

http://cracks.00bp.com


F
R
E
E


C
R
A
C
K
S
-- 
http://mail.python.org/mailman/listinfo/python-list


vuescan 8.4.13 crack

2008-04-20 Thread medin0065
vuescan 8.4.13 crack

http://cracks.00bp.com


F
R
E
E


C
R
A
C
K
S
-- 
http://mail.python.org/mailman/listinfo/python-list


diner dash 3 crack

2008-04-20 Thread medin0065
diner dash 3 crack

http://cracks.00bp.com


F
R
E
E


C
R
A
C
K
S
-- 
http://mail.python.org/mailman/listinfo/python-list


nikon lightroom crack

2008-04-20 Thread medin0065
nikon lightroom crack

http://cracks.00bp.com


F
R
E
E


C
R
A
C
K
S
-- 
http://mail.python.org/mailman/listinfo/python-list


anachronox patch

2008-04-20 Thread medin0065
anachronox patch

http://cracks.00bp.com


F
R
E
E


C
R
A
C
K
S
-- 
http://mail.python.org/mailman/listinfo/python-list


prevx1 crack

2008-04-20 Thread medin0065
prevx1 crack

http://cracks.00bp.com


F
R
E
E


C
R
A
C
K
S
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python setup.py install on Vista?

2008-04-20 Thread Martin v. Löwis
> It seems that quite a lot of people wondered why python doesn't set
> the environment variable to Python Path in the default installation.

For several reasons, one being that it's not needed. Just run setup.py
as a program, i.e. don't do

python setup.py install

but instead do

setup.py install

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


Re: Any reliable obfurscator for Python 2.5

2008-04-20 Thread JB Stern
Banibrata Dutta wrote:
>>Wanted to check if there is any known, reliable, FOSS/Libre -- Obfurscator
>> for Python 2.5 code.

No, sadly, there is not.  There are a number of applications I would be
working on if it were possible to obfuscate pyc files.  About the best
you can do as of 2008/04 is use Jython to compile into Java bytecode and
obfuscate that using Proguard.

Steve 'not an economics major' Holden wrote:
>The Python world isn't particularly paranoid about obfuscation. It's 
>quite easy to publish compiled code only (.pyc and/or .pyo files), and 
>that offers enough protection for most.

Curious Steve, how do you pay the rent and by what authority do you
speak for "The Python world"?  Your opinion couldn't be more wrong for
programmers like myself who live by the code they write (as opposed to
its support).

Steve 'not a software consultant' Holden wrote:
>The sad fact is that there seems to be an almost direct inverse 
>correlation between the worth of the code and the authors' desire to 
>protect it from piracy.

Would love to see some evidence to that effect.  

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


Alternate indent proposal for python 3000

2008-04-20 Thread Eric Wertman
I was considering putting together a proposal for an alternate block
syntax for python, and I figured I'd post it here and see what the
general reactions are.  I did some searching, and while I found a lot
of tab vs space debates, I didn't see anything like what I'm thinking
of, so forgive me if this is a very dead horse.

Generally speaking, I like the current block scheme just fine.  I use
python on a daily basis for system administration and text parsing
tasks, and it works great for me.

>From time to time, though, I find myself needing a language for server-
side includes in web pages.  Because of the need to indent (and
terminate indents), python seems an awkward choice for this, and it's
easy for me to see why php and perl are more popular choices for this
kind of task.  Perhaps this is just my perception though.

I feel that including some optional means to block code would be a big
step in getting wider adoption of the language in web development and
in general.  I do understand though, that the current strict indenting
is part of the core of the language, so... thoughts?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any reliable obfurscator for Python 2.5

2008-04-20 Thread Gabriel Genellina
En Sun, 20 Apr 2008 10:32:36 -0300, Banibrata Dutta <[EMAIL PROTECTED]> 
escribió:

> On 4/20/08, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
>>
>> En Sun, 20 Apr 2008 01:55:51 -0300, Banibrata Dutta <
>> [EMAIL PROTECTED]> escribió:
>>
>> > Wanted to check if there is any known, reliable, FOSS/Libre --
>> Obfurscator
>> > for Python 2.5 code.
>>
>> Why do you want to do that in the first place?
>
>
> I need to do to retain the confidentiality for certain core components,
> which are not supposed to be open. While I do have the option of
> implementing them in C/C++, I'm trying to see if I can avoid that for 2
> reasons --
> 1. Its a fairly large and complex set of components, and doing it in C/C++
> 'might' take significantly longer.
> 2. I'd try to avoid having mix of languages if possible. It makes the
> developement easier to maintain/manage over a period of time.
>
> There is very few you can do to obfuscate Python code. You can't rename
>> classes nor methods nor global variables nor argument names due to the
>> dynamic nature of Python. All you can safely do is to remove comments and
>> join simple statements using ;
>
>
> I do not understand the nuances of dynamic languages completely, so this
> might be a foolish assumption, but if i make a complete, self-contained
> Python application (collection of modules), then just before shipping a
> production copy, why can't I replace 'all' symbols i.e. classes, methods,
> variables etc ? Esply if I'm compiling the source ?

Because *any* string can be used to retrieve an attribute, it is not easy to 
replace *every* occurence of an attribute name (the code may use arbitrary 
expressions with getattr). The code may contain external references to class 
names (e.g. pickles, logging config files) that must be kept; also code that 
uses exec/eval will not find the referenced objects. Even local names are 
necesary in some cases like "%(some)s %(format)d" % locals().

> If you remove docstrings, some things may break. Even renaming local
>> variables isn't safe in all cases.
>
> Hmmm... but I'm aware of atleast 2 Obfuscators one commercial and one FOSS,
> that seem to exist for Python. The commercial one is what I might try if I
> don't find anything FOSS. The FOSS one seems to be a dead project. If they
> are (or have been) there, I guess obfuscation is a doable thing, no ?

Sure, it can be done - with a lot of care, and I'm sure *some* code will fail. 
You may distribute compiled .pyc files - that's enough for most people who 
cares at all. Paranoids use a modified version of the interpreter incompatible 
with the standard one.
In any case, bug reports (including tracebacks) are less valuable and harder to 
read.

-- 
Gabriel Genellina

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


Re: Alternate indent proposal for python 3000

2008-04-20 Thread Christian Heimes
Eric Wertman schrieb:
> I was considering putting together a proposal for an alternate block
> syntax for python, and I figured I'd post it here and see what the
> general reactions are.  I did some searching, and while I found a lot
> of tab vs space debates, I didn't see anything like what I'm thinking
> of, so forgive me if this is a very dead horse.

You are definitely too late to propose a change for py3k.

> I feel that including some optional means to block code would be a big
> step in getting wider adoption of the language in web development and
> in general.  I do understand though, that the current strict indenting
> is part of the core of the language, so... thoughts?

Why should Python repeat the mistakes other languages did with SSI or
 inline code? Python favors the MVC separation of code and layout.

Christian

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


Re: Alternate indent proposal for python 3000

2008-04-20 Thread George Sakkis
On Apr 20, 11:35 am, Eric Wertman <[EMAIL PROTECTED]> wrote:

> I was considering putting together a proposal for an alternate block
> syntax for python, and I figured I'd post it here and see what the
> general reactions are.  I did some searching, and while I found a lot
> of tab vs space debates, I didn't see anything like what I'm thinking
> of, so forgive me if this is a very dead horse.

[with apologies to Monty Python]

This horse is no more! He has ceased to be! 'E's expired and gone to
meet 'is maker! 'E's a stiff! Bereft of life, 'e rests in peace! THIS
IS AN EX-HORSE!!

:)

> Generally speaking, I like the current block scheme just fine.  I use
> python on a daily basis for system administration and text parsing
> tasks, and it works great for me.
>
> From time to time, though, I find myself needing a language for server-
> side includes in web pages.  Because of the need to indent (and
> terminate indents), python seems an awkward choice for this, and it's
> easy for me to see why php and perl are more popular choices for this
> kind of task.  Perhaps this is just my perception though.

Look into any of the dozen Python-based template engines that are
typically used for such tasks; they offer many more features than a
way to indent blocks.

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


Re: prevx1 crack

2008-04-20 Thread Danyelle Gragsone
what the ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Help needed - I don't understand how Python manages memory"

2008-04-20 Thread Gabriel Genellina
En Sun, 20 Apr 2008 09:46:37 -0300, Hank @ITGroup <[EMAIL PROTECTED]> escribió:

> ``starting python``# == Windows Task Manager:
> Python.exe  *4,076 *K memory-usage ==
>  >>> st1='abcdefg'*99 # == 10,952 K ==
>  >>> del st1 # == *4,104*K ==
>  >>> st1='abcdefg'*99 # == 10,952 K ==
>  >>> del st1 # == 4,104 K ==
>
>  >>> li = ['abcde']*99  # == 8,024 K ==
>  >>> del li# == *4,108* K ==
>
>  >>> from nltk import FreqDist # == 17,596 ==
>  >>> fd = FreqDist()# == 17,596 ==
>  >>> for i in range(99):fd.inc(i)  # == 53,412 ==
>  >>> del fd   # == *28,780* ==
>  >>> fd2 = FreqDist()   # == 28,780 ==
>  >>> for i in range(99):fd2.inc(i)  # == 53,412 ==
>  >>> del fd2# == 28,780 K ==
>
>  >>> def foo():
> ... fd3 = FreqDist()
> ... for i in range(99):fd3.inc(i)
>
>  >>>  foo() # == *28,788* K ==
>
>  >>> def bar():
> ... fd4 = FreqDist()
> ... for i in range(99):fd4.inc(i)
> ... del fd4
>  # == 28,788 K ==
>  >>> bar() # == 28,788 K ==
>
>
> That is my question, after ``del``, sometimes the memory space returns
> back as nothing happened, sometimes not... ...
> What exactly was happening???

Apart from what everyone has already said, consider that FreqDist may import 
other modules, store global state, create other objects... whatever.
Pure python code should not have any memory leaks (if there are, it's a bug in 
the Python interpreter). Not-carefully-written C extensions may introduce 
memory problems.

-- 
Gabriel Genellina

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


Re: Alternate indent proposal for python 3000

2008-04-20 Thread Eric Wertman

> Look into any of the dozen Python-based template engines that are
> typically used for such tasks; they offer many more features than a
> way to indent blocks.
>
> George

I definitely will.. could you throw out some examples though?
Thanks!

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


Re: Alternate indent proposal for python 3000

2008-04-20 Thread Matthew Woodcraft
Christian Heimes  <[EMAIL PROTECTED]> wrote:
>> I feel that including some optional means to block code would be a big
>> step in getting wider adoption of the language in web development and
>> in general.  I do understand though, that the current strict indenting
>> is part of the core of the language, so... thoughts?

> Why should Python repeat the mistakes other languages did with SSI or
>  inline code? Python favors the MVC separation of code and layout.

An alternative scheme for describing the block structure could be
useful in other cases, though. For example, if you wanted to support
putting snippets of Python in configuration files, or spreadsheet
cells.

There's no need to support the new scheme in .py files, so it seems to
me that this doesn't have to be done in the core language. All that's
needed is a variant of 'eval' which expects the alternate scheme, and
that could be prototyped just using text manipulation and the normal
'eval'.

If someone wrote a library for this and it proved popular, I expect it
would be considered for the standard library.

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


Re: Alternate indent proposal for python 3000

2008-04-20 Thread Arnaud Delobelle
On Apr 20, 5:42 pm, Matthew Woodcraft
<[EMAIL PROTECTED]> wrote:
> Christian Heimes  <[EMAIL PROTECTED]> wrote:
>
> >> I feel that including some optional means to block code would be a big
> >> step in getting wider adoption of the language in web development and
> >> in general.  I do understand though, that the current strict indenting
> >> is part of the core of the language, so... thoughts?
> > Why should Python repeat the mistakes other languages did with SSI or
> >  inline code? Python favors the MVC separation of code and layout.
>
> An alternative scheme for describing the block structure could be
> useful in other cases, though. For example, if you wanted to support
> putting snippets of Python in configuration files, or spreadsheet
> cells.
>
> There's no need to support the new scheme in .py files, so it seems to
> me that this doesn't have to be done in the core language. All that's
> needed is a variant of 'eval' which expects the alternate scheme, and
> that could be prototyped just using text manipulation and the normal
> 'eval'.

By 'eval', I guess you mean 'exec' :)

--
Arnaud

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


Re: Checking if a text file is blank

2008-04-20 Thread evenrik
On Apr 20, 2:04 pm, [EMAIL PROTECTED] wrote:
> Greetings!
>
> I've just started learning python, so this is probably one of those
> obvious questions newbies ask.
>
> Is there any way in python to check if a text file is blank?
>
> What I've tried to do so far is:
>
> f = file("friends.txt", "w")
> if f.read() is True:
> """do stuff"""
> else:
> """do other stuff"""
> f.close()
>
> What I *mean* to do in the second line is to check if the text file is
> not-blank. But apparently that's not the way to do it.
>
> Could someone set me straight please?

I use os.path.getsize(path) for this purpose.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Alternate indent proposal for python 3000

2008-04-20 Thread Matthew Woodcraft
Arnaud Delobelle  <[EMAIL PROTECTED]> wrote:
> By 'eval', I guess you mean 'exec' :)

Yes. Shows how often I use either.

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


Re: Alternate indent proposal for python 3000

2008-04-20 Thread Terry Reedy

"Matthew Woodcraft" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| There's no need to support the new scheme in .py files, so it seems to
| me that this doesn't have to be done in the core language. All that's
| needed is a variant of 'eval' which expects the alternate scheme, and
| that could be prototyped just using text manipulation and the normal
| 'eval'.

Eval() is for expressions, exec() is for general code.  But you do not 
really need a variant.  Just define a preprocessor function 'blockify' 
which converts code in an alternate syntax to regular indented block 
syntax.  Then

exec(blockify(alt_code_string))

I presume that this is more or less what the templating engines do. 



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


Re: Alternate indent proposal for python 3000

2008-04-20 Thread Gabriel Genellina
En Sun, 20 Apr 2008 13:42:05 -0300, Matthew Woodcraft <[EMAIL PROTECTED]> 
escribió:

> An alternative scheme for describing the block structure could be
> useful in other cases, though. For example, if you wanted to support
> putting snippets of Python in configuration files, or spreadsheet
> cells.
> [...] If someone wrote a library for this and it proved popular, I expect it
> would be considered for the standard library.

There is "pindent.py" in the Tools/scripts directory:

# ... When called as "pindent -r" it assumes its input is a
# Python program with block-closing comments but with its indentation
# messed up, and outputs a properly indented version.

# A "block-closing comment" is a comment of the form '# end '
# where  is the keyword that opened the block ...

def foobar(a, b):
if a == b:
a = a+1
elif a < b:
b = b-1
if b > a: a = a-1
# end if
else:
print 'oops!'
# end if
# end def foobar

-- 
Gabriel Genellina

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


Re: Finally had to plonk google gorups.

2008-04-20 Thread Terry Reedy

"Gabriel Genellina" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
En Wed, 16 Apr 2008 14:23:57 -0300, Steve Holden <[EMAIL PROTECTED]> 
escribió:
> Torsten Bronger wrote:

>> The admistrative overhead of mailing lists is tedious.  Fortunately,
>> most important computer-related lists are on gmane.org.  We could
>> list c.l.py there, too.  ;-)
>>
> c.l.py has been on gmane for years, as comp.python.general (why they
> have to have their own naming hierarchy i have never understood).

Because "someone" chose that name when he/she asked for the list to be 
added; the name gmane.comp.lang.python *could* have been used, but wasn't.
(gmane uses its own hierarchy because not all mirrored lists exist as a 
newsgroup outside gmane, and there are potential name conflicts)
==

Gmane mirror mailing lists, not usenet newsgroups.  There are over 200 
gmane.comp.python.* groups.  As far as I know, only 2 are also regular 
newsgroups. c.l.p, and c.l.p.announce. and those only because they are 
first gatewayed to python.org mailing lists.  In other words, 
gmane.comp.python.general mirrors python-list @ python.org 



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

Re: "Help needed - I don't understand how Python manages memory"

2008-04-20 Thread Christian Heimes
Gabriel Genellina schrieb:
> Apart from what everyone has already said, consider that FreqDist may import 
> other modules, store global state, create other objects... whatever.
> Pure python code should not have any memory leaks (if there are, it's a bug 
> in the Python interpreter). Not-carefully-written C extensions may introduce 
> memory problems.

Pure Python code can cause memory leaks. No, that's not a bug in the
interpreter but the fault of the developer. For example code that messes
around with stack frames and exception object can cause nasty reference
leaks.

Christian

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


Re: Any reliable obfurscator for Python 2.5

2008-04-20 Thread Terry Reedy

"Banibrata Dutta" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| Hmmm... but I'm aware of atleast 2 Obfuscators one commercial and one 
FOSS,
| that seem to exist for Python. The commercial one is what I might try if 
I
| don't find anything FOSS. The FOSS one seems to be a dead project. If 
they
| are (or have been) there, I guess obfuscation is a doable thing, no ?

Given that a reliable obfuscator (not obfurscator) would be commercially 
valuable, why would you expect someone to give it away rather than 
obfuscate it, like you want to do with your code?  So go ahead and pay.

There are ways to make Python code truly obscure by turning it into pure 
functional code, but I do not know that this can be done algorithmicly, and 
the result is not something one would want to develop and maintain for 
anything more than toy examples.



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


Re: "Help needed - I don't understand how Python manages memory"

2008-04-20 Thread Gabriel Genellina
En Sun, 20 Apr 2008 14:43:17 -0300, Christian Heimes <[EMAIL PROTECTED]> 
escribió:

> Gabriel Genellina schrieb:
>> Apart from what everyone has already said, consider that FreqDist may import 
>> other modules, store global state, create other objects... whatever.
>> Pure python code should not have any memory leaks (if there are, it's a bug 
>> in the Python interpreter). Not-carefully-written C extensions may introduce 
>> memory problems.
>
> Pure Python code can cause memory leaks. No, that's not a bug in the
> interpreter but the fault of the developer. For example code that messes
> around with stack frames and exception object can cause nasty reference
> leaks.

Ouch!
May I assume that code that doesn't use stack frames nor stores references to 
exception objects/tracebacks is safe?

-- 
Gabriel Genellina

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


Re: "Help needed - I don't understand how Python manages memory"

2008-04-20 Thread Torsten Bronger
Hallöchen!

Gabriel Genellina writes:

> En Sun, 20 Apr 2008 14:43:17 -0300, Christian Heimes <[EMAIL PROTECTED]>
> escribió:
>
>> Gabriel Genellina schrieb:
>>
>>> Apart from what everyone has already said, consider that
>>> FreqDist may import other modules, store global state, create
>>> other objects... whatever.  Pure python code should not have any
>>> memory leaks (if there are, it's a bug in the Python
>>> interpreter). Not-carefully-written C extensions may introduce
>>> memory problems.
>>
>> Pure Python code can cause memory leaks. No, that's not a bug in
>> the interpreter but the fault of the developer. For example code
>> that messes around with stack frames and exception object can
>> cause nasty reference leaks.
>
> Ouch!
> May I assume that code that doesn't use stack frames nor stores
> references to exception objects/tracebacks is safe?

Circular referencing is no leaking on the C level but in a way it is
memory leaking, too.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
   (See http://ime.webhop.org for further contact info.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Help needed - I don't understand how Python manages memory"

2008-04-20 Thread Hank @ITGroup
Christian Heimes wrote:
> Gabriel Genellina schrieb:
>   
>> Apart from what everyone has already said, consider that FreqDist may import 
>> other modules, store global state, create other objects... whatever.
>> Pure python code should not have any memory leaks (if there are, it's a bug 
>> in the Python interpreter). Not-carefully-written C extensions may introduce 
>> memory problems.
>> 
>
> Pure Python code can cause memory leaks. No, that's not a bug in the
> interpreter but the fault of the developer. For example code that messes
> around with stack frames and exception object can cause nasty reference
> leaks.
>
> Christian
>
>   
In order to deal with 400 thousands texts consisting of 80 million 
words, and huge sets of corpora , I have to be care about the memory 
things. I need to track every word's behavior, so there needs to be as 
many word-objects as words.
I am really suffering from the memory problem, even 4G  memory space can 
not survive... Only 10,000 texts can kill it in 2 minutes.
By the way, my program has been optimized to ``del`` the objects after 
traversing, in order not to store the information in memory all the time.

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


Re: Any reliable obfurscator for Python 2.5

2008-04-20 Thread sturlamolden
On Apr 20, 5:28 pm, JB Stern <[EMAIL PROTECTED]> wrote:

> Curious Steve, how do you pay the rent and by what authority do you
> speak for "The Python world"?  Your opinion couldn't be more wrong for
> programmers like myself who live by the code they write (as opposed to
> its support).


Are you afraid to show the code to your customer? Are you afraid it
will give you a bad reputatio? Are you worried about loosing future
contracts? Is your code really that bad? Then you better keep it
hidden from sight.

If this is the case, my advice to you would be to find a different
profession. Perhaps flipping burgers at McDonald's fits your talent?

















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


Re: Alternate indent proposal for python 3000

2008-04-20 Thread Matthew Woodcraft
Terry Reedy <[EMAIL PROTECTED]> wrote:

> But you do not really need a variant.  Just define a preprocessor
> function 'blockify' which converts code in an alternate syntax to
> regular indented block syntax.  Then
>
> exec(blockify(alt_code_string))

You can do it like that, but if it were to become part of the standard
distribution it would be nice to avoid having to tokenise the code
twice. (You could define the new block scheme in such a way that
'blockify' doesn't need to tokenise, but I think it would end up a bit
ugly.)

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


Re: Any reliable obfurscator for Python 2.5

2008-04-20 Thread Steve Holden
JB "My first post on c.l.py" Stern wrote:
> Banibrata Dutta wrote:
>>> Wanted to check if there is any known, reliable, FOSS/Libre -- Obfurscator
>>> for Python 2.5 code.
> 
> No, sadly, there is not.  There are a number of applications I would be
> working on if it were possible to obfuscate pyc files.  About the best
> you can do as of 2008/04 is use Jython to compile into Java bytecode and
> obfuscate that using Proguard.
> 
> Steve 'not an economics major' Holden wrote:
>> The Python world isn't particularly paranoid about obfuscation. It's 
>> quite easy to publish compiled code only (.pyc and/or .pyo files), and 
>> that offers enough protection for most.
> 
> Curious Steve, how do you pay the rent and by what authority do you
> speak for "The Python world"?  Your opinion couldn't be more wrong for
> programmers like myself who live by the code they write (as opposed to
> its support).
> 
I pay the mortgage by creating software systems, though not usually 
packaged systems for shrink-wrap sale. I don't claim to speak *for* the 
whole Python world, but as chairman of the Python Software Foundation 
and a long-time member of this mailing list I can probably claim to be 
more closely in touch with it than many--yourself included, apparently.

If it's important to you to be able to obfuscate your code then you have 
made an inapposite choice of language.

> Steve 'not a software consultant' Holden wrote:
>> The sad fact is that there seems to be an almost direct inverse 
>> correlation between the worth of the code and the authors' desire to 
>> protect it from piracy.
> 
> Would love to see some evidence to that effect.  
> 
That is just an observation based on the many similar posts that have 
been made on this list, not one of them coming from the author of a 
recognized software package, plus forty years experience in the software 
industry. The ripping of of source code is far less frequent that novice 
programmers believe.

The code that novice programmers write is almost always less valuable 
than they believe.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Alternate indent proposal for python 3000

2008-04-20 Thread Eric Wertman
On Apr 20, 1:29 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Sun, 20 Apr 2008 13:42:05 -0300, Matthew Woodcraft <[EMAIL PROTECTED]> 
> escribió:
>
> > An alternative scheme for describing the block structure could be
> > useful in other cases, though. For example, if you wanted to support
> > putting snippets of Python in configuration files, or spreadsheet
> > cells.
> > [...] If someone wrote a library for this and it proved popular, I expect it
> > would be considered for the standard library.
>
> There is "pindent.py" in the Tools/scripts directory:
>
> # ... When called as "pindent -r" it assumes its input is a
> # Python program with block-closing comments but with its indentation
> # messed up, and outputs a properly indented version.
>
> # A "block-closing comment" is a comment of the form '# end '
> # where  is the keyword that opened the block ...
>
> def foobar(a, b):
> if a == b:
> a = a+1
> elif a < b:
> b = b-1
> if b > a: a = a-1
> # end if
> else:
> print 'oops!'
> # end if
> # end def foobar
>
> --
> Gabriel Genellina

That's actually not a lot different than what you have to do now in a
web page.. It still seems overcomplicated though.  I'm not sure why
this is worse:

def foobar(a, b):
if a == b:
a = a+1;
elif a < b:
b = b-1;
if b > a:
a = a-1;
else:
print 'oops!';;

It's just ultimately whitespace insensitive.  Whether that's a good or
bad design is a debate that can be argued either way, but other
languages do it, and it's handy sometimes.  I agree that it makes it
much easier to produce illegible code.  Developing for a browser is
arguably annoying and hackish enough, without having to stick in
comments and such to enforce indenting.



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


Re: "Help needed - I don't understand how Python manages memory"

2008-04-20 Thread Martin v. Löwis
> Pure Python code can cause memory leaks. No, that's not a bug in the
> interpreter but the fault of the developer. For example code that messes
> around with stack frames and exception object can cause nasty reference
> leaks.

Can you give an example, please?

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


Re: Any reliable obfurscator for Python 2.5

2008-04-20 Thread Roy Smith
In article 
<[EMAIL PROTECTED]>,
 sturlamolden <[EMAIL PROTECTED]> wrote:

> On Apr 20, 5:28 pm, JB Stern <[EMAIL PROTECTED]> wrote:
> 
> > Curious Steve, how do you pay the rent and by what authority do you
> > speak for "The Python world"?  Your opinion couldn't be more wrong for
> > programmers like myself who live by the code they write (as opposed to
> > its support).
> 
> 
> Are you afraid to show the code to your customer? Are you afraid it
> will give you a bad reputatio? Are you worried about loosing future
> contracts? Is your code really that bad? Then you better keep it
> hidden from sight.
> 
> If this is the case, my advice to you would be to find a different
> profession. Perhaps flipping burgers at McDonald's fits your talent?

Even if this were worded in a less rude manner, it would be a silly 
argument.  For many businesses, keeping their source code secret is 
important.  Whether you agree with their reasons or not, they feel it is 
important to them.

Hiding your source code is not easy (perhaps impossible) in Python, for 
reasons which have been covered at length on a regular basis in this forum.  
If you only ship .pyc or .pyo files, there is still enough information 
recoverable in the field that most businesses which want to keep their 
source code hidden would feel excessively exposed.

Producing software is all about using tools.  Every tool has advantages and 
disadvantages.  The key to using tools effectively is understanding what 
those are and how they impact your business.  If you are lucky, you will 
find a tool which meets your needs perfectly.  More often, you have to 
weigh all the factors and make the best compromise you can.

If keeping your source code secret is of critical importance to your 
business, then Python is probably the wrong tool to be using to write an 
application that you're going to ship to customers.  If keeping your source 
code secret is not important to you, that doesn't mean those who do 
consider it important are stupid, or evil, or better suited for a career 
spatially reorienting meat by-product patties at a popular restaurant 
chain.  They just have different needs than you do.
-- 
http://mail.python.org/mailman/listinfo/python-list


I would like to learn scripting in Python too!

2008-04-20 Thread Software Testing
Hello There,

I am a software tester and I see lot of testers on the forums saying Python
is a wonderful scripting language that testers use on a daily basis.

I would also like to learn to script in Python but I do not have any
programming background.

Please help

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

Re: "Help needed - I don't understand how Python manages memory"

2008-04-20 Thread Gabriel Genellina
En Sun, 20 Apr 2008 15:02:37 -0300, Torsten Bronger <[EMAIL PROTECTED]> 
escribió:
> Gabriel Genellina writes:
>> En Sun, 20 Apr 2008 14:43:17 -0300, Christian Heimes <[EMAIL PROTECTED]>
>> escribió:
>>> Gabriel Genellina schrieb:
>>>
 Apart from what everyone has already said, consider that
 FreqDist may import other modules, store global state, create
 other objects... whatever.  Pure python code should not have any
 memory leaks (if there are, it's a bug in the Python
 interpreter). Not-carefully-written C extensions may introduce
 memory problems.
>>>
>>> Pure Python code can cause memory leaks. No, that's not a bug in
>>> the interpreter but the fault of the developer. For example code
>>> that messes around with stack frames and exception object can
>>> cause nasty reference leaks.
>>
>> Ouch!
>> May I assume that code that doesn't use stack frames nor stores
>> references to exception objects/tracebacks is safe?
>
> Circular referencing is no leaking on the C level but in a way it is
> memory leaking, too.

The garbage collector will eventually dispose of the cycle, unless you use 
__del__. Of course it's better if the code itself breaks the cycle when it's 
done using the objects.
The above comment about stack frames and exceptions does not refer to this 
situation, I presume.

-- 
Gabriel Genellina

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


Re: "Help needed - I don't understand how Python manages memory"

2008-04-20 Thread Martin v. Löwis
> In order to deal with 400 thousands texts consisting of 80 million
> words, and huge sets of corpora , I have to be care about the memory
> things. I need to track every word's behavior, so there needs to be as
> many word-objects as words.
> I am really suffering from the memory problem, even 4G  memory space can
> not survive... Only 10,000 texts can kill it in 2 minutes.
> By the way, my program has been optimized to ``del`` the objects after
> traversing, in order not to store the information in memory all the time.

It may then well be that your application leaks memory, however, the
examples that you have given so far don't demonstrate that. Most likely,
you still keep references to objects at some point, causing the leak.

It's fairly difficult to determine the source of such a problem.
As a starting point, I recommend to do

print len(gc.get_objects())

several times in the program, to see how the number of (gc-managed)
objects increases. This number should continually grow up, or else
you don't have a memory leak (or one in a C module which would be
even harder to determine).

Then, from time to time, call

import gc
from collections import defaultdict
def classify():
counters = defaultdict(lambda:0)
for o in gc.get_objects():
counters[type(o)] += 1
counters = [(freq, t) for t,freq in counters.items()]
counters.sort()
for freq,t in counters[-10:]:
print t.__name__, freq

a number of times, and see what kind of objects get allocated.

Then, for the most frequent kind of object, investigate whether
any of them "should" have been deleted. If any, try to find
out a) whether the code that should have released them was executed,
and b) why they are still referenced (use gc.get_referrers for that).
And so on.

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


What happened with python? messed strings?

2008-04-20 Thread algaba

Hi, 
I used extensively python and now I find this mess with strings,
I can't even reproduce tutorial examples:
>>> "apfel".encode('utf-8')  (it was with umlaut)
  File "", line 0

^
SyntaxError: 'ascii' codec can't decode byte 0xc4 in position 1: 
ordinal not in range(128)
>>> 
Is there any good guide to this mess of codecs and hell ?

python should have stayed at version 1.5, every single 'improvement'
has been a mess. But this is the definitive hell. 

thanks!

-- 
SDF-EU Public Access UNIX System - http://sdf-eu.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Alternate indent proposal for python 3000

2008-04-20 Thread [EMAIL PROTECTED]
On 20 avr, 17:35, Eric Wertman <[EMAIL PROTECTED]> wrote:
> I was considering putting together a proposal for an alternate block
> syntax for python, and I figured I'd post it here and see what the
> general reactions are.  I did some searching, and while I found a lot
> of tab vs space debates, I didn't see anything like what I'm thinking
> of, so forgive me if this is a very dead horse.
>
> Generally speaking, I like the current block scheme just fine.  I use
> python on a daily basis for system administration and text parsing
> tasks, and it works great for me.
>
> From time to time, though, I find myself needing a language for server-
> side includes in web pages.  Because of the need to indent (and
> terminate indents), python seems an awkward choice for this, and it's
> easy for me to see why php and perl are more popular choices for this
> kind of task.  Perhaps this is just my perception though.

The server-page scheme has long shown it's limitations and quirks -
mostly, you end up mixing application logic and presentation logic.
Even PHP programmers are slowly taking the MVC route.

> I feel that including some optional means to block code would be a big
> step in getting wider adoption of the language in web development and
> in general.  I do understand though, that the current strict indenting
> is part of the core of the language, so... thoughts?

Python Server Page packages are nothing new, and didn't help making
Python more popular for web developpement. MVC frameworks like Django,
Pylons, Turbogears or web.py seems to draw way more attention, and we
start to see PHP coders switching to Django - which is the one with
the IMHO weakest templating language.

If you're looking for a templating system with Python syntax support,
you may want to take a look at Cheetah and (my favourite one) Mako.
Mako is the default template system for Pylons, and IIRC web.py
supports Cheetah (warning: never used web.py, and haven't followed
recent dev, so you'd better check by yourself).

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


Re: "Help needed - I don't understand how Python manages memory"

2008-04-20 Thread Hank @ITGroup
Steve Holden wrote:
>
> You are suffering from a pathological condition yourself: the desire 
> to optimize performance in an area where you do not have any problems. 
> I would suggest you just enjoy using Python and then start to ask 
> these questions again when you have a real issue that's stopping you 
> from getting real work done.
>
> regards
>  Steve
>
Hi, Steve,
This not simply a pathological condition. My people are keeping trying 
many ways to have job done, and the memory problem became the focus we 
are paying attention on at this moment.
Could you please give us some clear clues to obviously call python to 
free memory. We want to control its gc operation handily as we were 
using J**A.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python setup.py install on Vista?

2008-04-20 Thread Lie
On Apr 20, 9:59 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> > It seems that quite a lot of people wondered why python doesn't set
> > the environment variable to Python Path in the default installation.
>
> For several reasons, one being that it's not needed. Just run setup.py
> as a program, i.e. don't do
>
> python setup.py install
>
> but instead do
>
> setup.py install
>
> Regards,
> Martin

who said it isn't needed:
1. I primarily set the EnvPath to invoke the interpreter in
interactive mode, without being intervened by IDLE ('cause IDLE is
extremely slow if you do a lot of print statements, most of the time
you won't notice it but if we do multitude of prints it might hang for
a second or two at every statement).
2. To avoid confusion with the rest of the world that uses python by
calling "python" in a shell-like interface (i.e. cmd).
3. Linux-people sometimes doesn't believe that there are Windows-
people that actually likes CLI, sometimes more than GUI.
4. Being such a great IDE, IDLE sometimes do odds and ends that it
sometimes DoS-ed me, having a quick, alternative way to be in touch
with python is a good thing, especially if you're being chased by a
deadline and moving focus away from the job to repair the tool is not
an option.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What happened with python? messed strings?

2008-04-20 Thread Arnaud Delobelle
On Apr 20, 7:54 pm, <[EMAIL PROTECTED]> wrote:
[...]
> python should have stayed at version 1.5, every single 'improvement'
> has been a mess. But this is the definitive hell.

You can still download Python 1.5.2 from python.org:

http://www.python.org/download/releases/1.5/

HTH

--
Arnaud

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


Re: What happened with python? messed strings?

2008-04-20 Thread Gabriel Genellina
En Sun, 20 Apr 2008 15:54:20 -0300, <[EMAIL PROTECTED]> escribió:

> I used extensively python and now I find this mess with strings,
> I can't even reproduce tutorial examples:
 "apfel".encode('utf-8')  (it was with umlaut)
>   File "", line 0
>^
> SyntaxError: 'ascii' codec can't decode byte 0xc4 in position 1:
> ordinal not in range(128)

> Is there any good guide to this mess of codecs and hell ?

The Absolute Minimum Every Software Developer Absolutely, Positively Must Know 
About Unicode and Character Sets (No Excuses!)


Python Unicode Howto: 

> python should have stayed at version 1.5, every single 'improvement'
> has been a mess. But this is the definitive hell.

Nobody forces you to use a newer version. You can download 1.5.2 from 
http://www.python.org/download/releases/1.5

-- 
Gabriel Genellina

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


Re: socket.AF_INET

2008-04-20 Thread Juergen Perlinger
Matt Herzog wrote:

> Hi All.
> 
> I'm trying to write a script that will send me an email message when my IP
> address changes on a specific NIC. On Linux, the script works. On FreeBSD,
> it fails with:
> 
> [snip]
> 
> def get_ip_address(ifname):
> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
> return socket.inet_ntoa(fcntl.ioctl(
> s.fileno(),
> 0x8915,  # SIOCGIFADDR
> struct.pack('256s', ifname[:15]) )[20:24])
> 

[OT: sorry Matt, hit email instead followup twice... stupid me]

My bets are that the SIOCGIFADDR opcode has a different numerical value for
BSD. Even if some names are portable, the numerical values aren't! I don't
have BSD, but using 

find /usr/include -type f -name '*.h' | xargs grep SIOCGIFADDR /dev/null

should give some hints...

-- 
juergen 'pearly' perlinger
"It's hard to make new errors!"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What happened with python? messed strings?

2008-04-20 Thread Juergen Perlinger
[EMAIL PROTECTED] wrote:

> 
> Hi,
> I used extensively python and now I find this mess with strings,
> I can't even reproduce tutorial examples:
 "apfel".encode('utf-8')  (it was with umlaut)
>   File "", line 0
> 
> ^
> SyntaxError: 'ascii' codec can't decode byte 0xc4 in position 1:
> ordinal not in range(128)
 
> Is there any good guide to this mess of codecs and hell ?
> 
> python should have stayed at version 1.5, every single 'improvement'
> has been a mess. But this is the definitive hell.
> 
> thanks!
> 

Basically you're not using ASCII encoding in your source text... You need to
define an encoding for your source if you're using german umlauts or other
fancy stuff.

See chapter 2.1.4 of the reference manual, and add e.g.

# -*- coding: utf-8 -*-

as first or second line to your script. Make sure your editor talks utf-8,
or use the encoding used by your editor. cp1552 is a good choice for
windows...

-- 
juergen 'pearly' perlinger
"It's hard to make new errors!"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What happened with python? messed strings?

2008-04-20 Thread Jason Scheirer
On Apr 20, 11:54 am, <[EMAIL PROTECTED]> wrote:
> Hi,
> I used extensively python and now I find this mess with strings,
> I can't even reproduce tutorial examples:>>> "apfel".encode('utf-8')  (it was 
> with umlaut)
>
>   File "", line 0
>
>     ^
> SyntaxError: 'ascii' codec can't decode byte 0xc4 in position 1:
> ordinal not in range(128)

Two things: Mark the character encoding of your file ( read
http://www.python.org/doc/2.3/whatsnew/section-encodings.html ), and
then if that doesn't work try to .decode('something') your string
first with the appropriate codec, then you get a unicode object for
free and you don't need the .encode('utf-8'). Also read the slides at
http://farmdev.com/talks/unicode/ for some good information about
unicode in Python.

>
> Is there any good guide to this mess of codecs and hell ?
>
> python should have stayed at version 1.5, every single 'improvement'
> has been a mess. But this is the definitive hell.

It's true -- decorators, the class/type cleanup, properties, -= and
+=, list comprehensions, generators, distutils, and all the new
modules in the standard library are completely, entirely useless.
Python SHOULD have stayed at 1.5.

>
> thanks!
>
> --
> SDF-EU Public Access UNIX System -http://sdf-eu.org


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


Re: What happened with python? messed strings?

2008-04-20 Thread Juergen Perlinger
Juergen Perlinger wrote:

> [EMAIL PROTECTED] wrote:
>  [snip]
> Basically you're not using ASCII encoding in your source text... You need
> to define an encoding for your source if you're using german umlauts or
> other fancy stuff.
> 
> See chapter 2.1.4 of the reference manual, and add e.g.
> 
> # -*- coding: utf-8 -*-
> 
> as first or second line to your script. Make sure your editor talks utf-8,
> or use the encoding used by your editor. cp1552 is a good choice for
> windows...
> 

stupid me. cp1252, of course.
-- 
juergen 'pearly' perlinger
"It's hard to make new errors!"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Help needed - I don't understand how Python manages memory"

2008-04-20 Thread Christian Heimes
Hank @ITGroup schrieb:
> In order to deal with 400 thousands texts consisting of 80 million
> words, and huge sets of corpora , I have to be care about the memory
> things. I need to track every word's behavior, so there needs to be as
> many word-objects as words.
> I am really suffering from the memory problem, even 4G  memory space can
> not survive... Only 10,000 texts can kill it in 2 minutes.
> By the way, my program has been optimized to ``del`` the objects after
> traversing, in order not to store the information in memory all the time.

No ordinary system and programming language can hold that much data in
memory at once. Your design is broken; some may call it even insane.

I highly recommend ZODB for your problem. ZODB will allow you to work
with several GB of data in a transaction oriented way without the needs
of an external database server like Postgres or MySQL. ZODB even
supports clustering and mounting of additional database from the same
file system or an external server.

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


Re: What happened with python? messed strings?

2008-04-20 Thread Juergen Perlinger
Jason Scheirer wrote:
[snip]
> 
> It's true -- decorators, the class/type cleanup, properties, -= and
> +=, list comprehensions, generators, distutils, and all the new
> modules in the standard library are completely, entirely useless.
> Python SHOULD have stayed at 1.5.

totally OT, but just a few personal observations:

1. Everything was better a few hundred years ago.

2. A fool with a tool is still a fool.
(just in general, all people present excused...)

3. Simple things tend to become complex. Complex things tend to break, even
when used properly. And it might be hard to use them properly if you don't
have the understanding.

4. Simplicity can be deceptive.


-- 
juergen 'pearly' perlinger
"It's hard to make new errors!"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Help needed - I don't understand how Python manages memory"

2008-04-20 Thread sturlamolden
On Apr 20, 9:09 pm, "Hank @ITGroup" <[EMAIL PROTECTED]> wrote:

> Could you please give us some clear clues to obviously call python to
> free memory. We want to control its gc operation handily as we were
> using J**A.

If you want to get rid of a Python object, the only way to do that is
to get rid of every reference to the object. This is no different from
Java.

If you just want to deallocate and allocate memory to store text,
Python lets you do that the same way as C:


from __future__ import with_statement
import os
from ctypes import c_char, c_char_p, c_long, cdll
from threading import Lock

_libc = cdll.msvcr71 if os.name == 'nt' else cdll.libc
_lock = Lock()

def string_heapalloc(n):
''' allocate a mutable string using malloc '''
with _lock:
malloc = _libc.malloc
malloc.argtypes = [c_long]
malloc.restype = c_char * n
memset = _libc.memset
memset.restype = None
memset.argtypes = [c_char * n, c_char, c_long]
tmp = malloc(n)
memset(tmp,'0',n)
return tmp

def string_heapfree(s):
''' free an allocated string '''
with _lock:
free = _libc.free
free.restype = None
free.argtypes = [c_char_p]
ptr_first_char = c_char_p( s[0] )
free(ptr_first_char)


if __name__ == '__main__':
s = string_heapalloc(1000)
s[:26] = 'abcdefghijklmnopqrstuvwxyz'
print s[:]
string_heapfree(s)

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


Re: "Help needed - I don't understand how Python manages memory"

2008-04-20 Thread Christian Heimes
Martin v. Löwis schrieb:
> Can you give an example, please?

http://trac.edgewall.org/ contains at least one example of a reference
leak. It's holding up the release of 0.11 for a while. *scnr*

The problem is also covered by the docs at
http://docs.python.org/dev/library/sys.html#sys.exc_info

Christian

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


cherrypy-webapp-code?

2008-04-20 Thread globalrev
anyone have a small cherrypy-webapp and are willing to post the code.

could be a nonsense-app just wanna see some code.
-- 
http://mail.python.org/mailman/listinfo/python-list


jennifer aniston paul

2008-04-20 Thread collardfelszkw
Just few link on some Movies


Movies: http://Jennifer-Aniston.12w.net


F
R
E
E


C
E
L
E
B
R
I
T
Y


M
O
V
I
E
S
-- 
http://mail.python.org/mailman/listinfo/python-list


jennifer aniston paul sculfor

2008-04-20 Thread collardfelszkw
Just few link on some Movies


Movies: http://Jennifer-Aniston.12w.net


F
R
E
E


C
E
L
E
B
R
I
T
Y


M
O
V
I
E
S
-- 
http://mail.python.org/mailman/listinfo/python-list


jennifer aniston and paul

2008-04-20 Thread collardfelszkw
Just few link on some Movies


Movies: http://Jennifer-Aniston.12w.net


F
R
E
E


C
E
L
E
B
R
I
T
Y


M
O
V
I
E
S
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Help needed - I don't understand how Python manages memory"

2008-04-20 Thread Martin v. Löwis
> http://trac.edgewall.org/ contains at least one example of a reference
> leak. It's holding up the release of 0.11 for a while. *scnr*

All my investigations on possible memory leaks in Trac have only
confirmed that Python does _not_, I repeat, it does *NOT* leak any
memory in Trac.

Instead, what appears as a leak is an unfortunate side effect of
the typical malloc implementation which prevents malloc from returning
memory to the system. The memory hasn't leaked, and is indeed available
for further allocations by trac.

> The problem is also covered by the docs at
> http://docs.python.org/dev/library/sys.html#sys.exc_info

Ah, but that's not a *reference* leak. If Python (or an extension
module) contains a reference leak, that's a bug.

A reference leak is a leak where the reference counter is increased
without ever being decreased (i.e. without the application having
a chance to ever decrease it correctly). In this case, it's just a
cyclic reference, which will get released whenever the garbage
collector runs next, so it's not a memory leak.

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


Re: cherrypy-webapp-code?

2008-04-20 Thread Daniel Fetchinson
> anyone have a small cherrypy-webapp and are willing to post the code.
> could be a nonsense-app just wanna see some code.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



Did you try google? And the cherrypy website?
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: I would like to learn scripting in Python too!

2008-04-20 Thread Daniel Fetchinson
> I am a software tester and I see lot of testers on the forums saying Python
> is a wonderful scripting language that testers use on a daily basis.
>
> I would also like to learn to script in Python but I do not have any
> programming background.


This is a good starting point: http://wiki.python.org/moin/BeginnersGuide

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


Re: "Help needed - I don't understand how Python manages memory"

2008-04-20 Thread Steve Holden
Hank @ITGroup wrote:
> Steve Holden wrote:
>> You are suffering from a pathological condition yourself: the desire 
>> to optimize performance in an area where you do not have any problems. 
>> I would suggest you just enjoy using Python and then start to ask 
>> these questions again when you have a real issue that's stopping you 
>> from getting real work done.
>>
>> regards
>>  Steve
>>
> Hi, Steve,
> This not simply a pathological condition. My people are keeping trying 
> many ways to have job done, and the memory problem became the focus we 
> are paying attention on at this moment.
> Could you please give us some clear clues to obviously call python to 
> free memory. We want to control its gc operation handily as we were 
> using J**A.

Well, now you've told us a little more about your application I can 
understand that you need to be careful with memory allocation.

The best thing you can do is to ensure that your program is reasonably 
decomposed into functions. That way the local namespaces have limited 
lifetimes, and only the values that they return are injected into the 
environment. You also need to be careful in exception processing that 
you do not cause a reference to the stack frame to be retained, as that 
can be a fruitful source of references to objects, rendering them 
non-collectable.

You appear to be stressing the limits of a single program under 
present-day memory constraints. I am afraid that no matter how carefully 
you manage object references, any difference you can make is likely to 
be lost in the noise as far as memory utilization is concerned, and you 
may have to consider using less direct methods of processing your data sets.

The gc module does give you some control over the garbage collector, but 
generally speaking most programs don't even need that much control.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Alternate indent proposal for python 3000

2008-04-20 Thread George Sakkis
On Apr 20, 12:34 pm, Eric Wertman <[EMAIL PROTECTED]> wrote:
> > Look into any of the dozen Python-based template engines that are
> > typically used for such tasks; they offer many more features than a
> > way to indent blocks.
>
> > George
>
> I definitely will.. could you throw out some examples though?
> Thanks!
>
> Eric

Start out here: http://wiki.python.org/moin/Templating

As you can see there is no shortage of alternatives, which can be
overwhelming. Cheetah used to be the most popular and it's still
widely used, but these days Django templates, Genshi and Mako seem
more prominent for web development.

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


  1   2   >