Re: Who's laughing at my responses, and who's not?

2012-09-24 Thread Ned Deily
In article 
,
 Dwight Hutto  wrote:
> It's a little guy talk, and most seem to be guys. A little, "hey
> buddy, this seems like like bullshit", seems ok around here, and it's
> a first amendment.

It's not OK around here.   "Spirited" discussion is fine and to be 
expected but the Python community is *very* serious about mutual respect 
and respecting diversity.  If you want to be taken seriously here, 
please keep that in mind.

http://www.python.org/community/diversity/

-- 
 Ned Deily,
 n...@acm.org

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


Re: Who's laughing at my responses, and who's not?

2012-09-24 Thread Kushal Das
On Tue, Sep 25, 2012 at 11:22 AM, Dwight Hutto  wrote:
> It's a little guy talk, and most seem to be guys. A little, "hey
> buddy, this seems like like bullshit", seems ok around here, and it's
> a first amendment.

First amendment does not apply to all the international people here.
Everyone should check twice what they are writing in the list.

Kushal
-- 
http://fedoraproject.org
http://kushaldas.in
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: For Counter Variable

2012-09-24 Thread Thomas Rachel

Am 25.09.2012 01:39 schrieb Dwight Hutto:


It's not the simpler solution I'm referring to, it's the fact that if
you're learning, then you should be able to design the built-in, not
just use it.


In some simpler cases you are right here. But the fact that you are able 
to design it doesn't necessarily mean that you should actually use your 
self-designed version.


But what you post suggests is important as well: if using the neat fancy 
built-in simplifications, you should always be aware what overhead they 
imply.


An example:

Let l be a big, big list.

for i in :
if i in l: 

This looks neat and simple and doesn't look as expensive as it really is.

If l is converted to a set beforehand, it nearly looks the same, but it 
is simpler.


So even if you use builtins, be aware what they do.



You don't always know all the built-ins, so the builtin is simpler,
but knowing how to code it yourself is the priority of learning to
code in a higher level language, which should be simpler to the user
of python.


When learning Python, it often happend me to re-inven the wheel. But as 
soon as I saw the presence of something I re-wrote, I skipped my 
re-written version and used the built-in.



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


Re: Who's laughing at my responses, and who's not?

2012-09-24 Thread Dwight Hutto
On Tue, Sep 25, 2012 at 1:25 AM, Ethan Furman  wrote:
> Dwight Hutto wrote:
>>>
>>> context and cut the potty mouth stuff.
>>
>> It was meant as a little shop talk, but I forgot there were ladies here as
>> well.
>
>
> Not only ladies, but gentlemen.  Foul-mouthed "shop talk" is not necessary
> to teach Python.  Practice some self-control, or at least self-editing.
>

It's a little guy talk, and most seem to be guys. A little, "hey
buddy, this seems like like bullshit", seems ok around here, and it's
a first amendment.

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



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-24 Thread Thomas Rachel

Am 25.09.2012 07:22 schrieb Dwight Hutto:


No, not really. If you wanna talk shit, I can reflect that, and if you
wanna talk politely I can reflect that. I go t attacked first.,


But not in this thread.

Some people read only selectively and see only your verbal assaults, 
without noticing that they refer to.


If you was really insulted, you should answer to these insults in their 
thread and not in a different one.



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


Re: python file API

2012-09-24 Thread Thomas Rachel

Am 25.09.2012 00:37 schrieb Ian Kelly:

On Mon, Sep 24, 2012 at 4:14 PM, Chris Angelico  wrote:

file.pos = 42 # Okay, you're at position 42
file.pos -= 10 # That should put you at position 32
foo = file.pos # Presumably foo is the integer 32
file.pos -= 100 # What should this do?


Since ints are immutable, the language specifies that it should be the
equivalent of "file.pos = file.pos - 100", so it should set the file
pointer to 68 bytes before EOF.


But this is not a "real int", it has a special use. So I don't think it 
is absolutely required to behave like an int.


This reminds me of some special purpose registers in embedded 
programming, where bits can only be set by hardware and are cleared by 
the application by writing 1 to them.


Or some bit setting registers, like on ATxmega: OUT = 0x10 sets bit 7 
and clears all others, OUTSET = 0x10 only sets bit 7, OUTTGL = 0x10 
toggles it and OUTCLR = 0x10 clears it.


If this behaviour is documented properly enough, it is quite OK, IMHO.


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


why do this program not fullscreen?

2012-09-24 Thread Levi Nie
the code:
import wx
app=wx.App()
win=wx.Frame(None)
win.ShowFullScreen()
app.MainLoop()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Who's laughing at my responses, and who's not?

2012-09-24 Thread Ethan Furman

Dwight Hutto wrote:

Been getting slammed by a few for some insignificant things, so who's
laughing at me, and who takes me seriously. I don't claim to be the
best, just trying to help.


Mis-interpreting posts is not insignificant.

Being rude is not insignificant.

Refusing to see these things, and instead blaming everyone else, is not 
insignificant.


Being wrong is not fun, but learn from it instead of saying, "I'm not 
wrong, you just don't understand!"


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


Re: python file API

2012-09-24 Thread Thomas Rachel

Am 25.09.2012 04:28 schrieb Steven D'Aprano:


By the way, the implementation of this is probably trivial in Python 2.x.
Untested:

class MyFile(file):
 @property
 def pos(self):
 return self.tell()
 @pos.setter
 def pos(self, p):
 if p<  0:
 self.seek(p, 2)
 else:
 self.seek(p)

You could even use a magic sentinel to mean "see to EOF", say, None.

 if p is None:
 self.seek(0, 2)

although I don't know if I like that.


The whole concept is incomplete at one place: self.seek(10, 2) seeks 
beyond EOF, potentially creating a sparse file. This is a thing you 
cannot achieve.


But the idea is great. I'd suggest to have another property:

  [...]
  @pos.setter
  def pos(self, p):
  self.seek(p)
  @property
  def eofpos(self): # to be consistent
  return self.tell()
  @eofpos.setter
  def eofpos(self, p):
  self.seek(p, 2)

Another option could be a special descriptor which can be used as well 
for relative seeking:


class FilePositionDesc(object):
def __init__(self):
pass
def __get__(self, instance, owner):
return FilePosition(self)
def __set__(self, value):
self.seek(value)

class FilePosition(object):
def __init__(self, file):
self.file = file
def __iadd__(self, offset):
self.file.seek(offset, 1)
def __isub__(self, offset):
self.file.seek(-offset, 1)

class MyFile(file):
pos = FilePositionDesc()
[...]

Stop.

This could be handled with a property as well.

Besides, this breaks some other expectations to the pos. So let's 
introduce a 3rd property named relpos:


class FilePosition(object):
def __init__(self, file):
self.file = file
self.seekoffset = 0
def __iadd__(self, offset):
self.seekoffset += offset
def __isub__(self, offset):
self.seekoffset -= offset
def __int__(self):
return self.file.tell() + self.seekoffset

class MyFile(file):
  @property
  def relpos(self):
  return FilePosition(self) # from above
  @relpos.setter
  def relpos(self, ofs):
  try:
  o = ofs.seekoffset # is it a FilePosition?
  except AttributeError:
  self.seek(ofs, 1) # no, but ofs can be an int as well
  else:
  self.seek(o, 1) # yes, it is


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


Re: Who's laughing at my responses, and who's not?

2012-09-24 Thread Ethan Furman

Dwight Hutto wrote:

context and cut the potty mouth stuff.

It was meant as a little shop talk, but I forgot there were ladies here as well.


Not only ladies, but gentlemen.  Foul-mouthed "shop talk" is not 
necessary to teach Python.  Practice some self-control, or at least 
self-editing.


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


Re: which a is used?

2012-09-24 Thread Dwight Hutto
>> OH. stirrin up shit and can't stand the smell.
>
>
> Where did he so?
>


You'd have to read the other posts. And remember that some of these
names are A.K.A.'s, they ask respond, and befriend another name
through another proxy.


-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-24 Thread Dwight Hutto
On Tue, Sep 25, 2012 at 1:06 AM, Thomas Rachel

wrote:
> Am 25.09.2012 03:13 schrieb Dwight Hutto:
>
>
>> Anything else bitch, take time to think about it.
>
>
> And you wonder if people don't like you because of your language?
>

No, not really. If you wanna talk shit, I can reflect that, and if you
wanna talk politely I can reflect that. I go t attacked first., and
project managers don't get shoved around, they listen, respond, and if
wrong correct themselves, if not, they slam back , or their position
gets taken.
>
> Thomas
>
> --
> http://mail.python.org/mailman/listinfo/python-list



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-24 Thread Thomas Rachel

Am 25.09.2012 04:37 schrieb Dwight Hutto:

I honestly could not care less what you think about me, but don't use
that term. This isn't a boys' club and we don't need your hurt ego
driving people away from here.


OH. stirrin up shit and can't stand the smell.


Where did he so?


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


Re: Who's laughing at my responses, and who's not?

2012-09-24 Thread Dwight Hutto
> context and cut the potty mouth stuff.
It was meant as a little shop talk, but I forgot there were ladies here as well.


-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-24 Thread Thomas Rachel

Am 25.09.2012 03:47 schrieb Dwight Hutto:


But within a class this is could be defined as self.x within the
functions and changed, correct?


class a():
def __init__(self,a):
self.a = a

def f(self):
print self.a

def g(self):
self.a = 20
print self.a


a = a(1)
a.f()
a.g()


Yes - this is a different situation. Here, the "self" referred to is the 
same in all cases (the "a" from top level), and so self.a can be used 
consistently as well.



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


Re: Who's laughing at my responses, and who's not?

2012-09-24 Thread Terry Reedy

On 9/25/2012 12:43 AM, Dwight Hutto wrote:

It sounds pretentious, but over the past several days, I've been
slammed on every post almost. All because of an argument over me not
posting a little context in a conversation, that seemed short and
chatty.

I was just wondering, if it's just them, or if it's my netiquette.


A 1000 line post with a one line response is not polite. Context free 
posts are disconcerting, but easier to ignore. Keep at least one 
sentence of context and cut the potty mouth stuff.


--
Terry Jan Reedy

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


Re: Who's laughing at my responses, and who's not?

2012-09-24 Thread Littlefield, Tyler

On 9/24/2012 10:43 PM, Dwight Hutto wrote:

It sounds pretentious, but over the past several days, I've been
slammed on every post almost. All because of an argument over me not
posting a little context in a conversation, that seemed short and
chatty.

I was just wondering, if it's just them, or if it's my netiquette.

I think you'd have a leg to stand on here if you didn't start cursing at anyone 
who got on your wrong side. It wasn't really an issue until you threw that
up. Granted you did take your cursing off list finally, but you still continued 
(and as of about 2 hours ago) continue to post trash like you did in response
to Alix's message. If you want to argue something, by all means argue. But 
there's no need to resort to comments like you've made.


-- Take care, Ty http://tds-solutions.net The aspen project: a barebones 
light-weight mud engine: http://code.google.com/p/aspenmud He that will 
not reason is a bigot; he that cannot reason is a fool; he that dares 
not reason is a slave.

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


Re: which a is used?

2012-09-24 Thread Terry Reedy

Revising my answer to your other post.

On 9/24/2012 9:13 PM, Dwight Hutto wrote:

Anything else bitch, take time to think about it.


This is completely bizarre, and uncalled for as an apparent response to 
Alex. Your next response is too dirty to read, let alone quote. Please 
desist. If necessary, learn to wait a few minutes before hitting send.



--
Terry Jan Reedy

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


Re: PHP vs. Python

2012-09-24 Thread tejas . tank . mca
On Thursday, 23 December 2004 03:33:36 UTC+5:30, (unknown)  wrote:
> Anyone know which is faster?  I'm a PHP programmer but considering
> getting into Python ... did searches on Google but didn't turn much up
> on this.
> 
> Thanks!
> Stephen


Here some helpful gudance.

http://hentenaar.com/serendipity/index.php?/archives/27-Benchmark-PHP-vs.-Python-vs.-Perl-vs.-Ruby.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Who's laughing at my responses, and who's not?

2012-09-24 Thread Terry Reedy
I am not laughing. Looking back, some of your responses seem sensible. I 
mostly skip over single word responses, and others that seems content 
free, whether from you or others.


--
Terry Jan Reedy

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


Re: Who's laughing at my responses, and who's not?

2012-09-24 Thread Dwight Hutto
It sounds pretentious, but over the past several days, I've been
slammed on every post almost. All because of an argument over me not
posting a little context in a conversation, that seemed short and
chatty.

I was just wondering, if it's just them, or if it's my netiquette.


-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Who's laughing at my responses, and who's not?

2012-09-24 Thread Tim Roberts
Dwight Hutto  wrote:
>
>Been getting slammed by a few for some insignificant things, so who's
>laughing at me, and who takes me seriously. I don't claim to be the
>best, just trying to help.
>
>So who doesn't want me around?

Who cares?  There are probably hundreds of thousands of people reading this
forum.  A few of those people probably don't like you.  So what?

Illegitemi non carborondum -- don't let the bastards wear you down.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Memory usage per top 10x usage per heapy

2012-09-24 Thread Junkshops

Just curious;  which is it, two million lines, or half a million bytes?
I have, in fact, this very afternoon, invented a means of writing a 
carriage return character using only 2 bits of information. I am 
prepared to sell licenses to this revolutionary technology for the low 
price of $29.95 plus tax.


Sorry, that should've been a 500Mb, 2M line file.


which machine is 2gb, the Windows machine, or the VM?

VM. Winders is 4gb.


...but I would point out that just because
you free up the memory from the Python doesn't mean it gets released
back to the system.  The C runtime manages its own heap, and is pretty
persistent about hanging onto memory once obtained.  It's not normally a
problem, since most small blocks are reused.  But it can get
fragmented.  And i have no idea how well Virtual Box maps the Linux
memory map into the Windows one.
Right, I understand that - but what's confusing me is that, given the 
memory use is (I assume) monotonically increasing, the code should never 
use more than what's reported by heapy once all the data is loaded into 
memory, given that memory released by the code to the Python runtime is 
reused. To the best of my ability to tell I'm not storing anything I 
shouldn't, so the only thing I can think of is that all the object 
creation and destruction, for some reason, it preventing reuse of 
memory. I'm at a bit of a loss regarding what to try next.


Cheers, MrsE

On 9/24/2012 6:14 PM, Dave Angel wrote:

On 09/24/2012 05:59 PM, MrsEntity wrote:

Hi all,

I'm working on some code that parses a 500kb, 2M line file

Just curious;  which is it, two million lines, or half a million bytes?


line by line and saves, per line, some derived strings into various data 
structures. I thus expect that memory use should monotonically increase. 
Currently, the program is taking up so much memory - even on 1/2 sized files - 
that on 2GB machine

which machine is 2gb, the Windows machine, or the VM?  You could get
thrashing at either level.


I'm thrashing swap. What's strange is that heapy 
(http://guppy-pe.sourceforge.net/) is showing that the code uses about 10x less 
memory than reported by top, and the heapy data seems consistent with what I 
was expecting based on the objects the code stores. I tried using 
memory_profiler (http://pypi.python.org/pypi/memory_profiler) but it didn't 
really provide any illuminating information. The code does create and discard a 
number of objects per line of the file, but they should not be stored anywhere, 
and heapy seems to confirm that. So, my questions are:

1) For those of you kind enough to help me figure out what's going on, what 
additional data would you like? I didn't want swamp everyone with the code and 
heapy/memory_profiler output but I can do so if it's valuable.
2) How can I diagnose (and hopefully fix) what's causing the massive memory 
usage when it appears, from heapy, that the code is performing reasonably?

Specs: Ubuntu 12.04 in Virtualbox on Win7/64, Python 2.7/64

Thanks very much.

Tim raised most of my concerns, but I would point out that just because
you free up the memory from the Python doesn't mean it gets released
back to the system.  The C runtime manages its own heap, and is pretty
persistent about hanging onto memory once obtained.  It's not normally a
problem, since most small blocks are reused.  But it can get
fragmented.  And i have no idea how well Virtual Box maps the Linux
memory map into the Windows one.




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


Re: How to limit CPU usage in Python

2012-09-24 Thread Tim Roberts
Paul Rubin  wrote:
>
>Tim Roberts: reasons to want to do this might involve a shared host
>where excessive cpu usage affects other users;

That's what priorities are for.

>...or a computer with
>limited power consumption, where prolonged high cpu activity causes
>thermal or other problems.

OK, I grant that.  However, statistically speaking, it is much more likely
that the OP merely has a misunderstanding.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "9/11 Missing Links" is the video that Jews do not want you to see!

2012-09-24 Thread hamilton

On 9/24/2012 9:35 PM, Suzi Mrezutttii wrote:

Google and watch "9/11 Missing Links" before Jews remove it from
youtube anytime now!





Hey dude, Nice name, "a boy named sue" !!!
--
http://mail.python.org/mailman/listinfo/python-list


"9/11 Missing Links" is the video that Jews do not want you to see!

2012-09-24 Thread Suzi Mrezutttii
Google and watch "9/11 Missing Links" before Jews remove it from
youtube anytime now!


http://joozhatetruth.blogspot.com/

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


Re: which a is used?

2012-09-24 Thread Dwight Hutto
> I honestly could not care less what you think about me, but don't use
> that term. This isn't a boys' club and we don't need your hurt ego
> driving people away from here.

OH. stirrin up shit and can't stand the smell. Turn and
switch technique. "You're so vulgar, and I wasn't."Go get a clue ho,
and then you can gumshoe it up the last crack alley on the left, and
suck till my nut hair tickles your tonsils.




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



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python file API

2012-09-24 Thread Mark Adam
On Mon, Sep 24, 2012 at 5:55 PM, Oscar Benjamin
 wrote:
> There are many situations where a little bit of attribute access magic is a
> good thing. However, operations that involve the underlying OS and that are
> prone to raising exceptions even in bug free code should not be performed
> implicitly like this. I find the following a little cryptic:
> try:
> f.pos = 256
> except IOError:
> print('Unseekable file')

Well it might be that the coupling between the python interpreter and
the operating system should be more direct and there should be a
special exception class that bypasses the normal overhead in the
CPython implementation so that error can be caught in the code without
breaking syntax.  But I don't think I'm ready to argue that point

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


Re: keeping information about players around

2012-09-24 Thread Steven D'Aprano
On Tue, 25 Sep 2012 08:19:34 +1000, Chris Angelico wrote:

> On Tue, Sep 25, 2012 at 7:14 AM, Dwight Hutto 
> wrote:
>> Also, If this is a browser app I'd go with phpmyadmin, and MySQL
>>
>> If a tkinter/wxpython/etc app, then maybe sqlite.
> 
> Out of curiosity, why? MySQL isn't magically better for everything where
> data ends up displayed in a web browser. Unless you're planning to also
> reference this database from some other language, it's going to make
> little difference what backend you use; and even if you are using
> multiple languages, it's usually not difficult to find overlap.

For a desktop application, you can't expect the application user to have 
set up MySQL or Postgresql first, so you have to use something like 
sqlite.

For web applications, you're probably expecting (or at least hoping for) 
tens of thousands of users a day, and sqlite probably won't cut it. If 
your web app is only used by you, then you might not care.

I think it is perfectly reasonable to assume a web app and a desktop app 
might use different backends.



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


Re: python file API

2012-09-24 Thread Steven D'Aprano
On Mon, 24 Sep 2012 15:36:20 -0700, zipher wrote:

> You raise a valid point: that by abstracting the file pointer into a
> position attribute you risk "de-coupling" the conceptual link between
> the underlying file and your abstraction in the python interpreter

I don't think this argument holds water. With the ease of writing 
attributes, it is more likely that people will perform file position 
operations directly on file.pos rather than decoupling it into a 
variable. Decoupling is more likely with file.seek, because it is so much 
more verbose to use, and you get exactly the same lack of bounds checking:

py> f = open("junk", "w")  # make a sample file
py> f.write("abcd\n")
py> f.close()
py> f = open("junk")  # now do decoupled seek operations
py> p = f.tell()
py> p += 2000
py> p -= 4000
py> p += 2
py> p += 2000
py> f.seek(p)
py> f.read(1)
'c'


But really, who does such a sequence of arithmetic operations on the file 
pointer without intervening reads or writes? We're arguing about 
something that almost never happens.

By the way, the implementation of this is probably trivial in Python 2.x. 
Untested:

class MyFile(file):
@property
def pos(self):
return self.tell()
@pos.setter
def pos(self, p):
if p < 0:
self.seek(p, 2)
else:
self.seek(p)

You could even use a magic sentinel to mean "see to EOF", say, None.

if p is None:
self.seek(0, 2)

although I don't know if I like that.



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


Re: which a is used?

2012-09-24 Thread alex23
On Sep 25, 11:13 am, Dwight Hutto  wrote:
> bitch

I honestly could not care less what you think about me, but don't use
that term. This isn't a boys' club and we don't need your hurt ego
driving people away from here.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PIL questions: still supported? Problems on 2.7 for win? alternatives?

2012-09-24 Thread alex23
On Sep 25, 11:46 am, Alex Clark  wrote:
> Actually, I started it for the Plone community, but have recently
> broadened the scope (since most of the contributions came from outside
> Plone).

You're a saint, thanks for taking this on.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PIL questions: still supported? Problems on 2.7 for win? alternatives?

2012-09-24 Thread alex23
On Sep 25, 6:04 am, Gelonida N  wrote:
> So I'll probably try to install the custom binary, but would like to
> know whether anybody has experience with this
> build.http://www.lfd.uci.edu/~gohlke/pythonlibs/#pil

Sorry, I missed this the first time. I'm using this version
successfully under Windows 7 64-bit. I've had nothing but success with
extensions I've used from that site.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-24 Thread Dwight Hutto
But within a class this is could be defined as self.x within the
functions and changed, correct?


class a():
def __init__(self,a):
self.a = a

def f(self):
print self.a

def g(self):
self.a = 20
print self.a


a = a(1)
a.f()
a.g()


Yielding:

david@david-desktop:~$ python answer_to_email.py
1
20
david@david-desktop:~$


-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-24 Thread Dwight Hutto
On Mon, Sep 24, 2012 at 9:18 PM, Steven D'Aprano
 wrote:
> On Mon, 24 Sep 2012 16:43:24 -0700, Jayden wrote:
>
>> Dear All,
>>
>> I have a simple code as follows:
>>
>> # Begin
>> a = 1
>>
>> def f():
>> print a
>>Paul Rubin 
>> def g():
>> a = 20
>> f()
>>
>> g()
>> #End
>>
>> I think the results should be 20, but it is 1. Would you please tell me
>> why?
>
> You are expecting "dynamic scoping", Python uses "static scoping" (or
> lexical scoping). With lexical scoping, you can reason about the
> behavioPaul Rubin ur of a function by knowing only 
> how and where it is defined. The
> caller is irrelevant.
>
> Since fuPaul Rubin nction f is defined globally, and 
> does not have its own local
> variable a, it will always see the global variable a no matter where it
> is called. So when you call f() from inside g(), f prints 1, the global
> a, not 20, g's local a.
>
> While dynamic scoping has its uses, it is more tricky to use correctly.
> One can no longer understand the behaviour of a function just by reading
> the funcPaul Rubin tion's own code, knowing where 
> and how it is defined. You also
> need to know where it is called. A function f that works perfectly when
> you call it from functions g, h, k, ... will suddenly misbehave (crash,
> or worse, behave wrongly) when called from function v because v
> accidentally changes some global variable that f relies on.
>
> This is especially a danger for Python, because built-in functions like
> len, chr, ord, print (version 3 only), and many others are all global
> variables.
>
> (Technically, they are in a third scope, the builtins, but that's
> equivalent to being global.)
>

But within a class this is could be defined as self.x within the
functions and changed, correct?


class a():
def __init__(self,a):
self.a = a

def f(self):
print self.a

def g(self):
self.a = 20
print self.a


a = a(1)
a.f()
a.g()


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



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PIL questions: still supported? Problems on 2.7 for win? alternatives?

2012-09-24 Thread Alex Clark

On 2012-09-24 23:38:05 +, alex23 said:


On Sep 25, 6:04 am, Gelonida N  wrote:

This all does not sound very comforting. Why is there no fix on the
official site?


Has a bug been logged about the issue?

The Plone community keeps a fairly up-to-date fork called Pillow,
we've had a lot of success using that locally:

http://pypi.python.org/pypi/Pillow/



Actually, I started it for the Plone community, but have recently 
broadened the scope (since most of the contributions came from outside 
Plone). It now lives here:


- https://github.com/python-imaging/Pillow


If you have any trouble using it, please open a ticket here:

- https://github.com/python-imaging/Pillow/issues



Alex



--
Alex Clark · http://pythonpackages.com


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


Re: python file API

2012-09-24 Thread Steven D'Aprano
On Tue, 25 Sep 2012 08:14:01 +1000, Chris Angelico wrote:

> Presumably the same way you reference a list element relative to
> end-of-list: negative numbers. However, this starts to feel like magic
> rather than attribute assignment - it's like manipulating the DOM in
> JavaScript, you set an attribute and stuff happens. Sure it's legal, but
> is it right? Also, it makes bounds checking awkward:
> 
> file.pos = 42 # Okay, you're at position 42 
> file.pos -= 10 # That should put you at position 32 
> foo = file.pos # Presumably foo is the integer 32
> file.pos -= 100 # What should this do? 
> foo -= 100 # But this sets foo to the integer -68 
> file.pos = foo # And this would set the file pointer 68 bytes
> from end-of-file.
> 
> I don't see it making sense for "file.pos -= 100" to suddenly put you
> near the end of the file; it should either cap and put you at position
> 0, or do what file.seek(-100,1) would do and throw an exception.

I would expect it to throw an exception, like file.seek and like list 
indexing.

> But
> doing the exact same operation on a saved snapshot of the position and
> reassigning it would then have quite different semantics in an unusual
> case, while still appearing identical in the normal case.

But this applies equally to file.seek and list indexing today. In neither 
case can you perform your own index operations outside of the file/list 
and expect to get the same result, for the simple and obvious reason that 
arithmetic doesn't perform the same bounds checking as actual seeking and 
indexing.

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


Who's laughing at my responses, and who's not?

2012-09-24 Thread Dwight Hutto
Been getting slammed by a few for some insignificant things, so who's
laughing at me, and who takes me seriously. I don't claim to be the
best, just trying to help.

So who doesn't want me around?

-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-24 Thread Steven D'Aprano
On Mon, 24 Sep 2012 16:43:24 -0700, Jayden wrote:

> Dear All,
> 
> I have a simple code as follows:
> 
> # Begin
> a = 1
> 
> def f():
> print a
> 
> def g():
> a = 20
> f()
> 
> g()
> #End
> 
> I think the results should be 20, but it is 1. Would you please tell me
> why?

You are expecting "dynamic scoping", Python uses "static scoping" (or 
lexical scoping). With lexical scoping, you can reason about the 
behaviour of a function by knowing only how and where it is defined. The 
caller is irrelevant.

Since function f is defined globally, and does not have its own local 
variable a, it will always see the global variable a no matter where it 
is called. So when you call f() from inside g(), f prints 1, the global 
a, not 20, g's local a.

While dynamic scoping has its uses, it is more tricky to use correctly. 
One can no longer understand the behaviour of a function just by reading 
the function's own code, knowing where and how it is defined. You also 
need to know where it is called. A function f that works perfectly when 
you call it from functions g, h, k, ... will suddenly misbehave (crash, 
or worse, behave wrongly) when called from function v because v 
accidentally changes some global variable that f relies on.

This is especially a danger for Python, because built-in functions like 
len, chr, ord, print (version 3 only), and many others are all global 
variables.

(Technically, they are in a third scope, the builtins, but that's 
equivalent to being global.)



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


Re: For Counter Variable

2012-09-24 Thread Paul Rubin
alex23  writes:
> To highlight the vast gulf between what you think you are and what you
> actually produce.

By now I think we're in the DNFTT zone.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Memory usage per top 10x usage per heapy

2012-09-24 Thread Dave Angel
On 09/24/2012 05:59 PM, MrsEntity wrote:
> Hi all,
>
> I'm working on some code that parses a 500kb, 2M line file 

Just curious;  which is it, two million lines, or half a million bytes?

> line by line and saves, per line, some derived strings into various data 
> structures. I thus expect that memory use should monotonically increase. 
> Currently, the program is taking up so much memory - even on 1/2 sized files 
> - that on 2GB machine 

which machine is 2gb, the Windows machine, or the VM?  You could get
thrashing at either level.

> I'm thrashing swap. What's strange is that heapy 
> (http://guppy-pe.sourceforge.net/) is showing that the code uses about 10x 
> less memory than reported by top, and the heapy data seems consistent with 
> what I was expecting based on the objects the code stores. I tried using 
> memory_profiler (http://pypi.python.org/pypi/memory_profiler) but it didn't 
> really provide any illuminating information. The code does create and discard 
> a number of objects per line of the file, but they should not be stored 
> anywhere, and heapy seems to confirm that. So, my questions are:
>
> 1) For those of you kind enough to help me figure out what's going on, what 
> additional data would you like? I didn't want swamp everyone with the code 
> and heapy/memory_profiler output but I can do so if it's valuable.
> 2) How can I diagnose (and hopefully fix) what's causing the massive memory 
> usage when it appears, from heapy, that the code is performing reasonably?
>
> Specs: Ubuntu 12.04 in Virtualbox on Win7/64, Python 2.7/64
>
> Thanks very much.

Tim raised most of my concerns, but I would point out that just because
you free up the memory from the Python doesn't mean it gets released
back to the system.  The C runtime manages its own heap, and is pretty
persistent about hanging onto memory once obtained.  It's not normally a
problem, since most small blocks are reused.  But it can get
fragmented.  And i have no idea how well Virtual Box maps the Linux
memory map into the Windows one.



-- 

DaveA

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


Re: which a is used?

2012-09-24 Thread Dwight Hutto
Anything else bitch, take time to think about it.
-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: For Counter Variable

2012-09-24 Thread Dwight Hutto
On Mon, Sep 24, 2012 at 8:32 PM, Littlefield, Tyler  wrote:
> On 9/24/2012 6:25 PM, Dwight Hutto wrote:
>>>
>>> To highlight the vast gulf between what you think you are and what you
>>> actually produce.
>>
>> I produce working code, and if it works, then I don't just think...I know.
>>
>> Working code != good code. Just an observation. Also, I've noticed a vast
>> differences between someone who can explain their answers as Alix has done
>> on multiple threads you've replied to in the last 5 minutes, and someone who
>> cobbles something together with "your variable isn't being shown right
I might have mispoke, forgive me for knowing several languages,and
getting a little class syntax wrong,. It's called computer science and
interdisciplinary study you dumb fucking double digit IQ'd twit.


>> because there's no self.a," which actually really makes no sense at all.

That was in a class scenario

>> Just my $0.02.
>
>
> --
> Take care,
> Ty
> http://tds-solutions.net
> The aspen project: a barebones light-weight mud engine:
> http://code.google.com/p/aspenmud
> He that will not reason is a bigot; he that cannot reason is a fool; he that
> dares not reason is a slave.
>
> --
> http://mail.python.org/mailman/listinfo/python-list



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: For Counter Variable

2012-09-24 Thread Littlefield, Tyler

On 9/24/2012 6:25 PM, Dwight Hutto wrote:

To highlight the vast gulf between what you think you are and what you
actually produce.

I produce working code, and if it works, then I don't just think...I know.

Working code != good code. Just an observation. Also, I've noticed a vast differences 
between someone who can explain their answers as Alix has done on multiple threads you've 
replied to in the last 5 minutes, and someone who cobbles something together with 
"your variable isn't being shown right because there's no self.a," which 
actually really makes no sense at all. Just my $0.02.


--
Take care,
Ty
http://tds-solutions.net
The aspen project: a barebones light-weight mud engine:
http://code.google.com/p/aspenmud
He that will not reason is a bigot; he that cannot reason is a fool; he that 
dares not reason is a slave.

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


Re: For Counter Variable

2012-09-24 Thread Oscar Benjamin
On 25 September 2012 01:17, Dwight Hutto  wrote:

> > Is the animated GIF on your website under 60MB yet?
> yeah a command line called convert, and taking out a few jpegs used to
> convert, and I can reduce it to any size, what's the fucking point of
> that question other than ignorant rhetoric, that you know is easily
> fixable?


Calm down! I don't want to read you to abusing and baiting each other.

If you do both mutually consent to continuing this conversation then do it
off list.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PIL questions: still supported? Problems on 2.7 for win? alternatives?

2012-09-24 Thread cjgohlke
On Monday, September 24, 2012 4:38:05 PM UTC-7, alex23 wrote:
> On Sep 25, 6:04 am, Gelonida N  wrote:
> 
> > This all does not sound very comforting. Why is there no fix on the
> 
> > official site?
> 
> 
> 
> Has a bug been logged about the issue?
> 

See issue #1 at 


Christoph

> 
> 
> The Plone community keeps a fairly up-to-date fork called Pillow,
> 
> we've had a lot of success using that locally:
> 
> 
> 
> http://pypi.python.org/pypi/Pillow/

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


Re: keeping information about players around

2012-09-24 Thread Dwight Hutto
On Mon, Sep 24, 2012 at 7:52 PM, alex23  wrote:
> On Sep 25, 9:44 am, Dwight Hutto  wrote:
>>  What DB are you recommending, check out sqlite's:
>>
>> http://www.cvedetails.com/vulnerability-list/vendor_id-9237/Sqlite.html
>
> Are you _seriously_ comparing _four_ vulnerabilities to 60+?
>
Even less if you use your own DB structure, and evn less in mysql if
you reject the injections of the known vulnerablities.

>> Maybe just a parsed file with data, and accessing data that you design.
>
> Just stop.

Why not suggest odbm or relational db's, this shows your lack of
complexity in design, so please stop your own Dunner-Kruning.



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: For Counter Variable

2012-09-24 Thread Dwight Hutto
> To highlight the vast gulf between what you think you are and what you
> actually produce.

I produce working code, and if it works, then I don't just think...I know.



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: For Counter Variable

2012-09-24 Thread Dwight Hutto
> Is the animated GIF on your website under 60MB yet?
yeah a command line called convert, and taking out a few jpegs used to
convert, and I can reduce it to any size, what's the fucking point of
that question other than ignorant rhetoric, that you know is easily
fixable?


-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: For Counter Variable

2012-09-24 Thread alex23
On Sep 25, 10:18 am, Dwight Hutto  wrote:
> what's the fucking point of that question

To highlight the vast gulf between what you think you are and what you
actually produce.


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


Re: which a is used?

2012-09-24 Thread alex23
On Sep 25, 9:43 am, Jayden  wrote:
> Dear All,
>
> I have a simple code as follows:
>
> # Begin
> a = 1
>
> def f():
>     print a
>
> def g():
>     a = 20
>     f()
>
> g()
> #End
>
> I think the results should be 20, but it is 1. Would you please tell me why?

Because you don't declare 'a' in 'f', it looks for 'a' in the
surrounding scope _where it was defined_, not where it was called.
Because 'a' in the module scope is 1, you'll get 1.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: keeping information about players around

2012-09-24 Thread Littlefield, Tyler

On 9/24/2012 3:14 PM, Dwight Hutto wrote:

I have yet another design question.
In my mud, zones are basically objects that manage a collection of rooms;
For example, a town would be it's own zone.
It holds information like maxRooms, the list of rooms as well as some other
data like player owners and access flags.
The access flags basically is a list holding the uid of a player, as well as
a bitarray of permissions on that zone. For example, a player might have the
ability to edit a zone, but not create rooms.
So I have a couple of questions based on this:
First, how viable would it be to keep a sort of player database around with
stats and that?



Well, what are the main items you need to retain for the player to
return to the game?



All of their contents are stored, which right now is done through Pickle. The 
stats is something different, as like I said, I don't want to unpickle an 
object every time I for example look at a zone and see what players have 
permissions on it.


Also, If this is a browser app I'd go with phpmyadmin, and MySQL If a 
tkinter/wxpython/etc app, then maybe sqlite.


PHPMyAdmin? Might I ask why? This is a mud, so it's all command based, 
so that's not even a question, but I'm kind of curious how PHPMyAdmin 
factors in there. It's a database creation tool from all I've ever seen 
of it, to define tables. Also, using it requires that I have it up on 
some server or another, and I'd really rather avoid that if I can.



It could contain the player's level, as well as other information like their
access (player, admin, builder etc), and then when someone does a whois on
the player I don't have to load that player up just to get data about them.
How would I keep the information updated? When I delete a player, I could
just delete the entry from the database by uid.
Second, would it be viable to have both the name and the uid stored in the
dictionary? Then I could look up by either of those?


Why would you use a dictionary, when it's DB manipulation you're after?



It is? I don't remember mentioning database anything in my thread. Unless I 
missed it, I mentioned pickle once or twice. But either way, I'd use a 
dictionary to keep a copy of {uid:object} for objects and {uid:player} for 
players. Makes lookup by uid pretty easy, as well as for any loaded objects.



Also, I have a couple more general-purpose questions relating to the mud.
When I load a zone, a list of rooms get stored on the zone, as well as
world. I thought it might make sense to store references to objects located
somewhere else but also on the world in WeakValueDictionaries to save
memory. It prevents them from being kept around (and thus having to be
deleted from the world when they lose their life), but also (I hope) will
save memory. Is a weakref going to be less expensive than a full reference?

For any case, you're going to have a DB field with a value, so it
doesn't look like a high value memory cost in the DB.


Second, I want to set up scripting so that you can script events for rooms
and npcs. For example, I plan to make some type of event system, so that
each type of object gets their own events. For example, when a player walks
into a room, they could trigger some sort of trap that would poison them.
This leads to a question though: I can store scripting on objects or in
separate files, but how is that generally associated and executed?

Well, the event doesn't need to be stored unless there is a necessity
to store the event, but if it's poisoned, then it's just a life
penalty, then no need to store the event, just the score loss.



I was asking about scripting the rooms, more than storing it. I need to have 
python code somewhere, somehow that attaches to the onEnter event in a room and 
subtracts hp from the player. Obviously you want that to be object specific and 
not have that script on everything.



Finally, I just want to make sure I'm doing things right. When I store data,
I just pickle it all, then load it back up again. My world object has an
attribute defined on it called picklevars, which is basically a list of
variables to pickle, and my __getstate__ just returns a dictionary of those.
All other objects are left "as-is" for now. Zones, (the entire zone and all
it's rooms) get pickled, as well as players and then the world object for
persistence. Is this the suggested way of doing things? I'll also pickle the
HelpManager object, which will basically contain a list of helpfiles that

I might suggest you take a look at the Blender Game Engine(python API)
at this point, unless you're just liking doing it the hard way to gain
experience(just like I have).



That's cool I guess, but I'm not taking your road and doing it the hard way for 
experience. The setup is more of a game engine, but beyond that, I don't think 
I need everything i get from a game library, especially since IIRC, Blender is 
mainly 3d focused?


Design the DB, and let the scene render what needs to be rendered, or 
list d

Re: which a is used?

2012-09-24 Thread Dwight Hutto
On Mon, Sep 24, 2012 at 7:57 PM, Dwight Hutto  wrote:
> On Mon, Sep 24, 2012 at 7:43 PM, Jayden  wrote:
>> Dear All,
>>
>> I have a simple code as follows:
>>
>> # Begin
>> a = 1
>>
>> def f():
>> print a
>>
>> def g():
>> a = 20
>> f()

this prints a from calling f() function

call print a wasn't in a class where it was self.a and changed, so it
performed the function f which prints a and a = 1, but g just assigns
the 20, and calls the f() function which shows a, there is no self.a,
nor a class to show this in.



>>
>> g()
>> #End
>>
>> I think the results should be 20, but it is 1. Would you please tell me why?
>>
>> Thanks a lot!
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>
> didn't return the value, or print it out
>
>
> --
> Best Regards,
> David Hutto
> CEO: http://www.hitwebdevelopment.com



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: For Counter Variable

2012-09-24 Thread alex23
On Sep 25, 9:49 am, Dwight Hutto  wrote:
> Rolling> your own version of an existing function from scratch is _not_ the
> > "professional" approach.
>
> Yes it is, if you don't know the builtin, and everyone has memory flaws.

Let me break this down for you in simple terms.

Code represents experience. Code that is considered important enough
to be in the standard library or as a built-in is something that
encapsulates a _lot_ of experience over time. You in your naive
approach to re-implement will _never capture that experience_. You'll
miss the edge cases that were already addressed. You'll over- or under-
extend the metaphor in ways the original doesn't.

And the first thing any experienced programmer would do when they
encountered your code is _refactor it to use the built-in_.

> Dude, you know jack shit, so go shovel this bullshit somewhere else,
> where people aren't intelligent enough to read the rest of my posts
> CEO: http://www.hitwebdevelopment.com

Is the animated GIF on your website under 60MB yet?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: keeping information about players around

2012-09-24 Thread alex23
On Sep 25, 9:44 am, Dwight Hutto  wrote:
>  What DB are you recommending, check out sqlite's:
>
> http://www.cvedetails.com/vulnerability-list/vendor_id-9237/Sqlite.html

Are you _seriously_ comparing _four_ vulnerabilities to 60+?

> Maybe just a parsed file with data, and accessing data that you design.

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


Re: Memory usage per top 10x usage per heapy

2012-09-24 Thread Junkshops

Hi Tim, thanks for the response.


- check how you're reading the data:  are you iterating over
   the lines a row at a time, or are you using
   .read()/.readlines() to pull in the whole file and then
   operate on that?
I'm using enumerate() on an iterable input (which in this case is the 
filehandle).



- check how you're storing them:  are you holding onto more
   than you think you are?
I've used ipython to look through my data structures (without going into 
ungainly detail, 2 dicts with X numbers of key/value pairs, where X = 
number of lines in the file), and everything seems to be working 
correctly. Like I say, heapy output looks reasonable - I don't see 
anything surprising there. In one dict I'm storing a id string (the 
first token in each line of the file) with values as (again, without 
going into massive detail) the md5 of the contents of the line. The 
second dict has the md5 as the key and an object with __slots__ set that 
stores the line number of the file and the type of object that line 
represents.



Would it hurt to switch from a
   dict to store your data (I'm assuming here) to using the
   anydbm module to temporarily persist the large quantity of
   data out to disk in order to keep memory usage lower?
That's the thing though - according to heapy, the memory usage *is* low 
and is more or less what I expect. What I don't understand is why top is 
reporting such vastly different memory usage. If a memory profiler is 
saying everything's ok, it makes it very difficult to figure out what's 
causing the problem. Based on heapy, a db based solution would be 
serious overkill.


-MrsE

On 9/24/2012 4:22 PM, Tim Chase wrote:

On 09/24/12 16:59, MrsEntity wrote:

I'm working on some code that parses a 500kb, 2M line file line
by line and saves, per line, some derived strings into various
data structures. I thus expect that memory use should
monotonically increase. Currently, the program is taking up so
much memory - even on 1/2 sized files - that on 2GB machine I'm
thrashing swap.

It might help to know what comprises the "into various data
structures".  I do a lot of ETL work on far larger files,
with similar machine specs, and rarely touch swap.


2) How can I diagnose (and hopefully fix) what's causing the
massive memory usage when it appears, from heapy, that the code
is performing reasonably?

I seem to recall that Python holds on to memory that the VM
releases, but that it *should* reuse it later.  So you'd get
the symptom of the memory-usage always increasing, never
decreasing.

Things that occur to me:

- check how you're reading the data:  are you iterating over
   the lines a row at a time, or are you using
   .read()/.readlines() to pull in the whole file and then
   operate on that?

- check how you're storing them:  are you holding onto more
   than you think you are?  Would it hurt to switch from a
   dict to store your data (I'm assuming here) to using the
   anydbm module to temporarily persist the large quantity of
   data out to disk in order to keep memory usage lower?

Without actual code, it's hard to do a more detailed
analysis.

-tkc


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


Re: For Counter Variable

2012-09-24 Thread Dwight Hutto
Propaganda over...

-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-24 Thread Dwight Hutto
On Mon, Sep 24, 2012 at 7:43 PM, Jayden  wrote:
> Dear All,
>
> I have a simple code as follows:
>
> # Begin
> a = 1
>
> def f():
> print a
>
> def g():
> a = 20
> f()
>
> g()
> #End
>
> I think the results should be 20, but it is 1. Would you please tell me why?
>
> Thanks a lot!
>
> --
> http://mail.python.org/mailman/listinfo/python-list

didn't return the value, or print it out


-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: For Counter Variable

2012-09-24 Thread Dwight Hutto
>> Well if you're learning then the builtin might be more like how we
>> answer students questions here, than those doing work.
>
> STOP SAYING THIS NONSENSE.
>
> Using a pre-defined function is _not_ the "student" approach.
What are talking about, I suggested they roll there own in several
responses this week.

Rolling
> your own version of an existing function from scratch is _not_ the
> "professional" approach.
Yes it is, if you don't know the builtin, and everyone has memory flaws.
> If you're unable to realise this, then please stop dispensing advice
> here like you know something.

Dude, you know jack shit, so go shovel this bullshit somewhere else,
where people aren't intelligent enough to read the rest of my posts


-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


which a is used?

2012-09-24 Thread Jayden
Dear All,

I have a simple code as follows:

# Begin
a = 1

def f():
print a

def g():
a = 20
f()

g()
#End

I think the results should be 20, but it is 1. Would you please tell me why?

Thanks a lot!

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


Re: For Counter Variable

2012-09-24 Thread alex23
On Sep 25, 9:39 am, Dwight Hutto  wrote:
> It's not the simpler solution I'm referring to, it's the fact that if
> you're learning, then you should be able to design the built-in, not
> just use it.

Garbage. I don't need to be able to build a SQLAlchemy to use it. I
don't need to be able to build an XML parser to use one. The whole
goddamn point of abstractions is to _ease the cognitive load_ in
building a complex system.

> You don't always know all the built-ins, so the builtin is simpler,
> but knowing how to code it yourself is the priority of learning to
> code in a higher level language, which should be simpler to the user
> of python.

"Higher level" means, in part, not _having to give a shit_ about the
sort of low level coding you're obsessed with. If it rocks your world
to declare your own index pointer and increment it on each pass of a
loop, knock yourself out. Just accept that others will criticise your
code for being "unpythonic". Why even use the language if you're not
prepared to _use_ the language...and that means _more than the
syntax_. It extends to the standard library and through to the entire
ecosystem that has developed around it.

People are drawn to Python to get shit done, not to spend pointless
time in recreating every wheel.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: For Counter Variable

2012-09-24 Thread Dwight Hutto
On Sep 25, 8:26 am, Dwight Hutto  wrote:
> It's a function usage. Not to be too serious, there are usually
> simpler solutions, and built in functions.

`enumerate` _is_ a built-in function. Please provide an example of a
"simpler solution".

It's not the simpler solution I'm referring to, it's the fact that if
you're learning, then you should be able to design the built-in, not
just use it.

You don't always know all the built-ins, so the builtin is simpler,
but knowing how to code it yourself is the priority of learning to
code in a higher level language, which should be simpler to the user
of python.

-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: keeping information about players around

2012-09-24 Thread Dwight Hutto
On Mon, Sep 24, 2012 at 7:28 PM, alex23  wrote:
> On Sep 25, 8:32 am, Dwight Hutto  wrote:
>> No, but phpmyadmin is a great GUI for MySQL
>
> If you're recommending MySQL use on the basis of phpmyadmin, you
> should also make sure to mention:
> http://www.phpmyadmin.net/home_page/security/
>
> Great GUI, maybe. Huge security hole, absolutely. Most organisations
> I've worked for won't allow it anywhere near their servers.
 What DB are you recommending, check out sqlite's:

http://www.cvedetails.com/vulnerability-list/vendor_id-9237/Sqlite.html

Maybe just a parsed file with data, and accessing data that you design.

-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: For Counter Variable

2012-09-24 Thread alex23
On Sep 25, 8:58 am, Dwight Hutto  wrote:
> Well if you're learning then the builtin might be more like how we
> answer students questions here, than those doing work.

STOP SAYING THIS NONSENSE.

Using a pre-defined function is _not_ the "student" approach. Rolling
your own version of an existing function from scratch is _not_ the
"professional" approach.

If you're unable to realise this, then please stop dispensing advice
here like you know something.


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


Re: PIL questions: still supported? Problems on 2.7 for win? alternatives?

2012-09-24 Thread alex23
On Sep 25, 6:04 am, Gelonida N  wrote:
> This all does not sound very comforting. Why is there no fix on the
> official site?

Has a bug been logged about the issue?

The Plone community keeps a fairly up-to-date fork called Pillow,
we've had a lot of success using that locally:

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


Re: keeping information about players around

2012-09-24 Thread alex23
On Sep 25, 8:32 am, Dwight Hutto  wrote:
> No, but phpmyadmin is a great GUI for MySQL

If you're recommending MySQL use on the basis of phpmyadmin, you
should also make sure to mention:
http://www.phpmyadmin.net/home_page/security/

Great GUI, maybe. Huge security hole, absolutely. Most organisations
I've worked for won't allow it anywhere near their servers.


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


Re: Memory usage per top 10x usage per heapy

2012-09-24 Thread Tim Chase
On 09/24/12 16:59, MrsEntity wrote:
> I'm working on some code that parses a 500kb, 2M line file line
> by line and saves, per line, some derived strings into various
> data structures. I thus expect that memory use should
> monotonically increase. Currently, the program is taking up so
> much memory - even on 1/2 sized files - that on 2GB machine I'm
> thrashing swap.

It might help to know what comprises the "into various data
structures".  I do a lot of ETL work on far larger files,
with similar machine specs, and rarely touch swap.

> 2) How can I diagnose (and hopefully fix) what's causing the
> massive memory usage when it appears, from heapy, that the code
> is performing reasonably?

I seem to recall that Python holds on to memory that the VM
releases, but that it *should* reuse it later.  So you'd get
the symptom of the memory-usage always increasing, never
decreasing.

Things that occur to me:

- check how you're reading the data:  are you iterating over
  the lines a row at a time, or are you using
  .read()/.readlines() to pull in the whole file and then
  operate on that?

- check how you're storing them:  are you holding onto more
  than you think you are?  Would it hurt to switch from a
  dict to store your data (I'm assuming here) to using the
  anydbm module to temporarily persist the large quantity of
  data out to disk in order to keep memory usage lower?

Without actual code, it's hard to do a more detailed
analysis.

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


Re: python file API

2012-09-24 Thread Chris Kaynor
On Mon, Sep 24, 2012 at 3:37 PM, Ian Kelly  wrote:
> On Mon, Sep 24, 2012 at 4:14 PM, Chris Angelico  wrote:
>> file.pos = 42 # Okay, you're at position 42
>> file.pos -= 10 # That should put you at position 32
>> foo = file.pos # Presumably foo is the integer 32
>> file.pos -= 100 # What should this do?
>
> Since ints are immutable, the language specifies that it should be the
> equivalent of "file.pos = file.pos - 100", so it should set the file
> pointer to 68 bytes before EOF.

There is no reason that it has to be an int object, however. It could
well return a "FilePosition" object which does not allow subtraction
to produce a negative result. Not saying its a good idea... Similarly,
it could be a more complex object with properties on it to determine
whether to seek from beginning or end.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A little morning puzzle

2012-09-24 Thread Dwight Hutto
The posted code produces neither a set nor any keys;
> it prints out the same predetermined non-key value multiple times.

This shows multiple dicts, with the same keys, and shows different
values, and some with the same, and that is, in my opinion what the OP
asked for:

a = {}
a['dict'] = 1

b = {}
b['dict'] = 2

c = {}
c['dict'] = 1

d = {}
d['dict'] = 3

e = {}
e['dict'] = 1


x = [a,b,c,d,e]
count = 0
collection_count = 0
search_variable = 1
for dict_key_search in x:
if dict_key_search['dict'] == search_variable:
print "Match count found: #%i = %i" % (count,search_variable)
collection_count += 1
count += 1
print collection_count



The OP can jump in and tell me to alter the example, if they want to.




-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python file API

2012-09-24 Thread Mark Lawrence

On 24/09/2012 22:35, zipher wrote:

For some time now, I've wanted to suggest a better abstraction for the  
type in Python.  It currently uses an antiquated C-style interface for moving around 
in a file, with methods like tell() and seek().  But after attributes were introduced 
to Python, it seems it should be re-addressed.

Let file-type have an attribute .pos for position.   Now you can get rid of the 
seek() and tell() methods and manipulate the file pointer more easily with 
standard arithmetic operations.


file.pos = x0ae1  #move file pointer to an absolute address
file.pos +=1#increment the file pointer one byte
curr_pos = file.pos  #read current file pointer


You've now simplified the API by the removal of two obscure legacy methods and replaced 
them with a more basic one called "position".

Thoughts?

markj



This strikes me as being a case of if it ain't broke don't fix it.

--
Cheers.

Mark Lawrence.

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


Re: keeping information about players around

2012-09-24 Thread Dwight Hutto
> is just a way of generating that. Any language works on the back
> end... and PHP isn't the best :) Python does quite well at that task;
> I have a tiny little Python script that uses a web browser as its
> front ent.

This stems from my limited usage of python in the browser(I usually
use it for prototype apps). It's usually going to be the difference
between echo or print html/javascript, and perform an iteration for
table, or formulaic computation within a standard function syntax.


-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python file API

2012-09-24 Thread Chris Angelico
On Tue, Sep 25, 2012 at 8:37 AM, Ian Kelly  wrote:
> On Mon, Sep 24, 2012 at 4:14 PM, Chris Angelico  wrote:
>> file.pos = 42 # Okay, you're at position 42
>> file.pos -= 10 # That should put you at position 32
>> foo = file.pos # Presumably foo is the integer 32
>> file.pos -= 100 # What should this do?
>
> Since ints are immutable, the language specifies that it should be the
> equivalent of "file.pos = file.pos - 100", so it should set the file
> pointer to 68 bytes before EOF.

Oh, I forgot that guaranteed equivalency. Well, at least it removes
the ambiguity. I don't like it though.

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


Re: A little morning puzzle

2012-09-24 Thread Ian Kelly
On Mon, Sep 24, 2012 at 4:07 PM, Dwight Hutto  wrote:
> They stated:
>
> I have a list of dictionaries.  They all have the same keys.  I want to find 
> the
> set of keys where all the dictionaries have the same values.  Suggestions?
>
> No, to me it meant to find similar values in several dicts with the
> same key, and value. So I created several dicts, and some with the
> same key and value, and showed the matches.

Well, to me at least it is clear that when the OP writes "I want to
find the *set* of *keys*..." (emphasis added), then setting aside the
rest of the problem statement, the result of the algorithm should be a
set (or at least something set-like), and the contents of the set
should be keys.  The posted code produces neither a set nor any keys;
it prints out the same predetermined non-key value multiple times.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python file API

2012-09-24 Thread Oscar Benjamin
 On 24 September 2012 23:41, Mark Adam  wrote:

> > seek() and tell() can raise exceptions on some files. Exposing pos as an
> > attribute and allowing it to be manipulated with attribute access gives
> the
> > impression that it is always meaningful to do so.
>
> It's a good point, python already is allowing exceptions to be caught
> within "properties",  so exceptions from such an attribute could
> presumably be handled similarly.
>

There are many situations where a little bit of attribute access magic is a
good thing. However, operations that involve the underlying OS and that are
prone to raising exceptions even in bug free code should not be performed
implicitly like this. I find the following a little cryptic:
try:
f.pos = 256
except IOError:
print('Unseekable file')

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


Re: For Counter Variable

2012-09-24 Thread Dwight Hutto
> *How* would one implement this better, more simply (for the user, not the
> implementator) or in a more readable manner?  Chose *any* one of those.

Well if you're learning then the builtin might be more like how we
answer students questions here, than those doing work.

Write out the algorithmic function, and if you find one you can stuff
a few parameters in fine, but you still now how to do it by yourself
algorithmically.


-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: keeping information about players around

2012-09-24 Thread Chris Angelico
On Tue, Sep 25, 2012 at 8:31 AM, Dwight Hutto  wrote:
> And in the end it's usually html, php, css, javascript in the browser,
> atleast for me it is. I'm just starting to utilize python in that
> area, so excuse the naivety.

In the browser it's HTML, CSS, JavaScript (ECMAScript, etc, etc); PHP
is just a way of generating that. Any language works on the back
end... and PHP isn't the best :) Python does quite well at that task;
I have a tiny little Python script that uses a web browser as its
front ent.

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


Re: For Counter Variable

2012-09-24 Thread Joshua Landau
On 24 September 2012 23:26, Dwight Hutto  wrote:

> On Mon, Sep 24, 2012 at 6:09 PM, Ethan Furman  wrote:
> > jimbo1qaz wrote:
> >>
> >> On Sunday, September 23, 2012 9:36:19 AM UTC-7, jimbo1qaz wrote:
> >>>
> >>> Am I missing something obvious, or do I have to manually put in a
> counter
> >>> in the for loops? That's a very basic request, but I couldn't find
> anything
> >>> in the documentation.
> >>
> >>
> >> Ya, they should really give a better way, but for now, enumerate works
> >> pretty well.
> >
> >
> > ROFLOL!!
> >
> > I look forward to the day when you look back on that statement and think,
> > "Wow, I've come a long way!"
> >
>
> It's a function usage. Not to be too serious, there are usually
> simpler solutions, and built in functions.
>
> But you usually sticks with what works, and seems timely in return of
> data output
>

This is not a criticism, but actual curiosity.

*How* would one implement this better, more simply (for the user, not the
implementator) or in a more readable manner?  Chose *any* one of those.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: keeping information about players around

2012-09-24 Thread Dwight Hutto
>> Out of curiosity, why? MySQL isn't magically better for everything
>> where data ends up displayed in a web browser.
>
> No, but phpmyadmin is a great GUI for MySQL
>
Meaning, it gives a great web app, that sqlite doesn't have...yet.
It's the tools around MySQL for me, that gives it the umph it needs to
be a great DB, with the GUI (phpmyadmin)to match, and short
reference/learni8ng curve to use php in this instance.

-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python file API

2012-09-24 Thread Ian Kelly
On Mon, Sep 24, 2012 at 4:14 PM, Chris Angelico  wrote:
> file.pos = 42 # Okay, you're at position 42
> file.pos -= 10 # That should put you at position 32
> foo = file.pos # Presumably foo is the integer 32
> file.pos -= 100 # What should this do?

Since ints are immutable, the language specifies that it should be the
equivalent of "file.pos = file.pos - 100", so it should set the file
pointer to 68 bytes before EOF.

> foo -= 100 # But this sets foo to the integer -68
> file.pos = foo # And this would set the file pointer 68 bytes from 
> end-of-file.

Which is the same result.

> I don't see it making sense for "file.pos -= 100" to suddenly put you
> near the end of the file; it should either cap and put you at position
> 0, or do what file.seek(-100,1) would do and throw an exception.

I agree, but the language doesn't allow those semantics.

Also, what about the use of `f.seek(0, os.SEEK_END)` to seek to EOF?
I'm not certain what the use cases are, but a quick google reveals
that this does happen in real code.  If a pos of 0 means BOF, and a
pos of -1 means 1 byte before EOF, then how do you seek to EOF without
knowing the file length?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python file API

2012-09-24 Thread Dave Angel
(forwarding to the list)

On 09/24/2012 06:23 PM, Mark Adam wrote:
> On Mon, Sep 24, 2012 at 4:49 PM, Dave Angel  wrote:
>> On 09/24/2012 05:35 PM, zipher wrote:
>>> For some time now, I've wanted to suggest a better abstraction for the 
>>>  type in Python.  It currently uses an antiquated C-style interface 
>>> for moving around in a file, with methods like tell() and seek().  But 
>>> after attributes were introduced to Python, it seems it should be 
>>> re-addressed.
>>>
>>> Let file-type have an attribute .pos for position.   Now you can get rid of 
>>> the seek() and tell() methods and manipulate the file pointer more easily 
>>> with standard arithmetic operations.
>>>
>> file.pos = x0ae1  #move file pointer to an absolute address
>> file.pos +=1#increment the file pointer one byte
>> curr_pos = file.pos  #read current file pointer
> 
>> And what approach would you use for positioning relative to
>> end-of-file?  That's currently done with an optional second parameter to
>> seek() method.
> 
> As size is an oft-useful construct, let it (like .name) be part of the
> descriptor.  Then
> 
 file.pos = file.size - 80  #80 chars from end-of-file
> 
> (Or, one could make slices part of the API...)
> 
> mark
> 

Well, if one of the goals was to reduce the number of attributes, we're
now back to the original number of them.

-- 

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


Re: python file API

2012-09-24 Thread zipher
You raise a valid point: that by abstracting the file pointer into a position 
attribute you risk "de-coupling" the conceptual link between the underlying 
file and your abstraction in the python interpreter, but I think the programmer 
can take responsibility for maintaining the abstraction.  

The key possible fault will be whether you can trap (OS-level) exceptions when 
assigning to the pos attribute beyond the bounds of the actual file on the 
system... 

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


Re: keeping information about players around

2012-09-24 Thread Dwight Hutto
On Mon, Sep 24, 2012 at 6:19 PM, Chris Angelico  wrote:
> On Tue, Sep 25, 2012 at 7:14 AM, Dwight Hutto  wrote:
>> Also, If this is a browser app I'd go with phpmyadmin, and MySQL
>>
>> If a tkinter/wxpython/etc app, then maybe sqlite.
>
> Out of curiosity, why? MySQL isn't magically better for everything
> where data ends up displayed in a web browser.

No, but phpmyadmin is a great GUI for MySQL

Unless you're planning
> to also reference this database from some other language, it's going
> to make little difference what backend you use; and even if you are
> using multiple languages, it's usually not difficult to find overlap.
Well this is python, but in the browser a little echo, instead of
print, isn't that bad for conversational php.

And in the end it's usually html, php, css, javascript in the browser,
atleast for me it is. I'm just starting to utilize python in that
area, so excuse the naivety.



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: For Counter Variable

2012-09-24 Thread Dwight Hutto
On Mon, Sep 24, 2012 at 6:09 PM, Ethan Furman  wrote:
> jimbo1qaz wrote:
>>
>> On Sunday, September 23, 2012 9:36:19 AM UTC-7, jimbo1qaz wrote:
>>>
>>> Am I missing something obvious, or do I have to manually put in a counter
>>> in the for loops? That's a very basic request, but I couldn't find anything
>>> in the documentation.
>>
>>
>> Ya, they should really give a better way, but for now, enumerate works
>> pretty well.
>
>
> ROFLOL!!
>
> I look forward to the day when you look back on that statement and think,
> "Wow, I've come a long way!"
>

It's a function usage. Not to be too serious, there are usually
simpler solutions, and built in functions.

But you usually sticks with what works, and seems timely in return of
data output

-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: keeping information about players around

2012-09-24 Thread Chris Angelico
On Tue, Sep 25, 2012 at 7:14 AM, Dwight Hutto  wrote:
> Also, If this is a browser app I'd go with phpmyadmin, and MySQL
>
> If a tkinter/wxpython/etc app, then maybe sqlite.

Out of curiosity, why? MySQL isn't magically better for everything
where data ends up displayed in a web browser. Unless you're planning
to also reference this database from some other language, it's going
to make little difference what backend you use; and even if you are
using multiple languages, it's usually not difficult to find overlap.

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


Re: For Counter Variable

2012-09-24 Thread Ethan Furman

jimbo1qaz wrote:

On Sunday, September 23, 2012 9:36:19 AM UTC-7, jimbo1qaz wrote:

Am I missing something obvious, or do I have to manually put in a counter in 
the for loops? That's a very basic request, but I couldn't find anything in the 
documentation.


Ya, they should really give a better way, but for now, enumerate works pretty 
well.


ROFLOL!!

I look forward to the day when you look back on that statement and 
think, "Wow, I've come a long way!"


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


Re: python file API

2012-09-24 Thread Chris Angelico
On Tue, Sep 25, 2012 at 7:49 AM, Dave Angel  wrote:
> On 09/24/2012 05:35 PM, zipher wrote:
>> Let file-type have an attribute .pos for position.   Now you can get rid of 
>> the seek() and tell() methods and manipulate the file pointer more easily 
>> with standard arithmetic operations.
>>
> file.pos = x0ae1  #move file pointer to an absolute address
> file.pos +=1#increment the file pointer one byte
> curr_pos = file.pos  #read current file pointer
>
> And what approach would you use for positioning relative to
> end-of-file?  That's currently done with an optional second parameter to
> seek() method.

Presumably the same way you reference a list element relative to
end-of-list: negative numbers. However, this starts to feel like magic
rather than attribute assignment - it's like manipulating the DOM in
JavaScript, you set an attribute and stuff happens. Sure it's legal,
but is it right? Also, it makes bounds checking awkward:

file.pos = 42 # Okay, you're at position 42
file.pos -= 10 # That should put you at position 32
foo = file.pos # Presumably foo is the integer 32
file.pos -= 100 # What should this do?
foo -= 100 # But this sets foo to the integer -68
file.pos = foo # And this would set the file pointer 68 bytes from end-of-file.

I don't see it making sense for "file.pos -= 100" to suddenly put you
near the end of the file; it should either cap and put you at position
0, or do what file.seek(-100,1) would do and throw an exception. But
doing the exact same operation on a saved snapshot of the position and
reassigning it would then have quite different semantics in an unusual
case, while still appearing identical in the normal case.

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


Re: A little morning puzzle

2012-09-24 Thread Dwight Hutto
On Mon, Sep 24, 2012 at 5:18 PM, Ethan Furman  wrote:
> Ian Kelly wrote:
>>
>> On Sat, Sep 22, 2012 at 9:44 PM, Dwight Hutto 
>> wrote:
>>>
>>> Why don't you all look at the code(python and C), and tell me how much
>>> code it took to write the functions the other's examples made use of
>>> to complete the task.n in or register.
>>>
>>> Just because you can use a function, and make it look easier, doesn't
>>> mean the function you used had less code than mine, so if you look at
>>> the whole of what you used to make it simpler, mine was on point.
>>
>>
>> I understood the sarcastic comments (the first one, at least) to be
>> referring to your solution as bad not due to complexity (I actually
>> thought it was quite simple), but because it does not solve the
>> problem as stated.  The problem posed by the OP was to find a set of
>> common keys that are associated with the same values in each dict.

>> Your solution takes only one predetermined key-value pair and counts
>> how many times it occurs in the dicts, which isn't even close to what

They stated:

I have a list of dictionaries.  They all have the same keys.  I want to find the
set of keys where all the dictionaries have the same values.  Suggestions?

No, to me it meant to find similar values in several dicts with the
same key, and value. So I created several dicts, and some with the
same key and value, and showed the matches.

The OP can comment as to whether that is the correct interpretation of
the situation.


>> was requested.  With your comment of "Might be better ones, though", I
>> actually thought that you were aware of this and were being
>> intentionally satirical.

I am. I just write out the algorithm as I understand the OP to want
it, to give my version of the example.

-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Memory usage per top 10x usage per heapy

2012-09-24 Thread MrsEntity
Hi all,

I'm working on some code that parses a 500kb, 2M line file line by line and 
saves, per line, some derived strings into various data structures. I thus 
expect that memory use should monotonically increase. Currently, the program is 
taking up so much memory - even on 1/2 sized files - that on 2GB machine I'm 
thrashing swap. What's strange is that heapy (http://guppy-pe.sourceforge.net/) 
is showing that the code uses about 10x less memory than reported by top, and 
the heapy data seems consistent with what I was expecting based on the objects 
the code stores. I tried using memory_profiler 
(http://pypi.python.org/pypi/memory_profiler) but it didn't really provide any 
illuminating information. The code does create and discard a number of objects 
per line of the file, but they should not be stored anywhere, and heapy seems 
to confirm that. So, my questions are:

1) For those of you kind enough to help me figure out what's going on, what 
additional data would you like? I didn't want swamp everyone with the code and 
heapy/memory_profiler output but I can do so if it's valuable.
2) How can I diagnose (and hopefully fix) what's causing the massive memory 
usage when it appears, from heapy, that the code is performing reasonably?

Specs: Ubuntu 12.04 in Virtualbox on Win7/64, Python 2.7/64

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


Re: python file API

2012-09-24 Thread Chris Kaynor
On Mon, Sep 24, 2012 at 2:49 PM, Dave Angel  wrote:
>
> And what approach would you use for positioning relative to
> end-of-file?  That's currently done with an optional second parameter to
> seek() method.
>

I'm not advocating for or against the idea, but that could be handled
the same way indexing into lists can index relative to the end:
negative indices.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python file API

2012-09-24 Thread Oscar Benjamin
On 24 September 2012 22:35, zipher  wrote:

> For some time now, I've wanted to suggest a better abstraction for the
>  type in Python.  It currently uses an antiquated C-style interface
> for moving around in a file, with methods like tell() and seek().  But
> after attributes were introduced to Python, it seems it should be
> re-addressed.
>
> Let file-type have an attribute .pos for position.   Now you can get rid
> of the seek() and tell() methods and manipulate the file pointer more
> easily with standard arithmetic operations.
>
> >>> file.pos = x0ae1  #move file pointer to an absolute address
> >>> file.pos +=1#increment the file pointer one byte
> >>> curr_pos = file.pos  #read current file pointer
>

seek() and tell() can raise exceptions on some files. Exposing pos as an
attribute and allowing it to be manipulated with attribute access gives the
impression that it is always meaningful to do so.

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


Re: A little morning puzzle

2012-09-24 Thread Ethan Furman

Ian Kelly wrote:

On Sat, Sep 22, 2012 at 9:44 PM, Dwight Hutto  wrote:

Why don't you all look at the code(python and C), and tell me how much
code it took to write the functions the other's examples made use of
to complete the task.

Just because you can use a function, and make it look easier, doesn't
mean the function you used had less code than mine, so if you look at
the whole of what you used to make it simpler, mine was on point.


I understood the sarcastic comments (the first one, at least) to be
referring to your solution as bad not due to complexity (I actually
thought it was quite simple), but because it does not solve the
problem as stated.  The problem posed by the OP was to find a set of
common keys that are associated with the same values in each dict.
Your solution takes only one predetermined key-value pair and counts
how many times it occurs in the dicts, which isn't even close to what
was requested.  With your comment of "Might be better ones, though", I
actually thought that you were aware of this and were being
intentionally satirical.


Unlikely.

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


Re: python file API

2012-09-24 Thread Dave Angel
On 09/24/2012 05:35 PM, zipher wrote:
> For some time now, I've wanted to suggest a better abstraction for the  
> type in Python.  It currently uses an antiquated C-style interface for moving 
> around in a file, with methods like tell() and seek().  But after attributes 
> were introduced to Python, it seems it should be re-addressed.
>
> Let file-type have an attribute .pos for position.   Now you can get rid of 
> the seek() and tell() methods and manipulate the file pointer more easily 
> with standard arithmetic operations. 
>
 file.pos = x0ae1  #move file pointer to an absolute address 
 file.pos +=1#increment the file pointer one byte
 curr_pos = file.pos  #read current file pointer
> You've now simplified the API by the removal of two obscure legacy methods 
> and replaced them with a more basic one called "position".
>
> Thoughts?
>
> markj

And what approach would you use for positioning relative to
end-of-file?  That's currently done with an optional second parameter to
seek() method.




-- 

DaveA

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


python file API

2012-09-24 Thread zipher
For some time now, I've wanted to suggest a better abstraction for the  
type in Python.  It currently uses an antiquated C-style interface for moving 
around in a file, with methods like tell() and seek().  But after attributes 
were introduced to Python, it seems it should be re-addressed.

Let file-type have an attribute .pos for position.   Now you can get rid of the 
seek() and tell() methods and manipulate the file pointer more easily with 
standard arithmetic operations. 

>>> file.pos = x0ae1  #move file pointer to an absolute address 
>>> file.pos +=1#increment the file pointer one byte
>>> curr_pos = file.pos  #read current file pointer

You've now simplified the API by the removal of two obscure legacy methods and 
replaced them with a more basic one called "position".

Thoughts?

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


Re: Anyone able to help on installing packages?

2012-09-24 Thread Dwight Hutto
You could just take the python code, and put it in the site packages
file. Depends on the package.

-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Anyone able to help on installing packages?

2012-09-24 Thread Oscar Benjamin
On 24 September 2012 21:27, John Mordecai Dildy  wrote:

> Anyone have Ideas on nose and distribute?


Your post has no context and simply asks a very vague question. Had you
explained what you tried and what happened and perhaps shown an error
message I might have been able to answer your question in this post.

Presumably you tried something before posting?

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


Re: A little morning puzzle

2012-09-24 Thread Dwight Hutto
> Ergo: 'enumerate()' is the correct suggestion over manually
> maintaining your own index, despite it ostensibly being "more" code
> due to its implementation.

But, therefore, that doesn't mean that the coder can just USE a
function, and not be able to design it themselves. So 'correct
suggestion' is a moot point.

-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: keeping information about players around

2012-09-24 Thread Dwight Hutto
> I have yet another design question.
> In my mud, zones are basically objects that manage a collection of rooms;
> For example, a town would be it's own zone.
> It holds information like maxRooms, the list of rooms as well as some other
> data like player owners and access flags.
> The access flags basically is a list holding the uid of a player, as well as
> a bitarray of permissions on that zone. For example, a player might have the
> ability to edit a zone, but not create rooms.
> So I have a couple of questions based on this:
> First, how viable would it be to keep a sort of player database around with
> stats and that?
Well, what are the main items you need to retain for the player to
return to the game?

Also, If this is a browser app I'd go with phpmyadmin, and MySQL

If a tkinter/wxpython/etc app, then maybe sqlite.

> It could contain the player's level, as well as other information like their
> access (player, admin, builder etc), and then when someone does a whois on
> the player I don't have to load that player up just to get data about them.
> How would I keep the information updated? When I delete a player, I could
> just delete the entry from the database by uid.
> Second, would it be viable to have both the name and the uid stored in the
> dictionary? Then I could look up by either of those?
>
Why would you use a dictionary, when it's DB manipulation you're after?

> Also, I have a couple more general-purpose questions relating to the mud.
> When I load a zone, a list of rooms get stored on the zone, as well as
> world. I thought it might make sense to store references to objects located
> somewhere else but also on the world in WeakValueDictionaries to save
> memory. It prevents them from being kept around (and thus having to be
> deleted from the world when they lose their life), but also (I hope) will
> save memory. Is a weakref going to be less expensive than a full reference?

For any case, you're going to have a DB field with a value, so it
doesn't look like a high value memory cost in the DB.

> Second, I want to set up scripting so that you can script events for rooms
> and npcs. For example, I plan to make some type of event system, so that
> each type of object gets their own events. For example, when a player walks
> into a room, they could trigger some sort of trap that would poison them.
> This leads to a question though: I can store scripting on objects or in
> separate files, but how is that generally associated and executed?

Well, the event doesn't need to be stored unless there is a necessity
to store the event, but if it's poisoned, then it's just a life
penalty, then no need to store the event, just the score loss.

> Finally, I just want to make sure I'm doing things right. When I store data,
> I just pickle it all, then load it back up again. My world object has an
> attribute defined on it called picklevars, which is basically a list of
> variables to pickle, and my __getstate__ just returns a dictionary of those.
> All other objects are left "as-is" for now. Zones, (the entire zone and all
> it's rooms) get pickled, as well as players and then the world object for
> persistence. Is this the suggested way of doing things? I'll also pickle the
> HelpManager object, which will basically contain a list of helpfiles that

I might suggest you take a look at the Blender Game Engine(python API)
at this point, unless you're just liking doing it the hard way to gain
experience(just like I have).

Design the DB, and let the scene render what needs to be rendered, or
list data  for, and those are the necessities to be stored.

-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: request for another code review

2012-09-24 Thread Littlefield, Tyler

On 9/23/2012 9:48 PM, alex23 wrote:

On Sep 23, 6:14 am, "Littlefield, Tyler"  wrote:

I've gotten a bit farther into my python mud, and wanted to request
another code review for style and the like.

Are you familiar with codereview.stackexchange.com ?



I actually wasn't, thanks!



(This isn't to dissuade you from posting such requests here, just to
help increase the chance of eyeballs on your code.)



--
Take care,
Ty
http://tds-solutions.net
The aspen project: a barebones light-weight mud engine:
http://code.google.com/p/aspenmud
He that will not reason is a bigot; he that cannot reason is a fool; he that 
dares not reason is a slave.

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


Re: request for another code review

2012-09-24 Thread Littlefield, Tyler

On 9/23/2012 9:48 PM, alex23 wrote:

On Sep 23, 6:14 am, "Littlefield, Tyler"  wrote:

I've gotten a bit farther into my python mud, and wanted to request
another code review for style and the like.

Are you familiar with codereview.stackexchange.com ?



I actually wasn't, thanks!



(This isn't to dissuade you from posting such requests here, just to
help increase the chance of eyeballs on your code.)



--
Take care,
Ty
http://tds-solutions.net
The aspen project: a barebones light-weight mud engine:
http://code.google.com/p/aspenmud
He that will not reason is a bigot; he that cannot reason is a fool; he that 
dares not reason is a slave.

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


Re: metaclass question

2012-09-24 Thread Ian Kelly
On Mon, Sep 24, 2012 at 11:43 AM, Chris Withers  wrote:
> Hi All,
>
> Is there a metaclass-y way I could cause the following:
>
> class TheParser(Parser):
> def handle_ARecord(self):
> pass
> def handle_ARecord(self):
> pass
>
> ...to raise an exception as a result of the 'handle_ARecord' name being
> reused?

In Python 2.x, no.

In Python 3.x, the __prepare__ method of the metaclass allows you to
specify a custom namespace object for the class definition.  The most
commonly cited use case is to use an OrderedDict to remember the order
in which the attributes are defined, but you could also use a dict
subclass that raises an exception if an attribute is redefined.  See
the docs at:

http://docs.python.org/dev/reference/datamodel.html#preparing-the-class-namespace
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >