Re: How to pass class instance to a method?

2012-11-26 Thread Alain Ketterlin
ALeX inSide  writes:

> How to "statically type" an instance of class that I pass to a method
> of other instance?

Python does not do static typing.

> I suppose there shall be some kind of method decorator to treat an
> argument as an instance of class?

Decorators are an option. Another is the use of the new parameter
annotations (param : expr) in function/method parameters. (That's python
3, not 2).

> Generally it is needed so IDE (PyCharm) can auto-complete instance's
> methods and properties.

You can't expect static info on the class of the object referenced by
any name, unless you impose strong conventions on the code.

> Pseudo-python-code example:
>
> i = MyClass()
>
> xxx(i, 1, 2);
>
> ...
> def xxx(self, MyClass myclass, number, foobar):
>myclass.classsmethod() #myclass - is an instance of known class

Could: xxx(self,myclass : MyClass, ...)

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


how to pass "echo t | " input to subprocess.check_output() method

2012-11-26 Thread dachakku
Hi all,

I want to list the repositories in svn using python. For this i have used below 
command,
" res = subprocess.check_output(["svn.exe", "list", 
"Https://127.0.0.1:443/svn/Repos"], stderr=subprocess.STDOUT) "

but it throws an exception, since it requires an user input to validate 
certificate,
" (R)eject, accept (t)emporarily or accept (p)ermanently? "

from Command prompt im able to pass the input while calling the process, and im 
able to get the output

"echo t | svn list Https://127.0.0.1:443/svn/Repos"

But i dont know how to pass the "echo t | " in subprocess.check_output while 
calling a process.
Is there a way to do this?
Please help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to pass "echo t | " input to subprocess.check_output() method

2012-11-26 Thread Chris Rebert
On Nov 26, 2012 2:41 AM,  wrote:
>
> Hi all,
>
> I want to list the repositories in svn using python. For this i have used
below command,
> " res = subprocess.check_output(["svn.exe", "list", "
Https://127.0.0.1:443/svn/Repos"], stderr=subprocess.STDOUT) "
>
> but it throws an exception, since it requires an user input to validate
certificate,
> " (R)eject, accept (t)emporarily or accept (p)ermanently? "
>
> from Command prompt im able to pass the input while calling the process,
and im able to get the output
>
> "echo t | svn list Https://127.0.0.1:443/svn/Repos"
>
> But i dont know how to pass the "echo t | " in subprocess.check_output
while calling a process.
> Is there a way to do this?

Use subprocess.Popen.communicate() instead, passing "t\n" as the input.

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


Re: how to pass "echo t | " input to subprocess.check_output() method

2012-11-26 Thread Duncan Booth
[email protected] wrote:

> Hi all,
> 
> I want to list the repositories in svn using python. For this i have
> used below command, " res = subprocess.check_output(["svn.exe",
> "list", "Https://127.0.0.1:443/svn/Repos"], stderr=subprocess.STDOUT)
> " 
> 
> but it throws an exception, since it requires an user input to
> validate certificate, " (R)eject, accept (t)emporarily or accept
> (p)ermanently? " 
> 
> from Command prompt im able to pass the input while calling the
> process, and im able to get the output 
> 
> "echo t | svn list Https://127.0.0.1:443/svn/Repos"
> 
> But i dont know how to pass the "echo t | " in subprocess.check_output
> while calling a process. Is there a way to do this?
> Please help.
> 

Run svn once manually as the same user that is running your script then 
when you get the prompt verify that it is indeed the certificate and 
accept it permanently. That will allow your script to work proviuded the 
certificate doesn't change.

Also, change the command you run to include the --non-interactive 
command line option so that if the certificate ever does change in the 
future the command will fail rather than prompting.

Alternatively use --non-interactive --trust-server-cert to just accept 
any old server regardless what certificate it uses, but be aware that 
this impacts security.

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to pass "echo t | " input to subprocess.check_output() method

2012-11-26 Thread Kushal Kumaran
[email protected] writes:

> Hi all,
>
> I want to list the repositories in svn using python. For this i have used 
> below command,
> " res = subprocess.check_output(["svn.exe", "list", 
> "Https://127.0.0.1:443/svn/Repos"], stderr=subprocess.STDOUT) "
>
> but it throws an exception, since it requires an user input to validate 
> certificate,
> " (R)eject, accept (t)emporarily or accept (p)ermanently? "
>
> from Command prompt im able to pass the input while calling the process, and 
> im able to get the output
>
> "echo t | svn list Https://127.0.0.1:443/svn/Repos"
>
> But i dont know how to pass the "echo t | " in subprocess.check_output while 
> calling a process.
> Is there a way to do this?
> Please help.


You could pass in a stdin argument to subprocess.check_output with a
value of 't\n'.

However, you might want to use something like http://pysvn.tigris.org/,
which is a python library for accessing subversion repositories.

-- 
regards,
kushal

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


Re: how to pass "echo t | " input to subprocess.check_output() method

2012-11-26 Thread Chris Rebert
On Nov 26, 2012 3:03 AM, "Kushal Kumaran" 
wrote:
> [email protected] writes:
> > I want to list the repositories in svn using python. For this i have
used below command,
> > " res = subprocess.check_output(["svn.exe", "list", "
Https://127.0.0.1:443/svn/Repos"], stderr=subprocess.STDOUT) "
> >
> > but it throws an exception, since it requires an user input to validate
certificate,
> > " (R)eject, accept (t)emporarily or accept (p)ermanently? "
> >
> > from Command prompt im able to pass the input while calling the
process, and im able to get the output
> >
> > "echo t | svn list Https://127.0.0.1:443/svn/Repos"
> >
> > But i dont know how to pass the "echo t | " in subprocess.check_output
while calling a process.
>
> You could pass in a stdin argument to subprocess.check_output with a
> value of 't\n'.

Strings aren't acceptable stdin values, so that wouldn't work.

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


Re: how to pass "echo t | " input to subprocess.check_output() method

2012-11-26 Thread dachakku
On Monday, 26 November 2012 16:22:42 UTC+5:30, Duncan Booth  wrote:
> [email protected] wrote:
> 
> 
> 
> > Hi all,
> 
> > 
> 
> > I want to list the repositories in svn using python. For this i have
> 
> > used below command, " res = subprocess.check_output(["svn.exe",
> 
> > "list", "Https://127.0.0.1:443/svn/Repos"], stderr=subprocess.STDOUT)
> 
> > " 
> 
> > 
> 
> > but it throws an exception, since it requires an user input to
> 
> > validate certificate, " (R)eject, accept (t)emporarily or accept
> 
> > (p)ermanently? " 
> 
> > 
> 
> > from Command prompt im able to pass the input while calling the
> 
> > process, and im able to get the output 
> 
> > 
> 
> > "echo t | svn list Https://127.0.0.1:443/svn/Repos"
> 
> > 
> 
> > But i dont know how to pass the "echo t | " in subprocess.check_output
> 
> > while calling a process. Is there a way to do this?
> 
> > Please help.
> 
> > 
> 
> 
> 
> Run svn once manually as the same user that is running your script then 
> 
> when you get the prompt verify that it is indeed the certificate and 
> 
> accept it permanently. That will allow your script to work proviuded the 
> 
> certificate doesn't change.
> 
> 
> 
> Also, change the command you run to include the --non-interactive 
> 
> command line option so that if the certificate ever does change in the 
> 
> future the command will fail rather than prompting.
> 
> 
> 
> Alternatively use --non-interactive --trust-server-cert to just accept 
> 
> any old server regardless what certificate it uses, but be aware that 
> 
> this impacts security.
> 
> 
> 
> -- 
> 
> Duncan Booth http://kupuguy.blogspot.com

Hi Duncan,

I tried using --non-interactive --trust-server-cert, but the call fails with 
error message,
svn: E175002: OPTIONS of 'https://127.0.0.1/svn/Repos': Server certificate 
verification failed: certificate issued for a different hostname, issuer is not 
trusted (https://127.0.0.1)

that's why I want to pass an input to accept the certificate (t)emporarily or 
(p)ermanently.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to pass "echo t | " input to subprocess.check_output() method

2012-11-26 Thread dachakku
On Monday, 26 November 2012 16:32:22 UTC+5:30, Kushal Kumaran  wrote:
> [email protected] writes:
> 
> 
> 
> > Hi all,
> 
> >
> 
> > I want to list the repositories in svn using python. For this i have used 
> > below command,
> 
> > " res = subprocess.check_output(["svn.exe", "list", 
> > "Https://127.0.0.1:443/svn/Repos"], stderr=subprocess.STDOUT) "
> 
> >
> 
> > but it throws an exception, since it requires an user input to validate 
> > certificate,
> 
> > " (R)eject, accept (t)emporarily or accept (p)ermanently? "
> 
> >
> 
> > from Command prompt im able to pass the input while calling the process, 
> > and im able to get the output
> 
> >
> 
> > "echo t | svn list Https://127.0.0.1:443/svn/Repos"
> 
> >
> 
> > But i dont know how to pass the "echo t | " in subprocess.check_output 
> > while calling a process.
> 
> > Is there a way to do this?
> 
> > Please help.
> 
> 
> 
> 
> 
> You could pass in a stdin argument to subprocess.check_output with a
> 
> value of 't\n'.
> 
> 
> 
> However, you might want to use something like http://pysvn.tigris.org/,
> 
> which is a python library for accessing subversion repositories.
> 
> 
> 
> -- 
> 
> regards,
> 
> kushal

Hi Kushal,

I tried passing the value 't\n' to check_output. But I think we cannot pass a 
string to stdin.

When I tried the below command,
subprocess.check_output([svn, "list", repos_Url], stdin='t\n', 
stderr=subprocess.STDOUT)

I got the below error message,
  File "C:\Python27\lib\subprocess.py", line 786, in _get_handles
p2cread = msvcrt.get_osfhandle(stdin.fileno())
AttributeError: 'str' object has no attribute 'fileno'

could you tell me how to pass the value to stdin..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to pass "echo t | " input to subprocess.check_output() method

2012-11-26 Thread Duncan Booth
[email protected] wrote:

> Hi Duncan,
> 
> I tried using --non-interactive --trust-server-cert, but the call
> fails with error message, svn: E175002: OPTIONS of
> 'https://127.0.0.1/svn/Repos': Server certificate verification failed:
> certificate issued for a different hostname, issuer is not trusted
> (https://127.0.0.1) 
> 
> that's why I want to pass an input to accept the certificate
> (t)emporarily or (p)ermanently. 
> 

I think you probably need to configure your web server so the certificate 
is valid for whichever hostname you use (if the svn server is also used by 
other machines then connect to it using the external hostname rather than 
localhost).

Or just use http:// configured to allow access through localhost only.

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Migrate from Access 2010 / VBA

2012-11-26 Thread kagard
On Nov 25, 3:48 pm, Wolfgang Keller  wrote:
> > I am the lone developer of db apps at a company of 350+ employees.
> > Everything is done in MS Access 2010 and VBA. I'm frustrated with the
> > limitations of this platform and have been considering switching to
> > Python.
>
> > I've been experimenting with the language for a year or so,
> > and feel comfortable with the basics.
>
> > I am concerned that I'll have a hard time replacing the access form
> > and report designers. I've worked a little with TKinter, but it's a
> > far cry from the GUI designer in Access.
>
> The list of Python frameworks for rapid development of desktop
> (i.e. non-Web) database applications currently contains:
>
> using PyQt (& Sqlalchemy):
> Pypapi:www.pypapi.org
> Camelot:www.python-camelot.com
> Qtalchemy:www.qtalchemy.org
>
> using PyGTK:
> Sqlkit: sqlkit.argolinux.org (also uses Sqlalchemy)
> Kiwi:www.async.com.br/projects/kiwi
>
> using wxPython:
> Dabo:www.dabodev.com
> Defis: sourceforge.net/projects/defis (Russian only)
> GNUe:www.gnuenterprise.org
>
> Pypapi, Camelot, Sqlkit and Dabo seem to be the most active and best
> documented/supported ones.
>
> > Finding a professional grade report designer looks like an even
> > bigger challenge.
>
> LibreOffice is imho quite useful for database reporting. It comes with a
> native (SDBC) driver for PostgreSQL and allows Python scripting.
> LibreOffice Base can even be useful for CRUD GUIs.
>
> > I don't need to port any applications, but I will need to use the
> > data (mdb/accede format),
>
> Don't. Put your data into an *actually* transaction-safe RDBMS (which
> "Jet" is *not*), such as e.g. PostgreSQL.
>
> > design a variety of reports with multi-level groupings, and deliver
> > them to many individual recipients via email.
>
> Sincerely,
>
> Wolfgang
>
>

Thanks to everyone who replied.

The reporting question is the one that gives me the greatest concern
when I think about switching to Python. I haven't seen a simple,
powerful report writer like Access has, or Crystal Reports, in Python.
Is generating XML / HTML a workable alternative? (In most cases, end
users don't need to design reports.)

Thanks again,

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


Re: how to pass "echo t | " input to subprocess.check_output() method

2012-11-26 Thread Kushal Kumaran
[email protected] writes:

> On Monday, 26 November 2012 16:32:22 UTC+5:30, Kushal Kumaran  wrote:
>> [email protected] writes:
>> 
>> 
>> 
>> > Hi all,
>> 
>> >
>> 
>> > I want to list the repositories in svn using python. For this i have used 
>> > below command,
>> 
>> > " res = subprocess.check_output(["svn.exe", "list", 
>> > "Https://127.0.0.1:443/svn/Repos"], stderr=subprocess.STDOUT) "
>> 
>> >
>> 
>> > but it throws an exception, since it requires an user input to validate 
>> > certificate,
>> 
>> > " (R)eject, accept (t)emporarily or accept (p)ermanently? "
>> 
>> >
>> 
>> > from Command prompt im able to pass the input while calling the process, 
>> > and im able to get the output
>> 
>> >
>> 
>> > "echo t | svn list Https://127.0.0.1:443/svn/Repos"
>> 
>> >
>> 
>> > But i dont know how to pass the "echo t | " in subprocess.check_output 
>> > while calling a process.
>> 
>> > Is there a way to do this?
>> 
>> > Please help.
>> 
>> 
>> 
>> 
>> 
>> You could pass in a stdin argument to subprocess.check_output with a
>> 
>> value of 't\n'.
>> 
>> 
>> 
>> However, you might want to use something like http://pysvn.tigris.org/,
>> 
>> which is a python library for accessing subversion repositories.
>> 
>> 
>> 
>
> Hi Kushal,
>
> I tried passing the value 't\n' to check_output. But I think we cannot pass a 
> string to stdin.
>
> When I tried the below command,
> subprocess.check_output([svn, "list", repos_Url], stdin='t\n', 
> stderr=subprocess.STDOUT)
>
> I got the below error message,
>   File "C:\Python27\lib\subprocess.py", line 786, in _get_handles
> p2cread = msvcrt.get_osfhandle(stdin.fileno())
> AttributeError: 'str' object has no attribute 'fileno'
>
> could you tell me how to pass the value to stdin..

Follow Chris Rebert's suggestion to use subprocess.Popen and the
communicate method of the Popen object.

Have you taken a look at pysvn?

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


Regular expression for different date formats in Python

2012-11-26 Thread undesputed . hackerz
Hello Developers,

I am a beginner in python and need help with writing a regular expression for 
date and time to be fetched from some html documents. In the following code I 
am walking through the html files in a folder called event and printing the 
headings with h1 tag using beautifulsoup. These html pages also contains 
different formats of date and time. I want to fetch and display this 
information as well. Different formats of date in these html documents are:

21 - 27 Nov 2012
1 Dec 2012
30 Nov - 2 Dec 2012
26 Nov 2012

Can someone help me out with fetching these formats from these html documents ?
Here is my code for walking through the files and fetching h1 from those html 
files:


Code:

 
import re
import os
from bs4 import BeautifulSoup

for subdir, dirs, files in os.walk("/home/himanshu/event/"):
for fle in files:
path = os.path.join(subdir, fle)
soup = BeautifulSoup(open(path))

print (soup.h1.string)
   
#Date and Time detection

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


Re: how to pass "echo t | " input to subprocess.check_output() method

2012-11-26 Thread Miki Tebeka
> But i dont know how to pass the "echo t | " in subprocess.check_output while 
> calling a process.
You need to create two subprocess and connect the stdout of the first to the 
stdin of the 2'nd.

See http://pythonwise.blogspot.com/2008/08/pipe.html for a possible solution.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Migrate from Access 2010 / VBA

2012-11-26 Thread Michael Torrie
On 11/22/2012 08:19 PM, kgard wrote:
> I am the lone developer of db apps at a company of 350+ employees.
> Everything is done in MS Access 2010 and VBA. I'm frustrated with the
> limitations of this platform and have been considering switching to
> Python. I've been experimenting with the language for a year or so,
> and feel comfortable with the basics.

Python is just a language, just like VBA itself is just a language.  You
can't just replace an MS Access VBA app with one in Python.  You have to
replace your *tools* with open source alternatives, that hopefully
python can glue together.  Wolfgang provided a nice list of such tools.

One program that claims to be working towards Access replacement is
Kexi.  It's not written in Python, but I think it does use Python as a
scripting language, just as Access uses VBA.  I doubt it's anywhere near
Access yet, but it's worth a look:

http://kexi-project.org/about.html


> 
> Has anyone here made this transition successfully? If so, could you
> pass along your suggestions about how to do this as quickly and
> painlessly as possible?

It will not be painless at all.  There is no "transition" path, really.
 That's partly the result of Microsoft product lock-in, partly because
you want to replace a complete system that happens to be glued together
with, simply, "Python."

I think Python could be a great fit if you could find the right tools to
go with it, but it's not going to be easy at all.  Complete MS Access
replacements is one of the may extremely weak spots in the open source
world.  Partly because web-based apps often work better than a desktop
DB solution, and you might want to go there too, perhaps using a python
web development toolkit like django.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular expression for different date formats in Python

2012-11-26 Thread Michael Torrie
On 11/26/2012 06:15 AM, [email protected] wrote:
> I am a beginner in python and need help with writing a regular
> expression for date and time to be fetched from some html documents.

Would the "parser" module from the third-party dateutil module work for you?

http://pypi.python.org/pypi/python-dateutil
http://labix.org/python-dateutil#head-c0e81a473b647dfa787dc11e8c69557ec2c3ecd2

I don't believe the library is updated for Python 3 yet, sadly.  But I
bet it could be ported fairly easily.  I think it's pure python.


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


Re: How to pass class instance to a method?

2012-11-26 Thread Nobody
On Sun, 25 Nov 2012 04:11:29 -0800, ALeX inSide wrote:

> How to "statically type" an instance of class that I pass to a method of
> other instance?

Python isn't statically typed. You can explicitly check for a specific
type with e.g.:

if not isinstance(arg, SomeType):
raise TypeError('expected SomeType but got %s' % type(arg))

But this defeats duck typing. If you do this a lot, you're using the wrong
language.

> I suppose there shall be some kind of method decorator to treat an
> argument as an instance of class?
> 
> Generally it is needed so IDE (PyCharm) can auto-complete instance's
> methods and properties.

You have it backwards.

In a dynamically-typed language such as Python, the set of acceptable
types for an argument is determined by the operations which the function
performs on it. This is in direct contrast to a statically-typed language,
where the set of acceptable operations on an argument is determined by the
type of the argument.

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


RE: Getting a seeded value from a list

2012-11-26 Thread Prasad, Ramit
Chris Angelico wrote:
> 
> On Sat, Nov 24, 2012 at 3:27 AM, Prasad, Ramit
>  wrote:
> > Steven D'Aprano wrote:
> >>
> >> On Wed, 21 Nov 2012 14:41:24 +1100, Chris Angelico wrote:
> >>
> >> > However, this still means that the player will see the exact same level
> >> > regenerated every time, absolutely fresh. As previously stated in this
> >> > thread, that's not usually a good thing for encounters, treasure, etc.
> >> > Once some nasty critter has been killed, he should STAY killed! :)
> >>
> >> Why? That isn't true in real life, why should it be true for games?
> >>
> >
> > It is not true in all games. I have seen games where treasures
> > regenerate in the same location except for key items. Same goes
> > for enemies (where only "bosses" do not regenerate). It really
> > just depends on the type of game you are playing--designing
> > in this case.
> 
> Perhaps they regenerate, but do they regenerate from the exact same
> random seed? For instance, in Murkon's Refuge, the maps are
> handcrafted and thus constant every time you enter a particular level
> - but go downstairs and upstairs, and the monsters and treasure
> regenerate, different from last time.
> 
> Of course, if the idea is that you're rewinding time, then it makes
> good sense for you to see the exact same pattern of enemies.
> 

Hmm. I guess most of the games where I remember "regenerating"
enemies are a bit older. Chrono Trigger had enemies that 
would regenerate if you left a map screen and came back, but
then again it seems more likely that the enemies were hard
coded and not "generated" at all. Either that or they [games] are
like Diablo/Castlevania where monsters are constantly "generated".

I still hold the opinion that the seeding behavior depends on the 
game. I wonder what Nethack does?


~Ramit


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


Re: Getting a seeded value from a list

2012-11-26 Thread Chris Angelico
On Tue, Nov 27, 2012 at 7:17 AM, Prasad, Ramit
 wrote:
> Hmm. I guess most of the games where I remember "regenerating"
> enemies are a bit older. Chrono Trigger had enemies that
> would regenerate if you left a map screen and came back, but
> then again it seems more likely that the enemies were hard
> coded and not "generated" at all. Either that or they [games] are
> like Diablo/Castlevania where monsters are constantly "generated".
>
> I still hold the opinion that the seeding behavior depends on the
> game. I wonder what Nethack does?

I don't know what Nethack does, but I know Angband - I used to
maintain my own variant (never got as far as publishing, though).
Levels are generated completely fresh on first entry; if you go down
to level 2, then down to level 3, then up to level 2, it'll be a
*different* level 2. No seeds get saved.

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


Re: How to pass class instance to a method?

2012-11-26 Thread Ian Kelly
On Mon, Nov 26, 2012 at 9:56 AM, Nobody  wrote:
> In a dynamically-typed language such as Python, the set of acceptable
> types for an argument is determined by the operations which the function
> performs on it. This is in direct contrast to a statically-typed language,
> where the set of acceptable operations on an argument is determined by the
> type of the argument.

Not how I would put it.  In a statically typed language, types are
checked at compile-time (which does not necessarily imply that useful
type information can be made available to an IDE), whereas in a
dynamically typed language, some or all type checking is deferred to
run-time.

The description that "the set of acceptable types for an argument is
determined by the operations which the function performs on it" sounds
to me more like type inference, as exemplified by Haskell, which is
nonetheless a statically typed language.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular expression for different date formats in Python

2012-11-26 Thread Miki Tebeka
On Monday, November 26, 2012 8:34:22 AM UTC-8, Michael Torrie wrote:
> http://pypi.python.org/pypi/python-dateutil
> ...
> I don't believe the library is updated for Python 3 yet, sadly.
dateutil supports 3.x since version 2.0.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to pass class instance to a method?

2012-11-26 Thread Dave Angel
On 11/26/2012 03:51 PM, Ian Kelly wrote:
> On Mon, Nov 26, 2012 at 9:56 AM, Nobody  wrote:
>> In a dynamically-typed language such as Python, the set of acceptable
>> types for an argument is determined by the operations which the function
>> performs on it. This is in direct contrast to a statically-typed language,
>> where the set of acceptable operations on an argument is determined by the
>> type of the argument.
> Not how I would put it.  In a statically typed language, types are
> checked at compile-time (which does not necessarily imply that useful
> type information can be made available to an IDE), whereas in a
> dynamically typed language, some or all type checking is deferred to
> run-time.

Not how I would put it.  In a statically typed language, the valid types
are directly implied by the function parameter declarations, while in a
dynamic language, they're defined in the documentation, and only
enforced (if at all) by the body of the function.


-- 

DaveA

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


Re: Compare list entry from csv files

2012-11-26 Thread Dave Angel
On 11/26/2012 04:08 PM, Anatoli Hristov wrote:
> Hello,
>
> I'm trying to complete a namebook CSV file with missing phone numbers
> which are in another CSV file.
> the namebook file is structured:
> First name;Lastname; Address; City; Country; Phone number, where the
> phone number is missing.
>
> The phonebook file is structured as:
> Name; phone, where the name shows first and last name and sometimes
> they are written together like "BillGates" or "Billgatesmicrosoft".
>
> I'm importing the files as lists ex.: phonelist" ["First name", "Last
> name","address","City"."Country","phone"],[etc...]
> in the loop I can compare the entry for ex. "Bill Gates" in the field
> "BillGatesmicrosoft" but I can't index it so I can only take the phone
> number from the file with the phones and insert it to field in the
> Namebook. Can you please give me an advice?
>
> Thanks
>
>
> import csv
>
> origf = open('c:/Working/Test_phonebook.csv', 'rt')
> phonelist = []
>
> try:
> reader = csv.reader(origf, delimiter=';')
> for row in reader:
> phonelist.append(row)
> finally:
> origf.close()
>
> secfile = open('c:/Working/phones.csv', 'rt')
> phones = []
>
> try:
> readersec = csv.reader(secfile, delimiter=';')
> for row in readersec:
> phones.append(row)
> finally:
> secfile.close()

You're trying to merge information from a second file into a first one,
where the shared key is only a little bit similar.  Good luck.

For example., in the first file, it might say  Susan; Gatley  and in the
other file it might say Mom.   Good luck coming up with an algorthm to
match those.

Now if you are assured that the two will be identical except for spaces,
then you could reduce both keys to the same format and then match them. 
Or if you want to say they're within a Soundex definition of each
other.  Or if you want to claim that they'll have the same words in
them, but not necessarily the same order.

But if these files are really as randomly connected as you say, then the
best you can probably do is to write two programs.  First is where you
take the names from each file and produce a 3rd file associating the
ones that are obvious (according to some algorithm), then build a list
of exceptions.  Then allow a human being to edit that file.  Then the
second file uses it to merge the first two files for your final pass.


-- 

DaveA

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


Re: How to pass class instance to a method?

2012-11-26 Thread Steven D'Aprano
On Mon, 26 Nov 2012 16:58:47 -0500, Dave Angel wrote:

> In a statically typed language, the valid types
> are directly implied by the function parameter declarations, while in a
> dynamic language, they're defined in the documentation, and only
> enforced (if at all) by the body of the function.


Well that certainly can't be true, because you can write functions 
without *any* documentation at all, and hence no defined type 
restrictions that could be enforced:

def trivial_example(x):
return x+1

No documentation, and so by your definition above this should be weakly 
typed and operate on any type at all. Since there are no type 
restrictions defined, the body cannot enforce those type restrictions. 
But that's clearly not true.

Please, everybody, before replying to this thread, please read this:

http://cdsmith.wordpress.com/2011/01/09/an-old-article-i-wrote/



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


Re: Compare list entry from csv files

2012-11-26 Thread Anatoli Hristov
I understand, but in my case I have for sure the field "Name" in the
second file that contains at least the first or the last name on it...
So probably it should be possible:)
The Name "Billgatesmicrosoft" contains the word "Gates" so logically I
might find a solution for it.

Thanks

On Mon, Nov 26, 2012 at 11:08 PM, Dave Angel  wrote:
> On 11/26/2012 04:08 PM, Anatoli Hristov wrote:
>> Hello,
>>
>> I'm trying to complete a namebook CSV file with missing phone numbers
>> which are in another CSV file.
>> the namebook file is structured:
>> First name;Lastname; Address; City; Country; Phone number, where the
>> phone number is missing.
>>
>> The phonebook file is structured as:
>> Name; phone, where the name shows first and last name and sometimes
>> they are written together like "BillGates" or "Billgatesmicrosoft".
>>
>> I'm importing the files as lists ex.: phonelist" ["First name", "Last
>> name","address","City"."Country","phone"],[etc...]
>> in the loop I can compare the entry for ex. "Bill Gates" in the field
>> "BillGatesmicrosoft" but I can't index it so I can only take the phone
>> number from the file with the phones and insert it to field in the
>> Namebook. Can you please give me an advice?
>>
>> Thanks
>>
>>
>> import csv
>>
>> origf = open('c:/Working/Test_phonebook.csv', 'rt')
>> phonelist = []
>>
>> try:
>> reader = csv.reader(origf, delimiter=';')
>> for row in reader:
>> phonelist.append(row)
>> finally:
>> origf.close()
>>
>> secfile = open('c:/Working/phones.csv', 'rt')
>> phones = []
>>
>> try:
>> readersec = csv.reader(secfile, delimiter=';')
>> for row in readersec:
>> phones.append(row)
>> finally:
>> secfile.close()
>
> You're trying to merge information from a second file into a first one,
> where the shared key is only a little bit similar.  Good luck.
>
> For example., in the first file, it might say  Susan; Gatley  and in the
> other file it might say Mom.   Good luck coming up with an algorthm to
> match those.
>
> Now if you are assured that the two will be identical except for spaces,
> then you could reduce both keys to the same format and then match them.
> Or if you want to say they're within a Soundex definition of each
> other.  Or if you want to claim that they'll have the same words in
> them, but not necessarily the same order.
>
> But if these files are really as randomly connected as you say, then the
> best you can probably do is to write two programs.  First is where you
> take the names from each file and produce a 3rd file associating the
> ones that are obvious (according to some algorithm), then build a list
> of exceptions.  Then allow a human being to edit that file.  Then the
> second file uses it to merge the first two files for your final pass.
>
>
> --
>
> DaveA
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compare list entry from csv files

2012-11-26 Thread Emile van Sebille

Anatoli Hristov wrote:

I understand, but in my case I have for sure the field "Name" in the
second file that contains at least the first or the last name on it...
So probably it should be possible:)
The Name "Billgatesmicrosoft" contains the word "Gates" so logically I
might find a solution for it.


Take a look at difflib -- I've used it before for this type of 'matching'

Emile

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


Re: How to pass class instance to a method?

2012-11-26 Thread Ian Kelly
On Mon, Nov 26, 2012 at 2:58 PM, Dave Angel  wrote:
> Not how I would put it.  In a statically typed language, the valid types
> are directly implied by the function parameter declarations,

As alluded to in my previous post, not all statically typed languages
require parameter type declarations to perform static checking.

> while in a
> dynamic language, they're defined in the documentation, and only
> enforced (if at all) by the body of the function.

That's not even true for Python.  The following example uses Python 2.x:

>>> class Foo(object):
... def method(self):
... pass
...
>>> Foo.method(4)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unbound method method() must be called with Foo instance as
first argument (got int instance instead)

That's a run-time check, and it's not enforced by the body of the function.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to pass class instance to a method?

2012-11-26 Thread Hans Mulder
On 27/11/12 00:07:10, Ian Kelly wrote:
> On Mon, Nov 26, 2012 at 2:58 PM, Dave Angel  wrote:
>> Not how I would put it.  In a statically typed language, the valid types
>> are directly implied by the function parameter declarations,
> 
> As alluded to in my previous post, not all statically typed languages
> require parameter type declarations to perform static checking.
> 
>> while in a
>> dynamic language, they're defined in the documentation, and only
>> enforced (if at all) by the body of the function.
> 
> That's not even true for Python.  The following example uses Python 2.x:
> 
 class Foo(object):
> ... def method(self):
> ... pass
> ...
 Foo.method(4)
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: unbound method method() must be called with Foo instance as
> first argument (got int instance instead)
> 
> That's a run-time check, and it's not enforced by the body of the function.

As Ian already knows, this problem has been fixed in Python 3.

-- HansM

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


Re: Getting a seeded value from a list

2012-11-26 Thread Hans Mulder
On 26/11/12 21:17:40, Prasad, Ramit wrote:
> Chris Angelico wrote:
>>
>> On Sat, Nov 24, 2012 at 3:27 AM, Prasad, Ramit
>>  wrote:
>>> Steven D'Aprano wrote:

 On Wed, 21 Nov 2012 14:41:24 +1100, Chris Angelico wrote:

> However, this still means that the player will see the exact same level
> regenerated every time, absolutely fresh. As previously stated in this
> thread, that's not usually a good thing for encounters, treasure, etc.
> Once some nasty critter has been killed, he should STAY killed! :)

 Why? That isn't true in real life, why should it be true for games?

>>>
>>> It is not true in all games. I have seen games where treasures
>>> regenerate in the same location except for key items. Same goes
>>> for enemies (where only "bosses" do not regenerate). It really
>>> just depends on the type of game you are playing--designing
>>> in this case.
>>
>> Perhaps they regenerate, but do they regenerate from the exact same
>> random seed? For instance, in Murkon's Refuge, the maps are
>> handcrafted and thus constant every time you enter a particular level
>> - but go downstairs and upstairs, and the monsters and treasure
>> regenerate, different from last time.
>>
>> Of course, if the idea is that you're rewinding time, then it makes
>> good sense for you to see the exact same pattern of enemies.
>>
> 
> Hmm. I guess most of the games where I remember "regenerating"
> enemies are a bit older. Chrono Trigger had enemies that 
> would regenerate if you left a map screen and came back, but
> then again it seems more likely that the enemies were hard
> coded and not "generated" at all. Either that or they [games] are
> like Diablo/Castlevania where monsters are constantly "generated".
> 
> I still hold the opinion that the seeding behavior depends on the 
> game. I wonder what Nethack does?

When you leave a level, Nethack saves it to the hard disk.
When you return, the level is reloaded from disk, so monsters
and objects appear where they were when you left the level.
The map is also saved, so if you had dug an extra corridor
on your first visit, it'll be there when you return.

The random level generation only happens if you go to a level
you haven't visited before in that game (and sometimes not
even then).

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


Re: How to pass class instance to a method?

2012-11-26 Thread Drew
On Sunday, November 25, 2012 7:11:29 AM UTC-5, ALeX inSide wrote:
> How to "statically type" an instance of class that I pass to a method of 
> other instance?
> 
> 
> 
> I suppose there shall be some kind of method decorator to treat an argument 
> as an instance of class?
> 
> 
> 
> Generally it is needed so IDE (PyCharm) can auto-complete instance's methods 
> and properties.
> 
> 
> 
> Pseudo-python-code example:
> 
> 
> 
> i = MyClass()
> 
> 
> 
> xxx(i, 1, 2);
> 
> 
> 
> ...
> 
> def xxx(self, MyClass myclass, number, foobar):
> 
>myclass.classsmethod() #myclass - is an instance of known class

I'm not sure I understand exactly what you sre asking.Python uses "duck 
typing".  As far as Python is concerned, you can pass in any class object and 
so long as it has the needed methods, it'll suffice ("If it walks like a duck 
and it quacks like a duck, then it is a duck.").   The down side to that is 
that if you hand an object as an argument and the method you pass doesn't 
behave like the expected method class would, then bad things may happen at run 
time.  It would be a bit of a hassle to check types to make sure things at 
least smell OK before execution goes possibly awry, but you are certainly free 
to write guard code that makes those sort of checks.

My reply here is a bit different from the other replies I see so far.  I worry 
that may mean I mis-understood your question.Has this been at all helpful 
an answer?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: Managing multiple packages

2012-11-26 Thread Evan Driscoll

On 11/22/2012 06:22 PM, Thomas Bach wrote:

I am using virtual environments and do a

python setup.py develop

on each package. This just creates a symbolic link to the package and
all edits show up immediately.


That's awesome; I didn't know about the 'develop' command. Thanks!

Is that just a setuptools thing, or can you do it with distutils too? I 
didn't see anything too promising so I'm not so hopeful, but I figured 
I'd ask anyway. I'm also pretty confused about the 
distutils/setuptools/distribute/distutils2 landscape and what the 
differences are (at least between the first 3) and what their 
relationships with standard Python are.


(I'd prefer to use distutils because (1) it ships with Python as opposed 
to being something extra to install (2) setuptools annoys me being the 
only think I can remember that, when you tell it to install to a prefix 
that doesn't exist, says "you want me to MAKE DIRECTORIES?! what are 
you, some kind of slave driver?!". Admittedly that second reason is not 
so rational and very occasionally putting up with that in exchange for 
development mode is plenty worth it, but being able to shun setuptools 
would make me feel good. :-))


Evan

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


Python dictionaries are awesome

2012-11-26 Thread Steven D'Aprano
... especially when you consider how some other languages implement them.


http://twistedoakgames.com/blog/?p=925

[quote]
Here’s the hypothetical situation: you’re making a flash game. In that 
game users can create named profiles. You store the profiles, keyed by 
their name, so that you ca- OOPS, you just introduced a bug. What’s the 
problem? The dictionary.
[end quote]




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


Re: How to pass class instance to a method?

2012-11-26 Thread Dave Angel
On 11/26/2012 06:07 PM, Ian Kelly wrote:
> On Mon, Nov 26, 2012 at 2:58 PM, Dave Angel  wrote:
>> Not how I would put it.  In a statically typed language, the valid types
>> are directly implied by the function parameter declarations,
> As alluded to in my previous post, not all statically typed languages
> require parameter type declarations to perform static checking.
>
>> while in a
>> dynamic language, they're defined in the documentation, and only
>> enforced (if at all) by the body of the function.
> That's not even true for Python.  The following example uses Python 2.x:
>
 class Foo(object):
> ... def method(self):
> ... pass
> ...
 Foo.method(4)
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: unbound method method() must be called with Foo instance as
> first argument (got int instance instead)
>
> That's a run-time check, and it's not enforced by the body of the function.

We were talking about function arguments.  I don't know of any place
where they get their types declared.

-- 

DaveA

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


Re: How to pass class instance to a method?

2012-11-26 Thread Dave Angel
On 11/26/2012 05:18 PM, Steven D'Aprano wrote:
> On Mon, 26 Nov 2012 16:58:47 -0500, Dave Angel wrote:
>
>> In a statically typed language, the valid types
>> are directly implied by the function parameter declarations, while in a
>> dynamic language, they're defined in the documentation, and only
>> enforced (if at all) by the body of the function.
>
> Well that certainly can't be true, because you can write functions 
> without *any* documentation at all, and hence no defined type 
> restrictions that could be enforced:

That's backwards.  Any body should be a bug in that case.  It doesn't
matter what you pass to a function that is unspecified, it's behavior is
undefined.  Calling it is inherently illegal.

>
> def trivial_example(x):
> return x+1
>
> No documentation, and so by your definition above this should be weakly 
> typed and operate on any type at all. Since there are no type 
> restrictions defined, the body cannot enforce those type restrictions. 
> But that's clearly not true.
>
> Please, everybody, before replying to this thread, please read this:
>
> http://cdsmith.wordpress.com/2011/01/09/an-old-article-i-wrote/

I read part of it, and it's more than I care to read tonight.  It seems
to be written by an anonymous person.  By jumping around in his blog, I
see a lot of interesting articles, but i haven't yet figured out who he
is.  Does he have a name?  A degree, a job in computers, a reputation?





-- 

DaveA

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


Re: Compare list entry from csv files

2012-11-26 Thread Dave Angel
On 11/26/2012 05:27 PM, Anatoli Hristov wrote:
> I understand, but in my case I have for sure the field "Name" in the
> second file that contains at least the first or the last name on it...
> So probably it should be possible:)
> The Name "Billgatesmicrosoft" contains the word "Gates" so logically I
> might find a solution for it.
> 

(Please don't top-post.  Or if you must, then delete everything after
your post, as I'm doing here.  Otherwise you end up with insanities like
new stuff, quote-4, quote-1, quote-3, quote-2.  In this case, long
tradition on this forum and many like it work well, even if Microsoft
mail programs and some others decide to put the cursor at the wrong end
of the existing text.  In most programs, it's configurable.)

If you can come up with an algorithm for comparing first+last in one
file to name in the other, then the problem can be solved.  But you
can't do it by hand-waving, you have to actually figure out a mechanism.
 Then we can help you code such a thing.  And I can just about guarantee
that if these fields are created independently by human beings, that
there will be exceptions that have to fixed by human beings.


-- 

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


Re: How to pass class instance to a method?

2012-11-26 Thread Steven D'Aprano
On Mon, 26 Nov 2012 22:14:59 -0500, Dave Angel wrote:

> On 11/26/2012 05:18 PM, Steven D'Aprano wrote:
>> On Mon, 26 Nov 2012 16:58:47 -0500, Dave Angel wrote:
>>
>>> In a statically typed language, the valid types are directly implied
>>> by the function parameter declarations, while in a dynamic language,
>>> they're defined in the documentation, and only enforced (if at all) by
>>> the body of the function.
>>
>> Well that certainly can't be true, because you can write functions
>> without *any* documentation at all, and hence no defined type
>> restrictions that could be enforced:
> 
> That's backwards.  Any body should be a bug in that case.  It doesn't
> matter what you pass to a function that is unspecified, it's behavior is
> undefined.  Calling it is inherently illegal.

Have you ever programmed before? *wink*

Seriously, as much as we would like to have full documentation of every 
piece of code before it is written, such a thing is awfully heavyweight 
for all but the biggest projects.

In practice, many functions never get documented at all, or only 
partially documented. Whether this is a good thing or not, it is a fact, 
and no mainstream language *requires* you to write documentation, nor is 
the documentation is used to determine runtime behaviour. If it did, it 
would be code, not documentation.

In lightweight or agile software development methodologies ("Bingo!") or 
exploratory development, you often write the code before you know what it 
does, or even what you want it to do. E.g. I'll sometimes have a vague 
idea of what I want a function or method to do, and go through three or 
four iterations of writing code before it is stable enough to begin 
documenting it.

Given the practical reality that documentation is often neglected, there 
is a school of thought that says that *code* is the One True source of 
information about what the code does, that documentation is at best a 
hint or at worst completely redundant. While I think that's a bit 
extreme, I can see the point. If function f() puts the cat on the mat, 
but is documented as putting the hat on the cat, how do you know whether 
the documentation is wrong or the code?


[...]
>> Please, everybody, before replying to this thread, please read this:
>>
>> http://cdsmith.wordpress.com/2011/01/09/an-old-article-i-wrote/
> 
> I read part of it, and it's more than I care to read tonight.  It seems
> to be written by an anonymous person.  By jumping around in his blog, I
> see a lot of interesting articles, but i haven't yet figured out who he
> is.  Does he have a name?  A degree, a job in computers, a reputation?

Does it matter? Surely what he says should stand or fail on its own 
merits, not by who he is.

He has a name, although it seems to be hard to find on his current blog: 
Chris Smith. As for the rest, I don't know.



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


Re: How to pass class instance to a method?

2012-11-26 Thread Roy Smith
Steven D'Aprano  wrote:
> Given the practical reality that documentation is often neglected, there 
> is a school of thought that says that *code* is the One True source of 
> information about what the code does, that documentation is at best a 
> hint or at worst completely redundant.

Yes, there is such a school.  Those people are full of bovine excrement.

> If function f() puts the cat on the mat, but is documented as putting 
> the hat on the cat, how do you know whether the documentation is 
> wrong or the code?

Documentation should describe intent and interface.  Yes, the code says 
what the code does.  But, the interface description says what it's 
supposed to do.  Can the docs be wrong?  Of course they can.  Usually 
because somebody changed the code and didn't bother to change the docs.

My take on people who never document anything is that they're just plain 
lazy.

Go ahead, ask me how I really feel about the topic :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to pass class instance to a method?

2012-11-26 Thread Dave Angel
On 11/26/2012 11:10 PM, Steven D'Aprano wrote:
> On Mon, 26 Nov 2012 22:14:59 -0500, Dave Angel wrote:
>
>> On 11/26/2012 05:18 PM, Steven D'Aprano wrote:
>>> On Mon, 26 Nov 2012 16:58:47 -0500, Dave Angel wrote:
>>>
 In a statically typed language, the valid types are directly implied
 by the function parameter declarations, while in a dynamic language,
 they're defined in the documentation, and only enforced (if at all) by
 the body of the function.
>>> Well that certainly can't be true, because you can write functions
>>> without *any* documentation at all, and hence no defined type
>>> restrictions that could be enforced:
>> That's backwards.  Any body should be a bug in that case.  It doesn't
>> matter what you pass to a function that is unspecified, it's behavior is
>> undefined.  Calling it is inherently illegal.
> Have you ever programmed before? *wink*

I think you know the answer to that.  But for anyone else, I've been in
various aspects of software development for 42 years, longer if you
count various projects which were not turned into products.  And the
approximately dozen patents were nearly all for things which shipped,
not just theoretical concepts.

>
> Seriously, as much as we would like to have full documentation of every 
> piece of code before it is written, such a thing is awfully heavyweight 
> for all but the biggest projects.
>
> In practice, many functions never get documented at all, or only 
> partially documented. Whether this is a good thing or not, it is a fact, 
> and no mainstream language *requires* you to write documentation, nor is 
> the documentation is used to determine runtime behaviour. If it did, it 
> would be code, not documentation.
>
> In lightweight or agile software development methodologies ("Bingo!") or 
> exploratory development, you often write the code before you know what it 
> does, or even what you want it to do. E.g. I'll sometimes have a vague 
> idea of what I want a function or method to do, and go through three or 
> four iterations of writing code before it is stable enough to begin 
> documenting it.
>
> Given the practical reality that documentation is often neglected, there 
> is a school of thought that says that *code* is the One True source of 
> information about what the code does, that documentation is at best a 
> hint or at worst completely redundant. While I think that's a bit 
> extreme, I can see the point. If function f() puts the cat on the mat, 
> but is documented as putting the hat on the cat, how do you know whether 
> the documentation is wrong or the code?
Yes, and yes.  They're both wrong.  Function f() is just broken. 
Especially it's name.

I know all that, and wasn't trying to pretend that documentation is
always or even frequently, adequate.  But the bulk of this part of the
thread has been dealing with a function call, contrasting static typing,
where some work is done by the compiler, and dynamic typing, where
supposedly something is done by the interpreter.  And I claim that the
interpreter cannot in general do anything at the call target, except
count the number of the arguments (maybe) and check the keywords.  So
the only thing that can be done there is manual - check the docs.  If
they're not there, there's just no comparison with the static case.  And
for a non-trivial function, or generally one which calls non-trivial
functions, exhaustively analyzing the code of the function, and of the
function it calls, is impractical.  So people just call the function and
hope.

Static typing isn't nearly enough, and therefore the feeling of security
it gives many is dangerously misleading.  There have been (and
presumably still are) languages which allow subsets of types to be
explicitly declared, for example the type is int, but the restriction is
nonnegative int (eg. square root).  Or the type is int, but the
restriction is between 4 and 7.  Or the parameters have an
interrelationship, or a dependency on the system state: e.g. if the
first parameter is a string, then the second one must be one of 8
specific strings.


>
> [...]
>>> Please, everybody, before replying to this thread, please read this:
>>>
>>> http://cdsmith.wordpress.com/2011/01/09/an-old-article-i-wrote/
>> I read part of it, and it's more than I care to read tonight.  It seems
>> to be written by an anonymous person.  By jumping around in his blog, I
>> see a lot of interesting articles, but i haven't yet figured out who he
>> is.  Does he have a name?  A degree, a job in computers, a reputation?
> Does it matter? Surely what he says should stand or fail on its own 
> merits, not by who he is.

Yes, but since it's very hard slugging at first, I was curious if it
would be worth it.  He uses a number of terms in ways foreign to my
background, and while I admire Humpty-Dumpty-ism, it certainly slows
down comprehension.  Anyway, he's apparently got a reputation with you,
and that alone should make it worth the trouble.  Just not tonight.

> 

Re: Python dictionaries are awesome

2012-11-26 Thread Dave Angel
On 11/26/2012 09:32 PM, Steven D'Aprano wrote:
> ... especially when you consider how some other languages implement them.
>
>
> http://twistedoakgames.com/blog/?p=925
>
> [quote]
> Here’s the hypothetical situation: you’re making a flash game. In that 
> game users can create named profiles. You store the profiles, keyed by 
> their name, so that you ca- OOPS, you just introduced a bug. What’s the 
> problem? The dictionary.
> [end quote]
>
>

(facetious)
Whenever someone tries to create a username that happens to conflict
with a pre-existing attribute, just tell them that username is already
taken.  Just watch out when your user HasOwnProperty tries to delete his
account.
(/facetious)

Namespaces are great, we should have lots of them.  But be very careful
about reusing one without checking to see if it's already inhabited.

When a language design does this sort of thing, it tends to make us
skittish about continuing use of said language.

-- 

DaveA

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