Re: Morelia for BDD in Python

2011-07-09 Thread Stefan Behnel

Phlip, 10.07.2011 07:10:

On Jul 9, 8:38 pm, Ben Finney  wrote:

Phlip  writes:

On Jul 9, 7:39 pm, mark curphey  wrote:



Thanks. FWIW I played with a bunch (Freshen, Morelia, Lettuce)



Morelia is "undermaintained" because it's finished. It attaches to any
pre-existing TestCase-style test runner, hence there's nothing to
maintain!


It looks good! But it's not yet in Debian :-(


Tx - I never added anything to a distro before! But..!

'sudo pip install morelia' just worked for me, on Ubuntu. I don't
think a python-morelia aptitude package would add any value.


There's no "pip uninstall", though.

Stefan

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


Re: String concatenation vs. string formatting

2011-07-09 Thread Andrew Berg
-BEGIN PGP SIGNED MESSAGE-
Hash: RIPEMD160

How should I go about switching from concatenation to string formatting
for this?

avs.write(demux_filter + field_filter + fpsin_filter + i2pfilter +
dn_filter + fpsout_filter + trim_filter + info_filter)

I can think of a few ways, but none of them are pretty.

- -- 
CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0
PGP/GPG Public Key ID: 0xF88E034060A78FCB
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAwAGBQJOGUp7AAoJEPiOA0Bgp4/L3koIAMntYStREGjww6yKGKE/xI0W
ecAg2BHdqBxTFsPT6NMrSRyrNbdfnWRQcRi/0Z+Hhbwqp4qsz5hDFgsoVPkT5gyj
6q0TeJqaSE+Uoj5g2BofqVlWydyQ7fW34KaANbj7V71/UqXXgb+fl8TYvVRJbg0A
KlfytOO0HBrDW8f6dzGZuxLxCb3EONt7buIUV3Pa7b9jQZNTTiOKktLtWAteMMiC
CHivQhqzB8/cNVddpyk5LaMEDzJ9yz8a83fjuK8F5E/wrYk22t6Fad6PKgDEivaj
hAiE5HMeUw+gQ7xFhJGkK31/KyHRqAaFR4mUh16u9GHMTaGPobk8NEj81LwCbvg=
=g3kL
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String concatenation vs. string formatting

2011-07-09 Thread Andrew Berg
-BEGIN PGP SIGNED MESSAGE-
Hash: RIPEMD160

On 2011.07.10 12:55 AM, Dennis Lee Bieber wrote:
> Maybe it's been removed, but from the help file for my installation
help(file) returns a NameError in 3.2. It shows up as a built-in
function in the 2.7 docs, but not in the py3k docs. It's not mentioned
in any of the "what's new" sections of the docs for any version since
2.2, though.

- -- 
CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0
PGP/GPG Public Key ID: 0xF88E034060A78FCB
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAwAGBQJOGUOYAAoJEPiOA0Bgp4/LS+oH/iirBETfcYYYtr3kaR/0JPMT
iz4eEwCvReiXGdNE/AsIfB7aUCwlNPP+KBr3fq9e8N+a8OvM8pwGcDbYGJd92zxI
atujVPZqYFWt8EfJEJBoqEmuofbnNlVdqzDaYFmrxQfXFxv2gl7wyEY1QH/udLt4
oL+zzNLgxMYGWp85Xrf/MLqqWOkp1Yk56m90oyU+DhzGnP15r/1jiQQ7/U6dydkc
ZgJ09W7mZ7svOq4+pVG+rOk3UFQKEe3E1XO5nEreRp9KGwWp+qYE9XUCzxv40/Y2
WKUN3G5MJ1GvkdfeeNcf4a08mTNe1wtVJQdtUyBQzZ23eTxN0PqNZXwSkg2OIIg=
=9nbT
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Morelia for BDD in Python

2011-07-09 Thread Ben Finney
Phlip  writes:

> 'sudo pip install morelia' just worked for me, on Ubuntu.

The problem with ‘pip’ is that it's a parallel package installation that
ignores the available package management system on the OS.

That's not a fault of ‘pip’ or Setuptools or PyPI or the rest; but it's
a higher maintenance burden for the user than getting a package from the
same system that provides all the rest of their packages on the
computer.

On operating systems with poor package management, Python's distutils
and PyPI etc. are better than nothing. But on an OS like Debian with
good package management already for free software, it's a step backward
to rely on external dependencies from a disjoint package system.

> I don't think a python-morelia aptitude package would add any value.

I think it would add great value, since without it I'm unlikely to
bother using Morelia in any project. The maintenance burden is too high
to keep adding dependencies that come from a distinct dependency system
outside my OS.

-- 
 \“Consider the daffodil. And while you're doing that, I'll be |
  `\  over here, looking through your stuff.” —Jack Handey |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Morelia for BDD in Python (was: CI and BDD with Python)

2011-07-09 Thread Phlip
> --
>  \        “That's the essence of science: Ask an impertinent question, |
>   `\            and you're on the way to the pertinent answer.” —Jacob |
> _o__)                            Boronowski, _The Ascent of Man_, 1976 |
> Ben Finney

That nose keeps reminding me of the start of one of the Pirates of the
Caribbean movies...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Morelia for BDD in Python (was: CI and BDD with Python)

2011-07-09 Thread Phlip
On Jul 9, 8:38 pm, Ben Finney  wrote:
> Phlip  writes:
> > On Jul 9, 7:39 pm, mark curphey  wrote:
>
> > > Thanks. FWIW I played with a bunch (Freshen, Morelia, Lettuce)
>
> > Morelia is "undermaintained" because it's finished. It attaches to any
> > pre-existing TestCase-style test runner, hence there's nothing to
> > maintain!
>
> It looks good! But it's not yet in Debian :-(

Tx - I never added anything to a distro before! But..!

'sudo pip install morelia' just worked for me, on Ubuntu. I don't
think a python-morelia aptitude package would add any value. Such test
rigs shall never have any embedded C code or other shenanigans.

If I needed to think of a feature to add, it would be P notation
in the regular expressions, to then enforce the names of the matching
arguments. But this is fluff; real programmers can do without it. If I
worked closer to the center of the BDD thought leadership I'd know
what else to add...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String concatenation vs. string formatting

2011-07-09 Thread Andrew Berg
-BEGIN PGP SIGNED MESSAGE-
Hash: RIPEMD160

On 2011.07.09 11:04 PM, Andrew Berg wrote:
> 
> Is barf built-in as well?
> 
That came off more hostile than I wanted, so I'll rephrase it:

I doubt it has anything to do with built-ins, since it fails on a
variable name that obviously does not reference a built-in.
- -- 
CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0
PGP/GPG Public Key ID: 0xF88E034060A78FCB
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAwAGBQJOGTBOAAoJEPiOA0Bgp4/LbkcH/2GdaIXnTRbfs4/aZInlf2sJ
CK3rxb5OVY2Xz8rWVyHSd5tLRcCV8+R8+Mvv0/Ho6ckZjVi3xi6LHvoVFnhUP5Iv
wayXHIJEjrN2oU5DJCSBbKGdtxjAMg48UUe6c2d4UUnV05bFX31SnHfI6Jq13uhs
RpLSS3vELl/XDrcNGzMpOP1z8NYt7KpwHWoAWwN2wSZ8SQnyJFcFqbapWxA165Lp
btDz1ufJ0nO/td+28y8FELoAkDtwrSBHCPqokbURA6zXy7KmVeGH9nVRO08Lz5ez
qRII3lTBzeI9E2X/CUMOwrfLiWYDYYvh6VWBJZifBe5B4PQe/ksVe586A1LHetM=
=5Xeo
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String concatenation vs. string formatting

2011-07-09 Thread Andrew Berg
-BEGIN PGP SIGNED MESSAGE-
Hash: RIPEMD160

On 2011.07.09 09:54 PM, Dennis Lee Bieber wrote:
> "file" is a built-in (related to "open").
Also:
> Traceback (most recent call last): File
> "C:\Users\Bahamut\workspace\Disillusion\disillusion.py", line 178, in
>  save_preset() File
> "C:\Users\Bahamut\workspace\Disillusion\disillusion.py", line 169, in
> save_preset logger.info('Binary preset file {barf} successfully
> stored.', barf=queue[0].preset_file) File
> "C:\Python32\lib\logging\__init__.py", line 1229, in info 
> self._log(INFO, msg, args, **kwargs) TypeError: _log() got an
> unexpected keyword argument 'barf'

Is barf built-in as well?

- -- 
CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0
PGP/GPG Public Key ID: 0xF88E034060A78FCB
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAwAGBQJOGSTlAAoJEPiOA0Bgp4/LfbgH/0yo5BegsXcqu3ZTyn3Src+k
RJBwnIZNBOpaUS2oogiD8eILF5JonCvztKn6rPuB8uhMWzOKl+jTwf5Y4y2Y+kJ7
37v3d41Bar1vAPQ42vKSqYkQ+p1ZHG5VMjkTFH76g8Q1a82oUMTNucqIXu84an2K
8sZA223ZZqzKa7VTzxr59TNX+4EnUIoBBZGH8LATAp9ILa0cNj/TJm7UOQmRAWzC
He2zkhrAERbKm9w0BR/Y9JidJ5BlgdkqY7/yNbaYucAm8aI5xgHYvqt7SrSnSFu8
3X7HBxWz2Kinanvlpb5zZEnBmESrR+PujZqS89Bo/uznipkmgZNdXYPyhO/Rbzk=
=QkWp
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Morelia for BDD in Python (was: CI and BDD with Python)

2011-07-09 Thread Ben Finney
Phlip  writes:

> On Jul 9, 7:39 pm, mark curphey  wrote:
>
> > Thanks. FWIW I played with a bunch (Freshen, Morelia, Lettuce)
>
> Morelia is "undermaintained" because it's finished. It attaches to any
> pre-existing TestCase-style test runner, hence there's nothing to
> maintain!

It looks good! But it's not yet in Debian :-(

I've filed bug report #633411 http://bugs.debian.org/633411> to
call for an interested Python programmer to package it for Debian.

-- 
 \“That's the essence of science: Ask an impertinent question, |
  `\and you're on the way to the pertinent answer.” —Jacob |
_o__)Boronowski, _The Ascent of Man_, 1976 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-09 Thread Benjamin Kaplan
On Sat, Jul 9, 2011 at 6:58 PM, Cameron Simpson  wrote:

> On 10Jul2011 03:00, Alexander Kapps  wrote:
> | On 10.07.2011 02:26, John Salerno wrote:
> | >I have a script that does some stuff that I want to run every day for
> | >maybe a week, or a month. So far I've been good about running it every
> | >night, but is there some way (using Python, of course) that I can make
> | >it automatically run at a set time each night?
> |
> | Use your operating system's facilities to run timed jobs.
> |
> | Unix/Linux: Cron jobs
> | Windows: Scheduled Tasks
> | Mac: don't know, but probably Cron too
>
> Yep. Macs are UNIX, BSD derived.
>

Macs have Cron, but Apple's trying to switch away from it. They wrote their
own framework to replace the various process-launching programs called
launchd. It uses a pretty simple XML config file to launch programs either
at startup (replacing init) or on an schedule (replacing cron).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String concatenation vs. string formatting

2011-07-09 Thread Andrew Berg

-BEGIN PGP SIGNED MESSAGE-
Hash: RIPEMD160
 
On 2011.07.09 09:54 PM, Dennis Lee Bieber wrote:
> "file" is a built-in (related to "open").
It is? What is it?
 
>>> type(file)
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'file' is not defined
 
I don't see it in the docs as a built-in function, constant or type.
 
- -- 
CPython 3.2 | Windows NT 6.1.7601.17592 | Thunderbird 5.0
PGP/GPG Public Key ID: 0xF88E034060A78FCB
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
 
iQEcBAEBAwAGBQJOGRszAAoJEPiOA0Bgp4/LAG4H/23ZZZWTEVUWDtFb28JtVKnq
oIQG3aKGxHTUrvUgZqRge6KbpYhDtZFNXcknPmC6rXjVFTBb6Ag5eOCVbEq1Nu5t
Ahonxy9Mr+a5URe+E4oeLvjp0ascLs2NuGxY35QFGm16jRehZ5egCnhvpMOaa1lp
q+VbKWIms2xNw4eyYVfGhfGNvBJ0RXDqHfHKjPwA+oDuUNpFeTRGLrBx9T4qazw5
2+P6fmz6Y8oV3Tu9PQe8L7qksV/NrLe4rG8+sxhlpfzqTGisfKbIsYodo1uUgcdc
723hnkxz1Nh3VmUrB+JTYwYz1mD0ndHMJpkNc4JGBEoxp2lSMk1LE+1+tAlA7b4=
=Gd/f
-END PGP SIGNATURE-

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


Re: CI and BDD with Python

2011-07-09 Thread Phlip
On Jul 9, 7:39 pm, mark curphey  wrote:

> Thanks. FWIW I played with a bunch (Freshen, Morelia, Lettuce)

Morelia is "undermaintained" because it's finished. It attaches to any
pre-existing TestCase-style test runner, hence there's nothing to
maintain!

Packages like Lettuce rebuild the entire TestCase back-end just to
change the front end. That forces its maintainer to then do the Red
Queen thing, and constantly compete with all other test runners just
to stay in place. Props for the effort, though..!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What makes functions special?

2011-07-09 Thread Carl Banks
On Saturday, July 9, 2011 2:28:58 PM UTC-7, Eric Snow wrote:
> A tracker issue [1] recently got me thinking about what makes
> functions special.  The discussion there was regarding the distinction
> between compile time (generation of .pyc files for modules and
> execution of code blocks), [function] definition time, and [function]
> execution time.  Definition time actually happens during compile time,

Nope.  Compile time and definition time are always distinct.


> but it has its own label to mark the contrast with execution time.  So
> why do functions get this special treatment?

They don't really.


[snip]
> Am I wrong about the optimization expectation?

As best as I can tell, you are asking (in a very opaque way) why the Python 
compiler even bothers to create code objects, rather than just to create a 
function object outright, because it doesn't (you think) do that for any other 
kind of object.

Two answers (one general, one specific):

1. You're looking for a pattern where it doesn't make any sense for there to be 
one.  The simple truth of the matter is different syntaxes do different things, 
and there isn't anything more to it.  A lambda expression or def statement does 
one thing; a different syntax, such as an integer constant, does another thing. 
 Neither one is treated "specially"; they're just different.

Consider another example: tuple syntax versus list syntax.  Python will often 
build the tuple at compile time, but it never builds a list at compile time.  
Neither one is "special"; it's just that tuple syntax does one thing, list 
syntax does a different thing.

2. Now that we've dispensed with the idea that Python is treating functions 
specially, let's answer your specific question.  It's not special, but still, 
why the code object?

The reason, simply, is that code objects are used for more than just functions. 
 Code objects are also used in modules, and in eval and exec statements, and 
there's one for each statement at the command line.  Code objects are also used 
directly by the interpreter when executing byte code.  A function object is 
only one of several "interfaces" to a code object.

A minor reason is that code objects are constant (in fact, any object that is 
built at compile time must be a constant).  However, function objects are 
mutable.

I hope that helps clear things up.


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


Re: Newbie help - Programming the Semantic Web with Python

2011-07-09 Thread Andrew Berg
On 2011.07.09 08:32 PM, Bruce Whealton wrote:
> Hello,
> So, I got this book on Programming the Semantic Web about
> the same time I started learning Python.  The code seems to be
> developed for python 2.7 and not 3, I believe.
If you're going to learn Python 3, I suggest learning from a book that
deals with Python 3 (if there's not an updated text for the area you're
dealing with, go with something that teaches the basics). Once you have
the basics down and you know the common differences, then it will be
much easier to learn from a text that's based on Python 2 (you'll
stumble a whole lot less when trying to learn from such texts). You'll
also find some things in Python 3 that have been added to recent
versions of Python 2 that the text may not cover (e.g., the old % string
formatting syntax vs. the new format() string method).
> If I was using python 3, it would require () around the thing that is
> going to be printed, right?
That's not really the right way to think of the print() function. The
print statement has some very arbitrary syntax that could cause
unexpected behavior if simply put in the print() function. The print
function has parameters for optional behavior rather than odd syntax. In
the simplest cases, print and print() are extremely similar, but print()
has a bunch of functionality that is either difficult/annoying to
decipher (for humans, not the interpreter) or simply doesn't exist in print.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CI and BDD with Python

2011-07-09 Thread mark curphey
Thanks. FWIW I played with a bunch (Freshen, Morelia, Lettuce) over the 
last few days and Lettuce appears to be the most "actively" maintained and 
closest to a cucumber-like implementation IMHO. I have decided to adopt it for 
now. I played with a few CI servers but Jenkins (Hudson) is tough to beat IMHO 
but I am sure this is just my personal preference. Anyways thanks for the help. 
Cheers, Mark


On Jul 9, 2011, at 7:05 PM, Phlip wrote:

> On Jul 8, 9:36 pm, Stefan Behnel  wrote:
>> mark curphey, 09.07.2011 01:41:
>> 
>>> And for CI having been using Hudson for a while, any real advantages in a 
>>> Python / Django world for adopting something native like Trac and one of 
>>> the CI plugins like Bitten?
> 
> I'm kind'a partial to Morelia for BDD.
> 
> Don't be fooled by Ruby's RSpec - it's _not_ "BDD". In my exalted
> opinion. "BDD" means "your customer gives you requirements as
> sentences, and you make them into executable statements." That's what
> Cucumber does, which Morelia learns from.
> 
> And BDD and CI are orthogonal. BDD should be part of a complete TDD
> test suite, and your CI tool should run that.
> 
> I still like CruiseControl.rb - even though it has bugs when it sees
> too many git integrations. Hudson had way too many features, and CCrb
> mildly presumes you know how to operate its .cruise/projects folder
> manually!
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Re: What makes functions special?

2011-07-09 Thread Eric Snow
On Sat, Jul 9, 2011 at 7:34 PM, Steven D'Aprano
 wrote:
> Eric Snow wrote:
>
>> Mostly I am just
>> trying to put together more pieces of the Python puzzle.  In this case
>> I was trying to find out if the optimized execution of code objects
>> for functions is a part of the language or just an implementation
>> detail.
>
> You keep using that phrase, "optimized execution of code objects for
> functions", but I have no idea what that means.
>
> The best I can think of is that you are thinking along these lines...
>
> "Suppose we have the source code to a function:
>
> def spam(n):
>    return "SPAM"*n
>
> To execute this, Python currently compiles the function into a code block,
> and then when you call spam(n) elsewhere, Python executes the already
> compiled code block.
>

Yeah, that's pretty much it.  Is that all there is to it?  I was
saying optimized, but I guess there isn't much special optimization
going on then.  Thanks for taking the time.

-eric

> Suppose instead an implementation of Python did not pre-compile the
> function. Each time you called spam(n), the implementation would have to
> locate the source code and interpret it on the spot. Would that be
> allowed?"
>
> If that's your question, then I would call that a Python interpreter using
> c.1960 technology (as opposed to a byte-code compiler, which all the main
> implementations currently are).
>
> If that were the *only* difference, then I see no reason why it wouldn't be
> allowed as an implementation of Python. A horribly slow implementation, but
> still an implementation.
>
> However, I doubt that would be the only difference. Given such a
> simple-minded Python interpreter, it would be hard to provide expected
> Python language features such as compiled code objects, closures, etc. You
> would have to fake them somehow. Provided you could fake them sufficiently
> well, then the lack of a byte-code compiler is just a quality of
> implementation issue.
>
> If that's *not* your question, them I'm stumped.
>
>
>
>
> --
> Steven
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CI and BDD with Python

2011-07-09 Thread Phlip
On Jul 8, 9:36 pm, Stefan Behnel  wrote:
> mark curphey, 09.07.2011 01:41:
>
> > And for CI having been using Hudson for a while, any real advantages in a 
> > Python / Django world for adopting something native like Trac and one of 
> > the CI plugins like Bitten?

I'm kind'a partial to Morelia for BDD.

Don't be fooled by Ruby's RSpec - it's _not_ "BDD". In my exalted
opinion. "BDD" means "your customer gives you requirements as
sentences, and you make them into executable statements." That's what
Cucumber does, which Morelia learns from.

And BDD and CI are orthogonal. BDD should be part of a complete TDD
test suite, and your CI tool should run that.

I still like CruiseControl.rb - even though it has bugs when it sees
too many git integrations. Hudson had way too many features, and CCrb
mildly presumes you know how to operate its .cruise/projects folder
manually!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie help - Programming the Semantic Web with Python

2011-07-09 Thread Chris Angelico
On Sun, Jul 10, 2011 at 11:32 AM, Bruce Whealton  wrote:
problem with is this line:
>     def add(self, (sub, pred, obj)):
> I think the problem is with the parentheses before the sub.  I removed those 
> and that seemed to fix that error or make it go away.  I don’t remember how I 
> figured that out,   It should be on the Errata page for sure.
> Then it has a problem with this line:
>     print list(g.triples((None, None, None)))
> If I was using python 3, it would require () around the thing that is going 
> to be printed, right?  Maybe python 2.7 doesn’t like this line for the same 
> reason.
>

The issue there is with tuple unpacking. To match the older syntax,
don't touch the call, but change the definition thus:
def add(self, args):
  (sub, pred, obj)=args

Or, of course, simply list the arguments directly, rather than in a
tuple; but that requires changing every call (if it's a small program
that may not be a problem).

You're right about needing parentheses around the print() call; in
Python 2 it's a statement, but in Python 3, print is a function like
any other.

Regarding the module search path, this may help:
http://docs.python.org/dev/tutorial/modules.html#the-module-search-path

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


Re: How can I make a program automatically run once per day?

2011-07-09 Thread John Salerno
Thanks everyone! I probably should have said something like "Python,
if possible and efficient, otherwise any other method" ! :)

I'll look into the Task Scheduler. Thanks again!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-09 Thread Cameron Simpson
On 10Jul2011 03:00, Alexander Kapps  wrote:
| On 10.07.2011 02:26, John Salerno wrote:
| >I have a script that does some stuff that I want to run every day for
| >maybe a week, or a month. So far I've been good about running it every
| >night, but is there some way (using Python, of course) that I can make
| >it automatically run at a set time each night?
| 
| Use your operating system's facilities to run timed jobs.
| 
| Unix/Linux: Cron jobs
| Windows: Scheduled Tasks
| Mac: don't know, but probably Cron too

Yep. Macs are UNIX, BSD derived.
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

USENET: Post to exotic, distant machines.  Meet exciting, unusual people.
And flame them. - Dan Sorenson, z1...@exnet.iastate.edu, DoD #1066
-- 
http://mail.python.org/mailman/listinfo/python-list


Newbie help - Programming the Semantic Web with Python

2011-07-09 Thread Bruce Whealton
Hello,
So, I got this book on Programming the Semantic Web about the same 
time I started learning Python.  The code seems to be developed for python 2.7 
and not 3, I believe.  The code is here:
http://semprog.com/content/the-book/
I tried to run simpletriple.py from inside eclipse with PYDEV.  The first thing 
it has a problem with is this line:
def add(self, (sub, pred, obj)):
I think the problem is with the parentheses before the sub.  I removed those 
and that seemed to fix that error or make it go away.  I don’t remember how I 
figured that out,   It should be on the Errata page for sure.  
Then it has a problem with this line:
print list(g.triples((None, None, None)))
If I was using python 3, it would require () around the thing that is going to 
be printed, right?  Maybe python 2.7 doesn’t like this line for the same 
reason.  

The book suggests that from IDLE, I can just use 
>>>from simplegraph import SimpleGraph
That means it is going to look for a file named simplegraph.py
but where will it be looking?  I guess I would have to have it in the same 
folder as the python interpreter or one of the PATH directories, right?
Thanks,
Bruce

++

Bruce Whealton, Owner Future Wave Designs

FOAF: http://whealton.info/BruceWhealtonJr/foaf.rdf

Vcard: http://whealton.info/BruceWhealtonJr/brucewhealtonvcard.html

Web Design and Development http://FutureWaveDesigns.com

http://futurewavedesigns.com/wordpress/

Web Technology wiki: http://futurewavedesigns.com/w/

++

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


Re: What makes functions special?

2011-07-09 Thread Steven D'Aprano
Eric Snow wrote:

> Mostly I am just
> trying to put together more pieces of the Python puzzle.  In this case
> I was trying to find out if the optimized execution of code objects
> for functions is a part of the language or just an implementation
> detail.

You keep using that phrase, "optimized execution of code objects for
functions", but I have no idea what that means.

The best I can think of is that you are thinking along these lines...

"Suppose we have the source code to a function:

def spam(n):
return "SPAM"*n

To execute this, Python currently compiles the function into a code block,
and then when you call spam(n) elsewhere, Python executes the already
compiled code block.

Suppose instead an implementation of Python did not pre-compile the
function. Each time you called spam(n), the implementation would have to
locate the source code and interpret it on the spot. Would that be
allowed?"

If that's your question, then I would call that a Python interpreter using
c.1960 technology (as opposed to a byte-code compiler, which all the main
implementations currently are).

If that were the *only* difference, then I see no reason why it wouldn't be
allowed as an implementation of Python. A horribly slow implementation, but
still an implementation.

However, I doubt that would be the only difference. Given such a
simple-minded Python interpreter, it would be hard to provide expected
Python language features such as compiled code objects, closures, etc. You
would have to fake them somehow. Provided you could fake them sufficiently
well, then the lack of a byte-code compiler is just a quality of
implementation issue.

If that's *not* your question, them I'm stumped.




-- 
Steven

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


Re: What makes functions special?

2011-07-09 Thread Eric Snow
On Sat, Jul 9, 2011 at 6:38 PM, Ben Finney  wrote:
> Eric Snow  writes:
>
>> On Sat, Jul 9, 2011 at 4:41 PM, Ben Finney  
>> wrote:
>> > Eric Snow  writes:
>> >> No other objects have code objects. No other objects in Python have
>> >> this special optimization.
>> >
>> > Yes. The two facts are directly related.
> […]
>
>> > Yes, functions are different and are treated differently. What's
>> > your question?
>>
>> My point is that functions are special in Python because they provide
>> a built in optimization via the special execution of code objects.
>
> Functions are special because they define a code object.
>

Right.  But the point is that the code objects (in CPython at least)
allow a special execution of the function body.  What does that
special execution give us?  I am guessing a sufficient performance
increase.  Is there anything else?  And do other Python
implementations do anything special with code objects?

I am not questioning why it was done a certain way, but rather trying
to understand how Python works.

>> I would like to know if it is really that big a deal
>
> Is *what* really that big a deal?
>
> Perhaps this could be clearer if you'd describe what it is that
> surprises you, and how you'd expect it to be different.
>

I don't have any unexpected failure that I ran into or anything like
that.  I am just trying to learn more about the ins and outs of Python
and that tracker issue got me thinking.  And I know that there are
plenty of people on this list that know a lot more about Python than I
do. :)  So I thought I would ask (in my own obscure way) if I was
understanding the definition/execution model correctly.  Sorry for any
confusion.

-eric

>> and if the optimized execution of code objects is a CPython
>> implementation detail or a specification of the language.
>
> I don't know that it's a specification. But functions result in code
> objects, and other statements don't; I am not seeing why treating them
> differently is surprising.
>
> --
>  \          “I see little commercial potential for the Internet for at |
>  `\                               least ten years.” —Bill Gates, 1994 |
> _o__)                                                                  |
> Ben Finney
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What makes functions special?

2011-07-09 Thread Eric Snow
On Sat, Jul 9, 2011 at 6:21 PM, Terry Reedy  wrote:
> On 7/9/2011 2:28 PM, Eric Snow wrote:
>>
>> A tracker issue [1] recently got me thinking about what makes
>> functions special.  The discussion there was regarding the distinction
>> between compile time (generation of .pyc files for modules and
>> execution of code blocks), [function] definition time, and [function]
>> execution time.  Definition time actually happens during compile time,
>
> Not true. For main modules, execution of each statement immediately follows
> compilation, but not for other modules, where compilation and caching of
> code objects may happen years before the function object is created.
>

So for non-main modules the function definition happens during module
compilation, and for all other code blocks (__main__, exec, etc.) it
happens during execution of the code block?

>> Functions are a special case in Python for providing a more optimized
>> execution of a code block in pure Python code.  And how is that?  When
>> the function is defined, a code object is generated for the function
>> body along with a few "static" details that will be used during
>> execution.  No other objects have code objects.  No other objects in
>> Python have this special optimization.
>
> A .pyc file is a serialized code object for a module.
>

I hadn't thought of it like that.  Nice insight.  In that case, do
[non-main] module definition and execution time have the same logical
separation as function phases do?

> As for the rest, I am not sure what you are asking.
>

Yeah, I have a real knack for communicating.  :)  Mostly I am just
trying to put together more pieces of the Python puzzle.  In this case
I was trying to find out if the optimized execution of code objects
for functions is a part of the language or just an implementation
detail.

-eric

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


Re: How can I make a program automatically run once per day?

2011-07-09 Thread Alexander Kapps

On 10.07.2011 02:26, John Salerno wrote:

I have a script that does some stuff that I want to run every day for
maybe a week, or a month. So far I've been good about running it every
night, but is there some way (using Python, of course) that I can make
it automatically run at a set time each night?


Use your operating system's facilities to run timed jobs.

Unix/Linux: Cron jobs
Windows: Scheduled Tasks
Mac: don't know, but probably Cron too
--
http://mail.python.org/mailman/listinfo/python-list


Re: What makes functions special?

2011-07-09 Thread Ben Finney
Eric Snow  writes:

> On Sat, Jul 9, 2011 at 4:41 PM, Ben Finney  wrote:
> > Eric Snow  writes:
> >> No other objects have code objects. No other objects in Python have
> >> this special optimization.
> >
> > Yes. The two facts are directly related.
[…]

> > Yes, functions are different and are treated differently. What's
> > your question?
>
> My point is that functions are special in Python because they provide
> a built in optimization via the special execution of code objects.

Functions are special because they define a code object.

> I would like to know if it is really that big a deal

Is *what* really that big a deal?

Perhaps this could be clearer if you'd describe what it is that
surprises you, and how you'd expect it to be different.

> and if the optimized execution of code objects is a CPython
> implementation detail or a specification of the language.

I don't know that it's a specification. But functions result in code
objects, and other statements don't; I am not seeing why treating them
differently is surprising.

-- 
 \  “I see little commercial potential for the Internet for at |
  `\   least ten years.” —Bill Gates, 1994 |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-09 Thread Ben Finney
John Salerno  writes:

> is there some way (using Python, of course) that I can make it
> automatically run at a set time each night?

You need to use whatever facilities your operating system has for
scheduled events. That's unrelated to the language you use for
implementing the program.

On a Unix-like system (e.g. GNU+Linux), you could create a ‘cron’ job
entry.

-- 
 \  “The most common way people give up their power is by thinking |
  `\   they don't have any.” —Alice Walker |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I make a program automatically run once per day?

2011-07-09 Thread Andrew Berg
On 2011.07.09 07:26 PM, John Salerno wrote:
> I have a script that does some stuff that I want to run every day for
> maybe a week, or a month. So far I've been good about running it every
> night, but is there some way (using Python, of course) that I can make
> it automatically run at a set time each night?
I would use the OS to worry about scheduling (cron/Windows Task
Scheduler/whatever), but in Python, you could probably use a while True
loop, time.sleep() (to specify how often to check the time) and a
datetime.time or datetime.now object (e.g. datetime.now().hour).
-- 
http://mail.python.org/mailman/listinfo/python-list


How can I make a program automatically run once per day?

2011-07-09 Thread John Salerno
I have a script that does some stuff that I want to run every day for
maybe a week, or a month. So far I've been good about running it every
night, but is there some way (using Python, of course) that I can make
it automatically run at a set time each night?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What makes functions special?

2011-07-09 Thread Terry Reedy

On 7/9/2011 2:28 PM, Eric Snow wrote:

A tracker issue [1] recently got me thinking about what makes
functions special.  The discussion there was regarding the distinction
between compile time (generation of .pyc files for modules and
execution of code blocks), [function] definition time, and [function]
execution time.  Definition time actually happens during compile time,


Not true. For main modules, execution of each statement immediately 
follows compilation, but not for other modules, where compilation and 
caching of code objects may happen years before the function object is 
created.



Functions are a special case in Python for providing a more optimized
execution of a code block in pure Python code.  And how is that?  When
the function is defined, a code object is generated for the function
body along with a few "static" details that will be used during
execution.  No other objects have code objects.  No other objects in
Python have this special optimization.


A .pyc file is a serialized code object for a module.

As for the rest, I am not sure what you are asking.

Terry Reedy

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


Re: What makes functions special?

2011-07-09 Thread Eric Snow
On Sat, Jul 9, 2011 at 4:41 PM, Ben Finney  wrote:
> Eric Snow  writes:
>
>> A tracker issue [1] recently got me thinking about what makes
>> functions special.
>
> As you describe, functions are special for your scenario because a
> function definition needs to result in executable code as an object.
>
>> Definition time actually happens during compile time, but it has its
>> own label to mark the contrast with execution time. So why do
>> functions get this special treatment?
>
> You answer this question.
>
>> No other objects have code objects. No other objects in Python have
>> this special optimization.
>
> Yes. The two facts are directly related.
>
>> Maybe I am missing something, or maybe it is super obvious, but isn't
>> this a critical point?
>
> What is the crisis (“a stark change from one state to another”) that
> you're referring to by “a critical point”?
>
> Yes, functions are different and are treated differently. What's your
> question?
>
>> From the docs, the code objects in of function objects are the latter,
>> but the optimization expectation is not clearly indicated. Are there
>> other motivations behind code objects that I am missing? Am I wrong
>> about the optimization expectation?
>
> What optimisation expectation?
>
>> Thoughts?
>
> I think yours need to be expressed more explicitly; I'm not seeing the
> issue that concerns you.
>

My point is that functions are special in Python because they provide
a built in optimization via the special execution of code objects.  I
would like to know if it is really that big a deal, and if the
optimized execution of code objects is a CPython implementation detail
or a specification of the language.

-eric

> --
>  \        “The reason we come up with new versions is not to fix bugs. |
>  `\                     It's absolutely not.” —Bill Gates, 1995-10-23 |
> _o__)                                                                  |
> Ben Finney
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What makes functions special?

2011-07-09 Thread Ben Finney
Eric Snow  writes:

> A tracker issue [1] recently got me thinking about what makes
> functions special.

As you describe, functions are special for your scenario because a
function definition needs to result in executable code as an object.

> Definition time actually happens during compile time, but it has its
> own label to mark the contrast with execution time. So why do
> functions get this special treatment?

You answer this question.

> No other objects have code objects. No other objects in Python have
> this special optimization.

Yes. The two facts are directly related.

> Maybe I am missing something, or maybe it is super obvious, but isn't
> this a critical point?

What is the crisis (“a stark change from one state to another”) that
you're referring to by “a critical point”?

Yes, functions are different and are treated differently. What's your
question?

> From the docs, the code objects in of function objects are the latter,
> but the optimization expectation is not clearly indicated. Are there
> other motivations behind code objects that I am missing? Am I wrong
> about the optimization expectation?

What optimisation expectation?

> Thoughts?

I think yours need to be expressed more explicitly; I'm not seeing the
issue that concerns you.

-- 
 \“The reason we come up with new versions is not to fix bugs. |
  `\ It's absolutely not.” —Bill Gates, 1995-10-23 |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String concatenation vs. string formatting

2011-07-09 Thread Andrew Berg
On 2011.07.09 06:06 AM, Vinay Sajip wrote:
> In a logging context at least, using the form like
>
> logger.debug("formatting message with %s", "arguments")
>
> rather than
>
> logger.debug("formatting message with %s" % "arguments")
How would I do that with the newer formatting? I've tried:
> logger.info('Binary preset file {file} successfully stored.', {file :
> queue[0].preset_file})
(global name 'file' not defined)
and
> logger.info('Binary preset file {file} successfully stored.',
> file=queue[0].preset_file)
(unexpected keyword 'file')

> By the way, logging primarily uses %-formatting instead of the newer
> {}-formatting, because it pre-dates {}-formatting. In more recent versions of
> Python, all of Python's three formatting styles are supported - see
I've noticed. :-)
> log_formatter = logging.Formatter('{asctime} - __main__ - {funcName} -
> line {lineno} - {levelname} - {message}', style='{')

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


What makes functions special?

2011-07-09 Thread Eric Snow
A tracker issue [1] recently got me thinking about what makes
functions special.  The discussion there was regarding the distinction
between compile time (generation of .pyc files for modules and
execution of code blocks), [function] definition time, and [function]
execution time.  Definition time actually happens during compile time,
but it has its own label to mark the contrast with execution time.  So
why do functions get this special treatment?

Functions are a special case in Python for providing a more optimized
execution of a code block in pure Python code.  And how is that?  When
the function is defined, a code object is generated for the function
body along with a few "static" details that will be used during
execution.  No other objects have code objects.  No other objects in
Python have this special optimization.

Maybe I am missing something, or maybe it is super obvious, but isn't
this a critical point?  Is it just a CPython implementation detail
that code objects should provide an optimization, or is it a
specification of the language?   From the docs, the code objects in of
function objects are the latter, but the optimization expectation is
not clearly indicated.  Are there other motivations behind code
objects that I am missing?  Am I wrong about the optimization
expectation?

Thoughts?

-eric

[1] http://bugs.python.org/issue12374
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why the following python program does not face any concurrency problems without synchronize mechanism?

2011-07-09 Thread Alexander Kapps

On 09.07.2011 22:45, smith jack wrote:

from threading import Thread

def calc(start, end):
 total = 0;
 for i in range(start, end + 1):
 total += i;
 print '--result:', total
 return total

t = Thread(target=calc, args=(1,100))
t.start()

I have run this program for many times,and the result is always 5050,
if there is any concurrency problem, the result should not be 5050,
which is never met, anyhow
I mean this program should get the wrong answer at some times, but
this never happens, why?
can concurrency without synchronize mechanism always get the right answer?
any special case in python programming?


Why do you think, that there's a concurrency problem?

All variables are local to the calc() function and all calc() 
invocations run in an own thread. No thread tries to access any 
shared data, so why should there be a concurrency problem?


Concurrency is an issue, when two or more threads/processes try to 
access the same data, but in your program everything is local to the 
calc() function.

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


why the following python program does not face any concurrency problems without synchronize mechanism?

2011-07-09 Thread smith jack
from threading import Thread

def calc(start, end):
total = 0;
for i in range(start, end + 1):
total += i;
print '--result:', total
return total

t = Thread(target=calc, args=(1,100))
t.start()

I have run this program for many times,and the result is always 5050,
if there is any concurrency problem, the result should not be 5050,
which is never met, anyhow
I mean this program should get the wrong answer at some times, but
this never happens, why?
can concurrency without synchronize mechanism always get the right answer?
any special case in python programming?
-- 
http://mail.python.org/mailman/listinfo/python-list


ctypes: point to buffer in structure

2011-07-09 Thread Jesse R
Hey I've been trying to convert this to run through ctypes and i'm
having a hard time

typedef struct _SYSTEM_PROCESS_ID_INFORMATION
{
HANDLE ProcessId;
UNICODE_STRING ImageName;
} SYSTEM_PROCESS_IMAGE_NAME_INFORMATION,
*PSYSTEM_PROCESS_IMAGE_NAME_INFORMATION;

to

class SYSTEM_PROCESS_ID_INFORMATION(ctypes.Structure):
_fields_ = [('pid', ctypes.c_ulong),
('imageName', ctypes.c_wchar_p)]

processNameBuffer = ctypes.create_unicode_buffer(0x100)
pidInfo = SYSTEM_PROCESS_ID_INFORMATION(pid,
ctypes.byref(processNameBuffer))
status = ntdll.NtQuerySystemInformation(0x58, ctypes.byref(pidInfo),
ctypes.sizeof(pidInfo), None)

does anyone know how to get this working?
-- 
http://mail.python.org/mailman/listinfo/python-list


HTTP Proxy : receive call on local socket takes a lot of time

2011-07-09 Thread Rémi

Hi all,

I am currently working on a HTTP Proxy. For maximum flexibility, I am 
implementing the proxy at a low level : I am using the SocketServer library.


The server itself is very simple:

class MyTCPServer(SocketServer.TCPServer):
allow_reuse_address = 1

and the handler looks like:

class MyTCPHandler(SocketServer.BaseRequestHandler):

def handle(self):
# Prints ip and port
print "\n  " + str(self.client_address) + " "

requestParser = HTTPRequestParser()

while True:
# Get packet
data = self.request.recv(4096)

if data == '':
break

# Parse request packet
if requestParser.got_new_chunk(data):
break

someStuff = ""
self.request.send(someStuff)


This is working fine, but I have a small performance issue.
The proxy is targeted by Firefox. Sometimes the first receive call on 
the input socket takes a lot of time (up to 20s sometimes), which should 
not be as this is a communication of two local sockets. This is 
occurring maybe every 30 requests or so.


When looking at the logs I noticed that this weird behavior happens when 
the client port is not contiguous to the previous ones. For example, 
handling the fourth request takes a lot of time:


  ('127.0.0.1', 49704) 
  ('127.0.0.1', 49705) 
  ('127.0.0.1', 49706) 
  ('127.0.0.1', 49674) 


Do you have any idea what the problem could be ? I tried to manually 
close self.request request, but I still have the problem. Is it related 
to "allow_reuse_address = 1" ?


Thanks for your help !

Rémi
--
http://mail.python.org/mailman/listinfo/python-list


Re: String concatenation vs. string formatting

2011-07-09 Thread Vinay Sajip
Andrew Berg  gmail.com> writes:

> Other than the case where a variable isn't a string (format() converts
> variables to strings, automatically, right?) and when a variable is used
> a bunch of times, concatenation is fine, but somehow, it seems wrong.
> Sorry if this seems a bit silly, but I'm a novice when it comes to
> design. Plus, there's not really supposed to be "more than one way to do
> it" in Python.

In a logging context at least, using the form like

logger.debug("formatting message with %s", "arguments")

rather than

logger.debug("formatting message with %s" % "arguments")

means that the formatting is deferred by logging until it is actually needed. If
the message never gets output because of the logging configuration in use, then
the formatting is never done. This optimisation won't matter in most cases, but
it will in some scenarios.

By the way, logging primarily uses %-formatting instead of the newer
{}-formatting, because it pre-dates {}-formatting. In more recent versions of
Python, all of Python's three formatting styles are supported - see

http://plumberjack.blogspot.com/2010/10/supporting-alternative-formatting.html

Also by the way - Python doesn't say there shouldn't be more than one way to do
things - just that there should be one *obvious* way (from the Zen of Python).

Regards,

Vinay Sajip

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