Re: PEP8 and 4 spaces

2014-07-03 Thread Toby Shepard

On 07/03/2014 12:44 PM, Simon Ward wrote:



On 3 July 2014 18:31:04 BST, Tobiah  wrote:

Coworker takes PEP8 as gospel and uses 4 spaces to indent.  I
prefer tabs.  Boss want's us to unify.


This isn't worth arguing about.


How point of view changes things.




Anyway, I gave up the 80 char line length long ago, having little
feeling for some dolt on a Weiss terminal that for some reason
needs to edit my code.


Putting the code factoring considerations aside, because others have
already mentioned them and I'm sure others will, there are some other
practical reasons for limiting line width:


All that is fine, and makes great sense.  I generally write short lines.
I know the tricks for splitting otherwise long lines into multiple readable
lines.  I'm not advocating that we use semicolons and always go past 80
characters.  I'm just saying that once in a while it makes sense to me
to do it, and I don't lose sleep when it happens.
 

I feel rather the same about the spaces and tabs, given that most
people seem to be using editors these days that are configurable to
show tabs a four characters.


Conversely, those same editors can probably automatically indent and
unindent a configurable amount of spaces. If you don't use such an
editor, and you really can't tolerate the different style, you can
use another tool to reindent your code.


It works both ways.  I'm using Vim, and it will handle the spaces
and give a tab-like experience - not quite as good, but good enough
to live with.  Either of us could give in.  The boss likes tabs,
as I do.  The coworker really only has PEP8 to point to.  There is
really nothing good about the space way, other than as I said, Notepad
users will see four space indents.  Most other users can configure the tabstop
as they like *if* tabs are being used.  The Notepad users will get by just fine.

It could fall either way.  I was just trying to nudge it toward mine.

Tobiah

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


Re: PEP8 and 4 spaces

2014-07-03 Thread Toby Shepard

On 07/03/2014 10:46 AM, Tim Chase wrote:

Any evidence out there that this part of PEP8 is becoming
more optional or even obsolete, as I've heard others
say about the 80 char line length?

Just need ammo for when the hammer of code
unification comes down.


I'm not sure you'll get a whole lot of "PEP8 is optional or
obsolete", though some may protest the 80-char suggestion.

While I prefer tabs for similar reasons you present (I can set them
to display at whatever width is comfortable), I have Vim configured
to expand tabs into spaces so that my code conforms to standards.

If you're really picky about it, just create hooks in your VCS (you
ARE using revision control, right?) that turn
$STANDARD_NUMBER_OF_SPACES into a tabs at checkout, and then revert
tabs back to that number of spaces pre-commit.  For git, this SO
post covers it:

http://stackoverflow.com/questions/2316677/can-git-automatically-switch-between-spaces-and-tabs



Very interesting.  Yes, we're using Git.  Thanks for the suggestion.

Tobiah

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


Re: Real time event accuracy

2012-05-09 Thread Toby
On 05/09/2012 09:13 AM, Dave Angel wrote:
> On 05/09/2012 11:52 AM, Tobiah wrote:
>> I'd like to send MIDI events from python to another
>> program.  I'd like advice as to how to accurately
>> time the events.  I'll have a list of floating point
>> start times in seconds for the events, and I'd like to send them
>> off as close to the correct time as possible.
>>
>> I'd also appreciate suggestions and pointers to a 
>> suitable python MIDI library, and maybe an outline
>> of what must be done to get the MIDI events to 
>> the other program's MIDI in.
>>
>> Thanks,
>>
>> Tobiah
> 
> You really need to specify the OS environment you're targeting, as well
> as telling what program you're intending to feed MIDI into, if you've
> already picked one.

I'm using Kontakt on Windows 7.  The MIDI file think would be good, but
(not having that computer in front of me) I don't think that Kontakt
had the ability to open a MIDI file.

Now, I know that I could load the file into Reaper, and use Kontakt
as a plugin.  My problem is that I can't afford to mess with GUI menus
during my composition process.  I need to edit a python program in
Vi, then slap it out to python, hearing the music, then edit again.
The cycle has to be very quick in order to get anything done.

Loading Kontakt with a bunch of samples is very time consuming, so
it needs to keep running.  Now, if I could find a program that would
interpret the MIDI file and send events off to Kontakt either as a plugin
or standalone, then the MIDI file generation idea would be perfect.



> Also, the midi file format has timing information, and that timing
> should be much better than trying to do it in python before sending
> commands to some external program.  In other words, instead of sleeping
> in your code and then issuing one midi event, use the midi file format
> to send a stream of commands that will be played according to the timing
> information included.
> 
> 
> 
> 

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


Re: Scheme as a virtual machine?

2010-11-24 Thread toby
On Nov 24, 1:10 pm, Raffael Cavallaro
 wrote:
> On 2010-11-23 11:34:14 -0500, Keith H Duggar said:
>
> > You don't understand the implications of your own words:
>
> >    "having a financial interest in the outcome of a debate makes
> >    anything that person says an advertisement for his financial
> >    interests, not a fair assessment."
>
> > is substantially different from
>
> >    "render his arguments in the debate inherently suspect."
>
> They are substantially the same, your jesuitical nit-picking
> notwithstanding; JH is an untrustworthy source on matters relating to
> the languages he sells training for.
>

And furthermore, he has cooties.

--T

> warmest regards,
>
> Ralph
>
> --
> Raffael Cavallaro

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


Re: Scheme as a virtual machine?

2010-11-22 Thread toby
On Nov 22, 12:28 pm, namekuseijin  wrote:
> On 22 nov, 14:47, Howard Brazee  wrote:
>
> > On Mon, 22 Nov 2010 08:14:40 -0800 (PST), toby
>
> >  wrote:
> > >This is a good (if familiar) observation. Teaching children (or young
> > >people with little exposure to computers) how to program in various
> > >paradigms could produce interesting primary evidence. Pity that this
> > >isn't examined widely and systematically. We could learn something
> > >about how to teach programming and design languages this way, don't
> > >you agree?
>
> > I do.
>
> > A study such as that would be more useful than how to teach languages
> > - it could be useful in teaching other stuff as well.
>
> yes, pity most children are (used to be) taught Basic first.
>
> Also, with a study like this, it's likely some children would be
> taught some lame language and others would be taught some "industrial
> strength" language and still others would be taught some esoteric
> language.

This is not worse than the status quo, which does exactly that, but
without paying attention to outcomes.

What I am proposing is doing it systematically, with observation. Then
we can learn something.

> I'm not sure it'd prove as much as we are hoping for -- as
> they are all Turing equivalent and the kids would be able to
> eventually do the task asked for in any of them -- but I'm sure some
> of those children would be mentally hurt for all their life.  Poor
> pioneers :p
>
> JH, nice to have you back! :)

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


Re: Scheme as a virtual machine?

2010-11-22 Thread toby
On Nov 22, 10:57 am, Howard Brazee  wrote:
> On Mon, 22 Nov 2010 05:38:53 +0100, Ertugrul S ylemez 
> wrote:
>
> >Haskell is a simple language with a comparably small specification.
> >It's not as simple as Common Lisp, but it's simple.  Note that simple
> >doesn't mean easy.  Haskell is certainly more difficult to learn than
> >other languages, which explains the low number of success stories.  On
> >the other hand, I'm doing rapid web development in it.
>
> I wonder how much that difficulty is innate, and how much is due to
> learning other languages first.

This is a good (if familiar) observation. Teaching children (or young
people with little exposure to computers) how to program in various
paradigms could produce interesting primary evidence. Pity that this
isn't examined widely and systematically. We could learn something
about how to teach programming and design languages this way, don't
you agree?

The OLPC might do some interesting things in this area but it is still
one set of tools. More interesting might be to compare outcomes across
a range of different tools, paradigms, syntaxes, and teaching
strategies.

> I'm an old time CoBOL programmer, and know of quite a few people who
> tried to learn OO-CoBOL without much luck.   The way to learn it was
> to forget it - learn OO with some other language, then come back to it
> later.    We had to divorce ourselves from the old paradigm first.    
>
> --
> "In no part of the constitution is more wisdom to be found,
> than in the clause which confides the question of war or peace
> to the legislature, and not to the executive department."
>
> - James Madison

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


Re: NoSQL Movement?

2010-03-03 Thread toby
On Mar 3, 3:54 pm, ccc31807  wrote:
> On Mar 3, 12:36 pm, Xah Lee  wrote:
>
> > recently i wrote a blog article on The NoSQL Movement
> > athttp://xahlee.org/comp/nosql.html
>
> > i'd like to post it somewhere public to solicit opinions, but in the
> > 20 min or so, i couldn't find a proper newsgroup, nor private list
> > that my somewhat anti-NoSQL Movement article is fitting.
>
> I only read the first two paragraphs of your article, so I can't
> respond to it.
>
> I've halfway followed the NoSQL movement. My day job is a database
> manager and I so SQL databases for a living, as well as Perl. I see a
> lot of abuse of relational databases in the Real World, as well as a
> lot of abuse for non-SQL alternatives, e.g., (mis)using Excel for a
> database. The big, enterprise database we have at work is built on IBM
> UniQuery, which is a non-SQL flat file database product, so I've had a
> lot of experience with big non-SQL database work.
>
> I've also developed a marked preference for plain text databases. For
> a lot of applications they are simpler, easier, and better. I've also
> had some experience with XML databases, and find that they are ideal
> for applications with 'ragged' data.
>
> As with anything else, you need to match the tool to the job. Yes, I
> feel that relational database technology has been much used, and much
> abused. However, one of my favorite applications is Postgres, and I
> think it's absolutely unbeatable

It is beatable outside of its sweetspot, like any system. NoSQL is not
so much about "beating" relational databases, as simply a blanket term
for useful non-relational technologies. There's not much point in
reading Xah beyond the heading of his manifesto, as it is no more
relevant to be "anti-NoSQL" as to be "anti-integers" because they
don't store fractions.

>  where you have to store data and

"relational data"

> perform a large number of queries.

Why does the number matter?

>
> Finally, with regard to Structured Query Language itself, I find that
> it's well suited to its purpose. I hand write a lot of SQL statements
> for various purposes, and while like any language you find it
> exceedingly difficult to express concepts that you can think, it
> mostly allows the expression of most of what you want to say.
>
> CC.

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


Re: Xah's Edu Corner: The importance of syntax & notations.

2009-08-16 Thread toby
On Aug 16, 12:05 pm, Peter Keller  wrote:
> In comp.lang.scheme Xah Lee  wrote:
>
> > Xah's Edu Corner: The importance of syntax & notations.
>
> >http://www.stephenwolfram.com/publications/recent/mathml/mathml_abstr...
>
> > this article should teach the coding sophomorons and computer
> > ?science? idiotic authors who harbor the notion that syntax is not
> > important, picked up by all the elite i-reddit & twittering &  hacker
> > news am-hip dunces.
>
> I must have really tweaked you with my "Syntax is not important, ideas are."
> statement.
>
> I read Wolfram's article carefully. He applies an intuitive sense onto
> why he does or doesn't like a particular notation, but yet can't really
> elucidate his feelings.

Exactly; and as far as I can determine, Knuth does the same. He
applies standards of *good taste* to his notation. (No surprise that
he's also singled out for vituperation by the OP.)

In my opinion Knuth believed in the value of literate programming for
similar reasons: To try to exploit existing cognitive training. If
your user base is familiar with English, or mathematical notation, or
some other lexicography, try to exploit the pre-wired associations.
Clearly this involves some intuition.

> ...
> Thank you.
>
> -pete

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


Re: multi-core software

2009-06-09 Thread toby
On Jun 7, 2:41 pm, Jon Harrop  wrote:
> Arved Sandstrom wrote:
> > Jon Harrop wrote:
> >> I see no problem with mutable shared state.
>
> > In which case, Jon, you're in a small minority.
>
> No. Most programmers still care about performance

Frequently when they shouldn't.

> and performance means
> mutable state.

Hm, not sure Erlangers would wholly agree.

>
> --
> Dr Jon D Harrop, Flying Frog Consultancy Ltd.http://www.ffconsultancy.com/?u

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


Re: Mathematica 7 compares to other languages

2008-12-10 Thread toby
On Dec 10, 3:37 pm, [EMAIL PROTECTED] wrote:
> On Dec 5, 9:51 am, Xah Lee <[EMAIL PROTECTED]> wrote:
>
>
>
> > For those of you who don't know linear algebra but knows coding, this
> > means, we want a function whose input is a list of 3 elements say
> > {x,y,z}, and output is also a list of 3 elements, say {a,b,c}, with
> > the condition that
>
> > a = x/Sqrt[x^2+y^2+z^2]
> > b = y/Sqrt[x^2+y^2+z^2]
> > c = z/Sqrt[x^2+y^2+z^2]
>
> > In lisp, python, perl, etc, you'll have 10 or so lines. In C or Java,
> > you'll have 50 or hundreds lines.

void normalise(float d[], float v[]){
float m = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
d[0] = v[0]/m;  // My guess is Xah Lee
d[1] = v[1]/m;  // hasn't touched C
d[2] = v[2]/m;  // for near to an eternitee
}


>
> Ruby:
>
> def norm a
>   s = Math.sqrt(a.map{|x|x*x}.inject{|x,y|x+y})
>   a.map{|x| x/s}
> end

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


Re: Mathematica 7 compares to other languages

2008-12-03 Thread toby
On Dec 3, 4:15 pm, Xah Lee <[EMAIL PROTECTED]> wrote:
> On Dec 3, 8:24 am, Jon Harrop <[EMAIL PROTECTED]> wrote:
>
> > My example demonstrates several of Mathematica's fundamental limitations.
>
> enough babble Jon.
>
> Come flying $5 to my paypal account, and i'll give you real code,

I'll give you $5 to go away

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


Re: Mathematica 7 compares to other languages

2008-12-03 Thread toby
On Dec 2, 5:04 pm, Tamas K Papp <[EMAIL PROTECTED]> wrote:
> On Tue, 02 Dec 2008 13:57:35 -0800, Lew wrote:
> > Xah Lee wrote:
> >> If [yo]u would like to learn [the] [E]nglish lang[uage] and writing
> >> insights from me, peruse:
>
> > /Au contraire/, I was suggesting a higher standard for your posts.
>
> Hi Lew,
>
> It is no use.  Xah has been posting irrelevant rants in broken English
> here for ages.  No one knows why, but mental institutions must be really
> classy these days if the inmates have internet access.  Just filter him
> out with your newsreader.

You think the posts are bad... check out his web site...
--T

>
> Best,
>
> Tamas

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


Re: Mathematica 7 compares to other languages

2008-12-01 Thread toby
On Dec 1, 5:24 am, budden <[EMAIL PROTECTED]> wrote:
> Mathematica is a great language, but:
> 1. it is too slow
> 2. It is often hard to read
> 3. It gives sence to every keystroke. You press escape by occasion and
> it goes in a code as a new
> symbol, w/o error. Nasty.
> 3. I know 5-th version. It does not allow to track the source as SLIME
> does. This feature as absolutely
> necessary for serious development

Worst of all, it's proprietary, which makes it next to useless. Money
corrupts.

>
> So, in fact, Mathematica do not scale well IMO.

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


emacs python mode problem

2007-12-05 Thread Toby
For some reason, emacs python-mode has stopped working for me. It has
been working without any problems since I installed it on Ubuntu Gutsy
Gibbon, but now the "Start Interpreter" causes emacs to hang requiring
me to kill emacs. Other parts of python-mode seem to work okay,
though. Any suggestions?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to build Hierarchies of dict's? (Prototypes in Python?)

2007-02-25 Thread Toby
class  value'
print '  =  ='
print '\n'.join([ "  %-6s '%s'" % x for x in found ])
print '(now choose wisely what to return)'

return None


# example use of AttrSearch in a class hierarchy:

class A(AttrSearch):
  a = 'attribute "a" of class A'

class B(A):
  a = 'attribute "a" of class B'

class C(A):
  a = 'attribute "a" of class C'

class D(B, C):
  a = 'attribute "a" of class D'

t = D()
t.a = 'attribute "a" of instance t'

# --- end ---

Now if you ask for t.a, for example in a print statement, you get None,
but not before the following lines are printed to stdout:


Looking for "a" in a D instance, found 5 candidates:
  class  value
  =  =
  D  'attribute "a" of class D'
  B  'attribute "a" of class B'
  A  'attribute "a" of class A'
  None   'attribute "a" of instance t'
  C  'attribute "a" of class C'
(now choose wisely what to return)



HTH
Toby

PS: I couldn't make out what you meant with your code... I fear it's
because of the hideous formatting :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to build Hierarchies of dict's? (Prototypes in Python?)

2007-02-25 Thread Toby
Charles D Hixson wrote:
> a class whose sub-classes automatically have unique class variables of
> a determined form such that I can do a hierarchical search through them

Something like this?  
(scroll down to see the results)


# --- begin ---

class AttrSearch(object):
  @classmethod
  def getclassattrset(cls, name):
s = set()
if name in cls.__dict__:
  s.add((cls.__name__, cls.__dict__[name]))
for base in cls.__bases__:
  try:
s.update(base.getclassattrset(name))
  except AttributeError:
pass
return s

  def getattrset(self, name):
s = set()
try:
  s.add((None, self.__dict__[name]))
except KeyError:
  pass
s.update(self.__class__.getclassattrset(name))
return s

  def __getattribute__(self, name):
if name.startswith('__'): #XXX not pretty
  return object.__getattribute__(self, name)
found = AttrSearch.getattrset(self, name)
print 'Looking for "%s" in a %s instance, found %d candidates:' \
  % (name, self.__class__.__name__, len(found))
print '\n'.join([ '  %-4s %s' % x for x in found ])
print '(now choose wisely what to return)'

class A(AttrSearch):
  a = 1

class B(A):
  a = 2

class C(A):
  a = 3

class D(B, C):
  a = 4


D().a

# --- end ---


Results:

Looking for "a" in a D instance, found 4 candidates:
  A1
  B2
  C3
  D4
(now choose wisely what to return)


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


Re: Endianness conversion

2007-02-24 Thread Toby
Daniel Harding wrote:
> Try the using the array module.  array objects provide a byteswap
> method which reverses endianness.

Thanks!


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


Re: Endianness conversion

2007-02-24 Thread Toby
Dan Sommers wrote:
> You could try the struct module.  If your input comes in fixed sized
> chunks, just call struct.unpack and struct.pack once per chunk.

Thanks, but it was a bit awkward to use for big chunks.

I ended up writing my own byteswapper in Pyrex:


def swapbytes(data):
  "Swap every two bytes of a even-sized python string, in place"
  cdef int i
  cdef char t, *p
  p = data
  for i from 0 <= i < len(data) / 2:
t = p[0]
p[0] = p[1]
p[1] = t
p = p + 2


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


Re: How to build Hierarchies of dict's? (Prototypes in Python?)

2007-02-24 Thread Toby
Charles D Hixson wrote:
> What I basically want is a kind of class that has both class and 
> instance level dict variables, such that descendant classes 
> automatically create their own class and instance level dict variables.  
> The idea is that if a member of this hierarchy looks up something in 
> it's local dict, and doesn't find it, it then looks in the class dict, 
> and if not there it looks in its ancestral dict's.  This is rather like 
> what Python does at compile time, but I want to do it at run time.

I don't understand, Python already does it at runtime:

class A:
  A_class_var = 1

class B(A):
  B_class_var = 2
  def __init__(self):
self.B_inst_var = 3

>>> b.A_class_var
1
>>> b.B_class_var
2
>>> b.B_inst_var
3
>>> A.another = 4
>>> b.another
4

Can you post a ">>>"-script of what you would like your classes to do?


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


Endianness conversion

2007-02-24 Thread Toby
As part of a program I'm writing, I need to save to disk big amounts of
data (hundreds of MB, in 8kB chunks) swapping every couple of bytes.  

I obviously cannot do it in a Python loop.

Is there a function I could use in the standard library, or do I have to
write my own C extension?


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


Re: Finding non ascii characters in a set of files

2007-02-24 Thread Toby A Inkster
bg_ie wrote:

> What I'd like to do is scan a directory and list all the
> files in it that contain a non ascii character.

Not quite sure what your intention is. If you're planning a one-time scan
of a directory for non-ASCII characters in files, so that you can manually
fix those files up, then this Perl one-liner will do the trick. At the
command line, type:

perl -ne 'print "$ARGV:$.\n" if /[\x80-\xFF]/;' *

This will print out a list of files that contain non-ASCII characters, and
the line numbers which those characters appear on. Note this also
operates on binary files like images, etc, so you may want to be more
specific with the wildcard. e.g.:

perl -ne 'print "$ARGV:$.\n" if /[\x80-\xFF]/;' *.py *.txt *.*htm*

-- 
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Rational numbers

2007-02-24 Thread Toby A Inkster
aleaxit wrote:

> If anybody who has easy access to Microsoft's MSVC++.NET (and is willing
> to try building GMP 4.2 with/for it), or a PPC Mac with XCode installed
> (possibly with MacOSX 10.3...)

I'm writing this message on a MacOS 10.3.9 box with Xcode 1.5 (gcc 3.3)
installed. If you tell me how, I'd be happy to compile it for you.

Contact me through the feedback form on the site below.

-- 
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: BDFL in wikipedia

2007-02-21 Thread Toby A Inkster
Jorge Vargas wrote:

> shouldn't it mention Linus, Larry Wall, others?[3]

Despite the link you posted, I don't think Linus, Larry Wall, Rasmus
Lerdorf, etc describe themselves as BDFLs, even if they fulfil similar
roles within their respective development communities.

-- 
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
Now Playing ~ ./vol/music/snug/from_solar_to_polar/04_naked_+_smiling.ogg

* = I'm getting there!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: BDFL in wikipedia

2007-02-21 Thread Toby A Inkster
Steven D'Aprano wrote:
> Carl Banks wrote:
>> 
>> Since when is Larry Wall benevolent?  He should be called the SDFL.
> 
> I can't think what the S stands for... if it was M, I'd say Malevolent,
> but S?

Scented, Sexy, Spanish... no, probably not those.

I assume "Sadistic".

-- 
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
Now Playing ~ ./vol/music/gorkys_zygotic_mynci_-_poodle_rockin.ogg

* = I'm getting there!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Thanks for the help

2007-02-09 Thread Toby A Inkster
[EMAIL PROTECTED] wrote:
> Reid wrote:
>
>> I do not need 3d stuff. Just a couple of buttons and menu's.
> 
> That's not "3D", that's GUI (Graphical User Interface). "3D" usually
> refers to "3D graphics"...

Hence the original poster's clever use of the word "not" ;-)

-- 
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/CSS/Javascript/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lambda functions ?

2007-02-05 Thread Toby A Inkster
Maxim Veksler wrote:

> And what is the "f" object? An integer? a pointer? an Object?

A function.

-- 
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/CSS/Javascript/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Subscribing" to topics?

2007-02-04 Thread Toby A Inkster
Mizipzor wrote:

> I searhed around a little and it seems that not only do i need a
> newsreader, i need a newsserver to. To fetch all the messages from
> here. I learned that sometimes the ISP provides one, however, mine do
> not. But then I discovered that Google has a free newsserver, so I
> joined this group from there.

You discovered wrong -- Google does not provide a free newsserver. They no
doubt *have* several newsservers, but don't provide direct access to them
either free, or for a fee. They only provide a web interface to access the
contents of their newsservers, with a fraction of the features that a real
newsreader would.

You seem to already have a newsreader -- you're using Opera, which
includes a fairly good one, hidden away in the Hotlist/Panels/whatever-
they're-calling-it-today. Other newsreaders I'd recommend are PAN and
Forte Agent.

So you just need a server. "pubnews.gradwell.net" still seems to exist --
it's free. Alternatively, "news.individual.net" offers a good service for
a fairly low yearly cost.

-- 
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/CSS/Javascript/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing "pythonish" code

2007-02-02 Thread Toby A Inkster
Mizipzor wrote:

> One thing is that in c++ im used to have private members in classes and
> no member is altered except through the public functions of the class.

By convention, class members starting with a single underscore are
considered private. 

This is much the same as the convention that on UNIX, files that start with
a dot are considered hidden -- there is nothing actually *preventing* a
programme from showing you these files in a directory listing, but by
convention it won't, unless you explicitly ask to see them.

Class members starting with a double underscore are "mangled" which makes
it more difficult for other code (even subclasses!) to access the member.
Difficult though -- not impossible.

-- 
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/CSS/Javascript/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Web File System

2007-01-31 Thread Toby A Inkster
anthony.cutrone wrote:

> Files and folders have to be in an SQL database, mounted in ext3-like 
> system. File would be identified by a single ID, and links with names 
> should be connected on these IDs.

Take a look at FUSE.

Also, have you considered subversion?

-- 
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/CSS/Javascript/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Commandline wrapper: help needed

2007-01-28 Thread Toby
Toby A Inkster wrote:
> Hello Toby, excellent name you have there. 

Why, thank you!

> What advantage (if any) does this method have over standard UNIX-style
> pipes?

The advantage is being able to write my own filters and input/output
modules and have as small a granularity as needed (while standard UNIX
filters such as cat, grep, sed and awk process entire lines at a time.)
For example I can launch an interactive shell of some kind and use it
both from the terminal I opened it in, and from the network, if my
script is listening on a socket.

By the way, I am using standard UNIX pipes, that's how popen() works!


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


Re: Ip address

2007-01-28 Thread Toby A Inkster
Scripter47 wrote:

> How do i get my ip address?

Which IP address. One computer might have many IP addresses. (Indeed a
typical network-connected computer will tend to have at least one for each
connected network device, plus the special address 127.0.0.1 for the
loopback network.) How is Python supposed to know which IP address you
want?

If you don't care which address, the code supplied by Adam should work. If
you do care, then you'll probably need to write OS-specific code for each
platform you choose to support, probably parsing the output of ipconfig
(Windows) or ifconfig (Linux/UNIX/Mac) somehow.

Adam also says:
| If you are wanting to to communicate over the internet you will have 
| to get the IP of you rounter.

Not strictly true, but if your network uses NAT, and you want some host
outside your network to be able to *connect to you*, then yes, you need the
IP address of your router. If you're not using NAT, then you shouldn't
need to worry about your router, as IP addresses alone provide full
end-to-end routing. (Indeed that's the whole point of IP.)

-- 
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/CSS/Javascript/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ip address

2007-01-28 Thread Toby A Inkster
Steve Holden wrote:

> There is absolutely no need to know the IP address of "your router" to 
> communicate with Internet devices. Either your IP layer is configured to 
> know the addresses of one or more routers, or it has discovered those 
> address by dynamic means, or you can't get off-net because there aren't 
> any routers.

... or you can't get off-net because you don't *know* the routers.

-- 
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/CSS/Javascript/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Commandline wrapper: help needed

2007-01-28 Thread Toby A Inkster
Toby wrote:

> Any idea how to improve the script and solve this problem?

Hello Toby, excellent name you have there. What advantage (if any) does
this method have over standard UNIX-style pipes?

-- 
Toby A Inkster BSc (Hons) ARCS
Contact Me  ~ http://tobyinkster.co.uk/contact
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to remove c++ comments from a cpp file?

2007-01-27 Thread Toby
Frank Potter wrote:
> r=re.compile(ur"//[^\r\n]+$", re.UNICODE|re.VERBOSE)
> f_new=r.sub(ur"",f)

>From the documentation:

re.MULTILINE
When specified [...] the pattern character "$" matches at the
end of the string and at the end of each line (immediately
preceding each newline). By default [...] "$" matches only at
the end of the string.

re.DOTALL
[...] without this flag, "." will match anything except a newline.

So a simple solution to your problem would be:

r = re.compile("//.*")
f_new = r.sub("", f)


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


Commandline wrapper: help needed

2007-01-27 Thread Toby
I'm trying to write a simple commandline wrapper: a script that runs
another program as a child and relays unbuffered stdin and stdout
to/from the child process, possibly filtering it.

The usefulness of such a program lies in the filtering stage, in a
possible integration with readline, or in other interface enhancements.

Still, I'd like to discuss with you the unfiltered, unembellished
version, because I'm not satisfied with it and because I'm having some
minor problems.

Here's the script:


#!/usr/bin/python

import sys, os, thread

def stdin_handler(child_stdin):
  while True:
d = sys.stdin.read(1)
if not d: break
child_stdin.write(d)
child_stdin.flush()
  child_stdin.close()

def stdout_handler(child_stdout):
  while True:
try:
  d = child_stdout.read(1)
  if not d: break
  sys.stdout.write(d)
  sys.stdout.flush()
except KeyboardInterrupt:
  pass

def wrap(cmd):
  child_stdin, child_stdout = os.popen2(cmd)
  thread.start_new_thread(stdin_handler, (child_stdin,))
  stdout_handler(child_stdout)

if __name__ == '__main__':
  wrap(sys.argv[1])


You invoke it passing a program name as the first argument (such as
bash, python itself, sbcl, whatever) and then you interact with the
child process as if this wrapper wasn't there.  Ctrl-C and Ctrl-D work
as expected, sending SIGINT (that the child program can catch) and
closing stdin respectively.

Problems:

1.

I don't like the read(1) loops.  I'd like to be able to read bigger
chunks at a time, but I haven't found a way to do that while keeping the
functionality intact.  I have tried fidgeting with select() but I didn't
get far.  What I (think I) need is a non-blocking read(), but I'm not
sure how to achieve that, at least with Python 2.4 on Linux.

2.

Even this version sometimes has problems.  For example, if you launch
the wrapper around sbcl (a free Lisp interpreter/compiler) it mostly
works (entering 1 gives 1, entering (+ 2 3) gives 5...) until you get to
the debugger, for example by entering an undefined name.  Now, when the
debugger says "0: [ABORT] Exit debugger...", entering 0 should get you
back to the "*" prompt--and indeed does, unless you are using my
wrapper, in which case everything hangs, and the only solution is to
terminate everything with Ctrl-\ or such.

Any idea how to improve the script and solve this problem?


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


Re: Error importing .pyd python extension

2006-10-30 Thread Toby
P.S. I have run 'depends', and all the dll's are there, the only error
its throwing up is:

"Warning: At least one module has an unresolved import due to a missing
export function in a delay-load dependent module."

The offending file is mpr.dll in c:\windows\system32\

Any ideas?

Toby

Toby wrote:
> Hi, I've managed to get my hands on the ms 2003 toolkit, and have
> successfully (i think) created a .pyd file in win xp (setup.py is
> provided intersystems cache):
>
> 
> C:\CacheSys\Dev\python>setup.py install
> enter directory where you installed Cache'c:\CacheSys
> libdir=c:\CacheSys\dev\cpp\lib
> include dir=c:\CacheSys\dev\cpp\include
> running install
> running build
> running build_py
> running build_ext
> running install_lib
> creating C:\Program Files\Python243\Lib\site-packages\intersys
> copying build\lib.win32-2.4\intersys\pythonbind.py -> C:\Program
> Files\Python243
> \Lib\site-packages\intersys
> copying build\lib.win32-2.4\intersys\pythonbind1.pyd -> C:\Program
> Files\Python2
> 43\Lib\site-packages\intersys
> copying build\lib.win32-2.4\intersys\__init__.py -> C:\Program
> Files\Python243\L
> ib\site-packages\intersys
> byte-compiling C:\Program
> Files\Python243\Lib\site-packages\intersys\pythonbind.
> py to pythonbind.pyc
> byte-compiling C:\Program
> Files\Python243\Lib\site-packages\intersys\__init__.py
>  to __init__.pyc
>
> C:\CacheSys\Dev\python>cd \program
> files\python243\Lib\site-packages\intersys\
>
> C:\Program Files\Python243\Lib\site-packages\intersys>dir
>  Volume in drive C is SYSTEM
>  Volume Serial Number is 3835-49DE
>
>  Directory of C:\Program Files\Python243\Lib\site-packages\intersys
>
> 31/10/2006  10:47 AM  .
> 31/10/2006  10:47 AM  ..
> 19/10/2006  05:50 PM 1,598 pythonbind.py
> 31/10/2006  10:47 AM 1,961 pythonbind.pyc
> 31/10/2006  09:44 AM69,632 pythonbind1.pyd
> 17/07/2006  05:34 PM 2 __init__.py
> 31/10/2006  10:47 AM   145 __init__.pyc
>5 File(s) 73,338 bytes
>2 Dir(s)  16,709,017,600 bytes free
> 
>
> However, when I try to import pythonbind1.pyd I get the following
> error:
>
> Traceback (most recent call last):
>   File
> "C:\PROGRA~1\ACTIVE~1.5\lib\support\dbgp\pythonlib\dbgp\client.py",
> line 1843, in runMain
> self.dbg.runfile(debug_args[0], debug_args)
>   File
> "C:\PROGRA~1\ACTIVE~1.5\lib\support\dbgp\pythonlib\dbgp\client.py",
> line 1538, in runfile
> h_execfile(file, args, module=main, tracer=self)
>   File
> "C:\PROGRA~1\ACTIVE~1.5\lib\support\dbgp\pythonlib\dbgp\client.py",
> line 596, in __init__
> execfile(file, globals, locals)
>   File "C:\Program
> Files\Python243\Lib\site-packages\intersys\tobytest.py", line 1, in
> __main__
> import pythonbind1.pyd
> ImportError: DLL load failed: The specified module could not be found.
> 
> 
> Any suggestions?

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


Error importing .pyd python extension

2006-10-30 Thread Toby
Hi, I've managed to get my hands on the ms 2003 toolkit, and have
successfully (i think) created a .pyd file in win xp (setup.py is
provided intersystems cache):


C:\CacheSys\Dev\python>setup.py install
enter directory where you installed Cache'c:\CacheSys
libdir=c:\CacheSys\dev\cpp\lib
include dir=c:\CacheSys\dev\cpp\include
running install
running build
running build_py
running build_ext
running install_lib
creating C:\Program Files\Python243\Lib\site-packages\intersys
copying build\lib.win32-2.4\intersys\pythonbind.py -> C:\Program
Files\Python243
\Lib\site-packages\intersys
copying build\lib.win32-2.4\intersys\pythonbind1.pyd -> C:\Program
Files\Python2
43\Lib\site-packages\intersys
copying build\lib.win32-2.4\intersys\__init__.py -> C:\Program
Files\Python243\L
ib\site-packages\intersys
byte-compiling C:\Program
Files\Python243\Lib\site-packages\intersys\pythonbind.
py to pythonbind.pyc
byte-compiling C:\Program
Files\Python243\Lib\site-packages\intersys\__init__.py
 to __init__.pyc

C:\CacheSys\Dev\python>cd \program
files\python243\Lib\site-packages\intersys\

C:\Program Files\Python243\Lib\site-packages\intersys>dir
 Volume in drive C is SYSTEM
 Volume Serial Number is 3835-49DE

 Directory of C:\Program Files\Python243\Lib\site-packages\intersys

31/10/2006  10:47 AM  .
31/10/2006  10:47 AM  ..
19/10/2006  05:50 PM 1,598 pythonbind.py
31/10/2006  10:47 AM 1,961 pythonbind.pyc
31/10/2006  09:44 AM69,632 pythonbind1.pyd
17/07/2006  05:34 PM 2 __init__.py
31/10/2006  10:47 AM   145 __init__.pyc
   5 File(s) 73,338 bytes
   2 Dir(s)  16,709,017,600 bytes free


However, when I try to import pythonbind1.pyd I get the following
error:

Traceback (most recent call last):
  File
"C:\PROGRA~1\ACTIVE~1.5\lib\support\dbgp\pythonlib\dbgp\client.py",
line 1843, in runMain
self.dbg.runfile(debug_args[0], debug_args)
  File
"C:\PROGRA~1\ACTIVE~1.5\lib\support\dbgp\pythonlib\dbgp\client.py",
line 1538, in runfile
h_execfile(file, args, module=main, tracer=self)
  File
"C:\PROGRA~1\ACTIVE~1.5\lib\support\dbgp\pythonlib\dbgp\client.py",
line 596, in __init__
execfile(file, globals, locals)
  File "C:\Program
Files\Python243\Lib\site-packages\intersys\tobytest.py", line 1, in
__main__
import pythonbind1.pyd
ImportError: DLL load failed: The specified module could not be found.


Any suggestions?

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


Re: PEP 354: Enumerations in Python

2006-02-28 Thread Toby Dickenson
On Monday 27 February 2006 02:49, Ben Finney wrote:

> Coercing a value from an enumeration to a ``str`` results in the
> string that was specified for that value when constructing the
> enumeration::

That sentence seems to assume that all enumeration values will have been 
specified as strings. Thats reasonable, but your description of the creation 
of an enumeration doesnt specify that.

> An enumerated type is created from a sequence of arguments to the
> type's constructor::
> 
> >>> Weekdays = enum('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat')
> >>> Grades = enum('A', 'B', 'C', 'D', 'F')

s/arguments/strings/

?

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


Re: Using graphviz to visualize trace.py output, anybody?

2005-11-01 Thread Toby Dickenson
> Maybe there is some other tool that I am not aware of which can create
> this kind of trace. I use eclipse with pydev plugin on MacOS 10.3.9

kcachegrind

http://kcachegrind.sourceforge.net/cgi-bin/show.cgi

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


Re: Sorting with only a partial order definition

2005-10-27 Thread Toby Dickenson
On Thursday 27 October 2005 11:08, Lasse Vågsæther Karlsen wrote:

> What I was wondering about is if there is an algorithm that would do 
> what I want? Ie. help me pick the nodes so as to minimize the number of 
> edges. 

To rephrase your question, you want a sorting algorithm that minimises the 
number of comparisons (because a comparison involves asking a human), and 
which takes advantage of any pre-existing rough ordering.

You need timsort - the algorithm behind python lists sort() method.

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


Re: Would there be support for a more general cmp/__cmp__

2005-10-20 Thread Toby Dickenson
On Thursday 20 October 2005 11:53, Steve Holden wrote:

> Personally I'm still not convinced that your requirement reflects a 
> substantial use case (but then I'm getting used to that ;-). Just 
> because an ordering is partial that doesn't mean that two instances of a 
> class shouldn't be compared.

C++ has a cmp template function which can be implemented to define a total 
ordering for one type. This can be reliably used by implementations of 
ordered tree containers (for example) so that this container template class 
can only be instantiated for holding types that provide this comparison 
template function.

One disadvantage is that these template container classes can only hold one 
type.

ZODB's BTrees work in a similar way but use the regular python comparison 
function, and the lack of a guarantee of a total ordering can be a liability.
Described here in 2002, but I think same is true today:
http://mail.zope.org/pipermail/zodb-dev/2002-February/002304.html

A BTree might contain two objects that are incomparable. That is, they raise 
an exception when compared. However the user will not know this if by 
coincidence the BTree implementation has never needed to compare these two 
objects.

Now removing a third object from the container such that these two 
incomparable objects are adjacent in the BTree. There is a possibility that 
an exception might be raised when *reading* content from the BTree, since the 
BTree implementation now might need to compare this pair of objects.

> What would you have Python do when the programmer tries to perform an 
> invalid comparison (i.e. what are the exact semantics imposed when 
> __cmp__() returns None/raises an exception)?

Its too late to handle this by the time a specific comparison method of an 
individual object is being called. If you need a total ordering across a 
domain of objects then you need to involve some representation of that domain 
as a whole. 


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


Re: Limited XML tidy

2005-08-26 Thread Toby White
[EMAIL PROTECTED] writes:

>> The problem is that when the sax handler raises an exception,
> I can't see how to find out why. What I want to do is for
> DodgyErrorHandler to do something different depending on
> where we are in the course of parsing. Is there anyway
> to get that information back from xml.sax (or indeed from
> any other sax handler?)
>
> You can get raw location information, yes.  See:
>
> http://www.xml.com/pub/a/2004/11/24/py-xml.html
>
> But I don't think this is enough for you.  You also need recovery,
> which you're implementing in crude form.

(If you're referring to the Locator objects), yes I'm aware
that's possible. But what I want is not my location in the 
document, but for the parser to say "this is an error because
I am in the middle of a tag & the document ended", or "I
was in the middle of a text section and the document ended", or
"I was in the middle of an attribute value and the document
ended", etc, so that I can then construct a simple end to the
document, inserting quote marks, finishing the tag, and closing 
all unclosed tags as appropriate.

I have just realised that I might be able to grab the message
that the exception gives me, look at the expat source code 
and work out what parsing events cause which error messages.
Which is a bit round the houses, but I think ought to work.


> I tend to agree with Magnus that using an SGML parser might be your
> best bet.  You might even be able to turn that SGML into XML using a
> tool such as James Clark's SX:
>
> http://www.jclark.com/sp/sx.htm

If I can't get my scheme above to work, I'll have a go. But I was
hoping to do this without requiring additional packages. And in
any case, it doesn't need to be perfectly robust. As long as it
handles 99% of cases, I'll be happy.

-- 
Dr. Toby White 
Dept. of Earth Sciences, Downing Street, Cambridge CB2 3EQ. UK
Email: <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Limited XML tidy

2005-08-23 Thread Toby White

I have a program which produces well-formed XML documents,
but takes several hours if not days to do so. It would
be useful to be able to take the incomplete output and
manipulate it as XML.

Clearly, however, the incomplete output will not be well-
formed, so before being able to manipulate it I need to 
make it wellformed.

This is essentially fairly simple. I know it's well-formed
up to now - all I need to do is close unclosed tags. So,
I 've made a short function that will do this:

#!/usr/bin/python

import sys
import xml.sax

tagStack = []

closingTags = ""

class DodgyHandler(xml.sax.ContentHandler):
def startElement(self, tag, attributes):
tagStack.append(tag)

def endElement(self, tag):
tagStack.pop()


class DodgyErrorHandler(xml.sax.ErrorHandler):
def fatalError(self,exception):
global closingTags
tagStack.reverse()
for tag in tagStack:
closingTags += "" % tag
return closingTags


def finishXML(text):
p = xml.sax.make_parser()
p.setContentHandler(DodgyHandler())
p.setErrorHandler(DodgyErrorHandler())

for line in text:
   p.feed(line)
p.close()

text.append(closingTags)


However - while this works for 90% of the cases I need,
it fails in the case where my incomplete output stops in the
middle of a tag (not to mention some other more arcane 
places I don't really care about).

The problem is that when the sax handler raises an exception,
I can't see how to find out why. What I want to do is for
DodgyErrorHandler to do something different depending on 
where we are in the course of parsing. Is there anyway
to get that information back from xml.sax (or indeed from
any other sax handler?)

Toby

-- 
Dr. Toby White 
Dept. of Earth Sciences, Downing Street, Cambridge CB2 3EQ. UK
Email: <[EMAIL PROTECTED]>

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


Limited XML tidy

2005-08-23 Thread Toby White

I have a program which produces well-formed XML documents,
but takes several hours if not days to do so. It would
be useful to be able to take the incomplete output and
manipulate it as XML.

Clearly, however, the incomplete output will not be well-
formed, so before being able to manipulate it I need to 
make it wellformed.

This is essentially fairly simple. I know it's well-formed
up to now - all I need to do is close unclosed tags. So,
I 've made a short function that will do this:

#!/usr/bin/python

import sys
import xml.sax

tagStack = []
closingTags = ""

class DodgyHandler(xml.sax.ContentHandler):
def startElement(self, tag, attributes):
tagStack.append(tag)

def endElement(self, tag):
tagStack.pop()


class DodgyErrorHandler(xml.sax.ErrorHandler):
def fatalError(self,exception):
global closingTags
tagStack.reverse()
for tag in tagStack:
closingTags += "" % tag
return closingTags

filename = sys.argv[1]

p = xml.sax.make_parser()
p.setContentHandler(DodgyHandler())
p.setErrorHandler(DodgyErrorHandler())

f = open(filename, mode='r')

for line in f:
print line,
p.feed(line)
p.close()

print closingTags

However - while this works for 90% of the cases I need,
it fails in the case where my incomplete output stops in the
middle of a tag (not to mention some other more arcane 
places I don't really care about).

The problem is that when the sax handler raises an exception,
I can't see how to find out why. What I want to do is for
DodgyErrorHandler to do something different depending on 
where we are in the course of parsing. Is there anyway
to get that information back from xml.sax (or indeed from
any other sax handler?)

Toby

-- 
Dr. Toby White 
Dept. of Earth Sciences, Downing Street, Cambridge CB2 3EQ. UK
Email: <[EMAIL PROTECTED]>

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


Re: [path-PEP] Path inherits from basestring again

2005-07-26 Thread Toby Dickenson
On Wednesday 27 July 2005 05:37, Meyer, Tony wrote:

> I can see that this would make sense in some situations, but ISTM that it
> would make a great deal more sense (and be much more intuitive) to have
> concatenation include the separator character (i.e. be join).  

def functions_which_modifies_some_file_in_place(path):
 output = open(path+'.tmp', 'w')
 .

I dont want a seperator inserted between path and the new extension.


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



Re: System Independent Wallpaper Changer

2005-07-06 Thread Toby Dickenson
On Wednesday 06 July 2005 01:12, Terrance N. Phillip wrote:

> I've done some searching, and can't seem to find a programatic way of 
> getting *** that to happen.

http://www.google.com/search?q=setwallpaper+dcop

I hope this helps

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


Re: asynchronous comunication, wxPython and threads.

2005-06-21 Thread Toby Dickenson
On Tuesday 21 June 2005 14:22, Zunbeltz Izaola wrote:

> This comunication is done in a new thread not to frezee the GUI.
> The problem is that when "Stop" is done (it kills the thread) some
> confirmation sockets are mixed (are not receibed in the correct order
> although i use tcp).

I guess you are accessing the socket from both your GUI thread and 
communications thread. Dont do that. An action in the GUI thread should 
signal the communictions thread, then the communictions thread talks to the 
socket.

> I have been told not to do comunication in a new thread; instead, I should
> use asyncronus comunication.

Using non-blocking sockets in the GUI thread may cause the opposite problem to 
the one that led you to use threads in the first place: a blocking operation 
in the GUI may freeze the communications. Maybe that isnt a problem for you. 
If it is, I suggest sticking to two threads.

> What module should i use, asyncore, asynchat, twisted,(anohter) 

If you are talking to only one device, then using blocking sockets is a good 
approach. However Ive never written an application like this that didnt need 
to support a second (or third) machine sooner or later, and three 
communictions threads is starting to get ugly. A framework like Twisted will 
let you handle many machines in the one thread, but it still makes sense to 
keep a second one for the GUI.


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


Re: collect data using threads

2005-06-14 Thread Toby Dickenson
On Tuesday 14 June 2005 17:47, Peter Hansen wrote:
> Kent Johnson wrote:
> > Peter Hansen wrote:
> >> That will not work, and you will get data loss, as Jeremy points out.
> >>
> > Can you explain why not? self.data is still bound to the same list as x. 
> > At least if the execution sequence is x = self.data
> >self.data.append(a_piece_of_data)
> > self.data = []
> 
> Ah, since the entire list is being returned, you appear to be correct. 
> Interesting... this means the OP's code is actually appending things to 
> a list, over and over (presumably), then returning a reference to that 
> list and rebinding the internal variable to a new list.  If another 
> thread calls on_received() and causes new data to be appended to "the 
> list" between those two statements, then it will show up in the returned 
> list (rather magically, at least to my way of looking at it) and will 
> not in fact be lost.

But it might not "show up" until too late.

The consumer thread that called get_data presumably does something with that 
list, such as iterating over its contents. It might only "show up" after that 
iteration has finished, when the consumer has discarded its reference to the 
shared list.

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


Re: Python Impact Analysis Tool ?

2005-05-26 Thread Toby Dickenson
On Thursday 26 May 2005 13:46, [EMAIL PROTECTED] wrote:
> Hi
> 
> I am a mainframe designer/progrmmer. What I need is a tool that shows
> me at design time what links to what so that I can understand the
> application. When a design change comes through I could say OK this
> change affects only A, B, and C out of the whole alphanet. Then I would
> be able to isolate what needs to be changed and unit tested..I am
> trying to improve programmer productivity at design time.

For physical dependencies between modules:

http://www.tarind.com/depgraph.html

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


Re: Windows distribution suggestions?

2005-05-17 Thread Toby Dickenson
On Tuesday 17 May 2005 09:35, Timothy Smith wrote:
> mate dont bugger around with all that. py2exe will make you a windows 
> native exe to run. and for updates you just need to update it's 
> library.zip.

py2exe is working great for me too. 

>> My app contains three different programs (say alice.py, bob.py, and
>> carol.py) that need to be independently launchable, and a dozen or
>> so other .py files that get imported into those first three

One tip: make sure your three top-level scripts are as empty as possible: just 
import some other module and call a function. All your active code is then in 
some library.zip shared between the three, and you need never change 
alice.exe, bob.exe, and carol.exe

> use NSIS for the installer, it can do anything you want an  
> it's free. it couldn't be more simple, shoot me an email if you
> need more 

Ive not used NSIS, but I have had good results from the free WiX tools, at 
http://sourceforge.net/projects/wix/. Documentation is poor, but examples are 
plenty.

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


Re: Distributing applications

2005-03-02 Thread Toby Dickenson
On Wednesday 02 March 2005 14:12, Phillip Mills wrote:
> now any comments or references on the mechanics of creating 
> a self-contained distribution?

Run to http://starship.python.net/crew/theller/py2exe/


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


Re: Flow chart (function tree) & cross references

2005-02-22 Thread Toby Dickenson
On Tuesday 22 February 2005 13:27, qwweeeit wrote:

> Does someone knows something about function tree generation and cross
> references?

for trees of *module* dependencies:
http://www.tarind.com/depgraph.html

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


Re: python connect to server using SSH protocol

2005-02-09 Thread Toby Dickenson
On Tuesday 08 February 2005 13:26, Simon Anders wrote:

> This is what I was about to reply as well. But I did a short test 
> program and encountered a problem:
> 
> import os
> fi, foe = os.popen4 ('ssh dopey')
> print >>fi, 'ls'
> fi.close ()  # <-- this is annoying
> for line in foe:
> print line,
> foe.close ()
> 
> The above connects to a server, passes the command 'ls', which is 
> executed there, and prints the returned result.
> 
> However, reading from foe succeeds only if fin has been closed before. 
> An fi.flush() seems to be not sufficient. 

But this version below does work. Im not sure whats happening when using the 
file as an iterator to make a difference.

import os, sys
fi, foe = os.popen4 ('ssh x')
print >>fi, 'ls'
fi.flush ()  # <-- this is annoying
while 1:
b = foe.readline()
sys.stdout.write(b)


> But if one wants Python to  
> interactivly communicate with some shell on a remote machine, it is 
> inconvenient to have to close and reopen the connection all the time.

But this route carries a big deadlock risk. the rsync program can tunnel over 
ssh this way, but have first hand experience of
http://www.google.com/search?q=rsync+ssh+deadlock

In the script above, if 'ls' is replaced with a longer input then there is 
every chance that the fi stream will block before all of it is written, 
because this script hasnt started draining foe.

For a real python program using ssh (but not 'interactive'... data written to 
fi does not depend on data read from foe) see
http://dirstorage.sourceforge.net/replica.html
-- 
Toby Dickenson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "private" variables a.k.a. name mangling (WAS: What is print? A function?)

2005-01-25 Thread Toby Dickenson
On Tuesday 25 January 2005 12:40, Richie Hindle wrote:
> 
> [Steven]
> > Can someone give me an example of where __-mangling really solved a 
problem 
> > for them, where a simple leading underscore wouldn't have solved the 
> > same problem?
> 
> 
http://cvs.sourceforge.net/viewcvs.py/spambayes/spambayes/spambayes/Dibbler.py?r1=1.13&r2=1.13.4.1
> 
> That's a bugfix to SpamBayes, where I'd inadvertently named an instance
> variable '_map' without realising that the base class
> (asynchat.async_chat) also had an instance variable of that name.  Using
> double underscores fixed it, and had I used them from the beginning the
> bug would never have cropped up (even if asynchat.async_chat had an
> instance variable named '__map', which is the whole point (which you know,
> Steven, but others might not)).

I have a counterexample. Consider refactoring a class from

class B(A):
etc

into

class C(A):
etc
class B(C):
etc

Usage of some double-undescore attributes moved from B to the new intermediate 
base class C. Unit tests on B still passed, so that change is safe. right?

The problem occured because the double-underscore mangling uses the class 
name, but ignores module names. A related project already had a class named C 
derived from B  (same name - different module). My refactoring caused 
aliasing of some originally distinct double-underscore attributes.

-- 
Toby Dickenson



Important Notice:

This email and any attachments are confidential and may contain trade secrets 
or be legally privileged. If you have received this email in error you must not 
use, rely upon, disclose, copy or distribute the contents. Please reply to the 
sender so that proper delivery can be arranged and delete the email from your 
computer.
Gemini Data Loggers monitor incoming and outgoing email to ensure satisfactory 
customer service, maintain company security and prevent abuse of their email 
system. However, any views expressed in this email are not necessarily those of 
Gemini and Gemini cannot be held responsible for the content.
Gemini makes best efforts to ensure emails are virus free; however you are 
advised to carry out your own checks. Gemini does not accept responsibility for 
any damage resulting from email viruses.


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