Re: unicode issue

2009-10-01 Thread Hyuga
On Sep 30, 3:34 am, gentlestone tibor.b...@hotmail.com wrote:
 Why don't work this code on Python 2.6? Or how can I do this job?

 _MAP = {
     # LATIN
     u'À': 'A', u'Á': 'A', u'Â': 'A', u'Ã': 'A', u'Ä': 'A', u'Å': 'A',
 u'Æ': 'AE', u'Ç':'C',
     u'È': 'E', u'É': 'E', u'Ê': 'E', u'Ë': 'E', u'Ì': 'I', u'Í': 'I',
 u'Î': 'I',
     u'Ï': 'I', u'Ð': 'D', u'Ñ': 'N', u'Ò': 'O', u'Ó': 'O', u'Ô': 'O',
 u'Õ': 'O', u'Ö':'O',
     u'Ő': 'O', u'Ø': 'O', u'Ù': 'U', u'Ú': 'U', u'Û': 'U', u'Ü': 'U',
 u'Ű': 'U',
     u'Ý': 'Y', u'Þ': 'TH', u'ß': 'ss', u'à':'a', u'á':'a', u'â': 'a',
 u'ã': 'a', u'ä':'a',
     u'å': 'a', u'æ': 'ae', u'ç': 'c', u'è': 'e', u'é': 'e', u'ê': 'e',
 u'ë': 'e',
     u'ì': 'i', u'í': 'i', u'î': 'i', u'ï': 'i', u'ð': 'd', u'ñ': 'n',
 u'ò': 'o', u'ó':'o',
     u'ô': 'o', u'õ': 'o', u'ö': 'o', u'ő': 'o', u'ø': 'o', u'ù': 'u',
 u'ú': 'u',
     u'û': 'u', u'ü': 'u', u'ű': 'u', u'ý': 'y', u'þ': 'th', u'ÿ': 'y',
     # LATIN_SYMBOLS
     u'©':'(c)',
     # GREEK
     u'α':'a', u'β':'b', u'γ':'g', u'δ':'d', u'ε':'e', u'ζ':'z',
 u'η':'h', u'θ':'8',
     u'ι':'i', u'κ':'k', u'λ':'l', u'μ':'m', u'ν':'n', u'ξ':'3',
 u'ο':'o', u'π':'p',
     u'ρ':'r', u'σ':'s', u'τ':'t', u'υ':'y', u'φ':'f', u'χ':'x',
 u'ψ':'ps', u'ω':'w',
     u'ά':'a', u'έ':'e', u'ί':'i', u'ό':'o', u'ύ':'y', u'ή':'h',
 u'ώ':'w', u'ς':'s',
     u'ϊ':'i', u'ΰ':'y', u'ϋ':'y', u'ΐ':'i',
     u'Α':'A', u'Β':'B', u'Γ':'G', u'Δ':'D', u'Ε':'E', u'Ζ':'Z',
 u'Η':'H', u'Θ':'8',
     u'Ι':'I', u'Κ':'K', u'Λ':'L', u'Μ':'M', u'Ν':'N', u'Ξ':'3',
 u'Ο':'O', u'Π':'P',
     u'Ρ':'R', u'Σ':'S', u'Τ':'T', u'Υ':'Y', u'Φ':'F', u'Χ':'X',
 u'Ψ':'PS', u'Ω':'W',
     u'Ά':'A', u'Έ':'E', u'Ί':'I', u'Ό':'O', u'Ύ':'Y', u'Ή':'H',
 u'Ώ':'W', u'Ϊ':'I', u'Ϋ':'Y',
     # TURKISH
     u'ş':'s', u'Ş':'S', u'ı':'i', u'İ':'I', u'ç':'c', u'Ç':'C',
 u'ü':'u', u'Ü':'U',
     u'ö':'o', u'Ö':'O', u'ğ':'g', u'Ğ':'G',
     # RUSSIAN
     u'а':'a', u'б':'b', u'в':'v', u'г':'g', u'д':'d', u'е':'e',
 u'ё':'yo', u'ж':'zh',
     u'з':'z', u'и':'i', u'й':'j', u'к':'k', u'л':'l', u'м':'m',
 u'н':'n', u'о':'o',
     u'п':'p', u'р':'r', u'с':'s', u'т':'t', u'у':'u', u'ф':'f',
 u'х':'h', u'ц':'c',
     u'ч':'ch', u'ш':'sh', u'щ':'sh', u'ъ':'', u'ы':'y', u'ь':'',
 u'э':'e', u'ю':'yu', u'я':'ya',
     u'А':'A', u'Б':'B', u'В':'V', u'Г':'G', u'Д':'D', u'Е':'E',
 u'Ё':'Yo', u'Ж':'Zh',
     u'З':'Z', u'И':'I', u'Й':'J', u'К':'K', u'Л':'L', u'М':'M',
 u'Н':'N', u'О':'O',
     u'П':'P', u'Р':'R', u'С':'S', u'Т':'T', u'У':'U', u'Ф':'F',
 u'Х':'H', u'Ц':'C',
     u'Ч':'Ch', u'Ш':'Sh', u'Щ':'Sh', u'Ъ':'', u'Ы':'Y', u'Ь':'',
 u'Э':'E', u'Ю':'Yu', u'Я':'Ya',
     # UKRAINIAN
     u'Є':'Ye', u'І':'I', u'Ї':'Yi', u'Ґ':'G', u'є':'ye', u'і':'i',
 u'ї':'yi', u'ґ':'g',
     # CZECH
     u'č':'c', u'ď':'d', u'ě':'e', u'ň':'n', u'ř':'r', u'š':'s',
 u'ť':'t', u'ů':'u',
     u'ž':'z', u'Č':'C', u'Ď':'D', u'Ě':'E', u'Ň':'N', u'Ř':'R',
 u'Š':'S', u'Ť':'T', u'Ů':'U', u'Ž':'Z',
     # POLISH
     u'ą':'a', u'ć':'c', u'ę':'e', u'ł':'l', u'ń':'n', u'ó':'o',
 u'ś':'s', u'ź':'z',
     u'ż':'z', u'Ą':'A', u'Ć':'C', u'Ę':'e', u'Ł':'L', u'Ń':'N',
 u'Ó':'o', u'Ś':'S',
     u'Ź':'Z', u'Ż':'Z',
     # LATVIAN
     u'ā':'a', u'č':'c', u'ē':'e', u'ģ':'g', u'ī':'i', u'ķ':'k',
 u'ļ':'l', u'ņ':'n',
     u'š':'s', u'ū':'u', u'ž':'z', u'Ā':'A', u'Č':'C', u'Ē':'E',
 u'Ģ':'G', u'Ī':'i',
     u'Ķ':'k', u'Ļ':'L', u'Ņ':'N', u'Š':'S', u'Ū':'u', u'Ž':'Z'

 }

 def downcode(name):
     
      downcode(uŽabovitá zmiešaná kaša)
     u'Zabovita zmiesana kasa'
     
     for key, value in _MAP.iteritems():
         name = name.replace(key, value)
     return name

Though C Python is pretty optimized under the hood for this sort of
single-character replacement, this still seems pretty inefficient
since you're calling replace for every character you want to map.  I
think that a better approach might be something like:

def downcode(name):
return ''.join(_MAP.get(c, c) for c in name)

Or using string.translate:

import string
def downcode(name):
table = string.maketrans(
'ÀÁÂÃÄÅ...',
'AA...')
return name.translate(table)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OK to memoize re objects?

2009-09-22 Thread Hyuga
On Sep 21, 11:02 am, Nobody nob...@nowhere.com wrote:
 On Mon, 21 Sep 2009 07:11:36 -0700, Ethan Furman wrote:
  Looking in the code for re in 2.5:
  _MAXCACHE = 100
  On the other hand, I (a
  re novice, to be sure) have only used between two to five in any one
  program... it'll be a while before I hit _MAXCACHE!

 Do you know how many REs import-ed modules are using? The cache isn't
 reserved for __main__.

Based on this, I'd say that the best policy would be that if you only
have a handful of simple REs that are used only on occasion, it's
probably not worth using re.compile--even if they fall out of cache,
it shouldn't take a noticeable amount of time to recompile them.

If, however, these are either complex REs, or REs that are being used
very frequently, say in a loop, might as well save the compiled RE
somewhere just to be sure it doesn't have to be recompiled at any
point.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-22 Thread Hyuga
On Sep 22, 9:57 am, Grant Edwards inva...@invalid.invalid wrote:
 On 2009-09-22, Mel mwil...@the-wire.com wrote:

  Tim Roberts wrote:

  daggerdvm dagger...@yahoo.com wrote:

 carl banks.you are a dork

  What are you, eleven years old?

  Look, you asked us to answer for you what is CLEARLY a homework question.
  It is unethical for you to ask that, and it is unethical for us to answer
  it.

  Forget ethical.  We can do his homework for him, we can perhaps pass exams
  for him, maybe graduate for him, and then with our luck, he'll get a job in
  our office and we get to do his work for him.

 No, no, no.  The plan is to do his homework for him so that
 he's incompetent when he graduates and won't be competition for
 the rest of us who did do our homework.

Well, while they may not be as much competition come promotion time, I
think Mr. Finney had it right that these people *do* still somehow get
hired, and then the rest of us end up having to do enough work for
multiple people.  Sometimes spending more time redoing other peoples'
shoddy work than it would have taken to do ourselves in the first
place.  Annoying for the programmer, but really bad for business.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An assessment of the Unicode standard

2009-09-15 Thread Hyuga
On Sep 14, 5:05 am, Christopher Culver
crcul...@christopherculver.com wrote:
 Hyuga hyugaricd...@gmail.com writes:
  I just wanted to add, in defense of the Chinese written language
  ... that I think it would make a fairly good candidate for use at
  least as a universal *written* language.  Particularly simplified
  Chinese since, well, it's simpler.

  The advantages are that the grammar is relatively simple, and it can
  be used to illustrate concepts independently of the writer's spoken
  language.

 Musings about the universality of the Chinese writing system, once so
 common among Western thinkers, nevertheless do not square with
 reality. The Chinese writing system is in fact deeply linked to the
 Chinese language, even to the specific dialect being spoken. See
 Defrancis' _The Chinese Language: Fact and Fantasy_ (Honolulu:
 University of Hawaii Press, 1984):

 http://preview.tinyurl.com/rbyuuk

Oh, certainly! I thought I said as much in my original post, but maybe
I didn't stress that enough.  I'm a lot stronger in Japanese than I am
in Chinese, but even Japanese uses various Chinese characters in ways
that have deep cultural ties that may not translate well (and in many
cases that are completely different from those characters'
implications in any Chinese language).  I guess the reason I didn't
stress that enough is that I'm in no way implying that they be used as
is.  I just think they could be taken as the basis for a standardized
universal written language. One might argue that it would make more
sense to come up with a new character set for that, but here we have
one that so many people are already familiar with in some form or
another.  And the radical system makes them much easier to remember
than many people realize.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An assessment of the Unicode standard

2009-09-01 Thread Hyuga
On Aug 29, 8:20 pm, John Machin sjmac...@lexicon.net wrote:
 On Aug 30, 8:46 am, r rt8...@gmail.com wrote:



  Take for instance the Chinese language with it's thousands of
  characters and BS, it's more of an art than a language.  Why do we
  need such complicated languages in this day and time. Many languages
  have been perfected, (although not perfect) far beyond that of Chinese
  language.

 The Chinese language is more widely spoken than English, is quite
 capable of expression in ASCII (r tongzhi shi sha gua) and doesn't
 have those pesky it's/its problems.

  The A-Z char set is flawless!

 ... for expressing the sounds of a very limited number of languages,
 and English is *NOT* one of those.

I'd say don't feel the troll, but too late for that I guess.  I just
wanted to add, in defense of the Chinese written language (in case
this hasn't already been added--I'm probably not going to bother
reading this entire thread) that I think it would make a fairly good
candidate for use at least as a universal *written* language.
Particularly simplified Chinese since, well, it's simpler.

The advantages are that the grammar is relatively simple, and it can
be used to illustrate concepts independently of the writer's spoken
language.  Sure it's tied somewhat to the Chinese language, but it can
certainly be mapped more easily to any other language than
phonetically-based written language.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: are user defined classes hashable?

2009-07-21 Thread Hyuga
On Jul 20, 10:53 pm, a...@pythoncraft.com (Aahz) wrote:
 In article 373d6c69-6965-4a88-bdd2-8028ef850...@k6g2000yqn.googlegroups.com,

 Hyuga  hyugaricd...@gmail.com wrote:

 Regardless, Nicolas's example can be applied to the class too:

  class Foo(object):
     pass

  hash(Foo)
 11443104
  id(Foo)
 11443104

 class objects are just objects of type 'type'.

 Not quite.  They certainly default that way, but changing the metaclass
 changes a class's type::

 class M(type):
     pass

 class C(object):
     pass

 class C2(object):
     __metaclass__ = M

 print type(C)
 print type(C2)

Well, okay, you got me there.  But the OP wasn't asking about classes
with different metaclasses.  And besides, type(type(C2)) is still
type ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: are user defined classes hashable?

2009-07-20 Thread Hyuga
On Jul 19, 11:39 am, Nicolas Dandrimont nicolas.dandrim...@crans.org
wrote:
 * Alan G Isaac alan.is...@gmail.com [2009-07-19 14:46:12 +]:

  Again, my question is about the class not its instances,
  but still, checking as you suggest gives the same answer.

 That's what I get for answering before my coffee!

Regardless, Nicolas's example can be applied to the class too:

 class Foo(object):
pass

 hash(Foo)
11443104
 id(Foo)
11443104

class objects are just objects of type 'type'.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Perl's @foo[3,7,1,-1] ?

2009-06-18 Thread Hyuga
On Jun 13, 6:22 pm, Brian Quinlan br...@sweetapp.com wrote:
 MRAB wrote:
  Brian Quinlan wrote:
  kj wrote:
  In slrnh37t2p.63e.n...@irishsea.home.craig-wood.com Nick Craig-Wood
  n...@craig-wood.com writes:

  However I can't think of the last time I wanted to do this - array
  elements having individual purposes are usually a sign that you should
  be using a different data structure.

  In the case I was working with, was a stand-in for the value returned
  by some_match.groups().  The match comes from a standard regexp
  defined elsewhere and that captures more groups than I need.  (This
  regexp is applied to every line of a log file.)

  kj

  The common idiom for this sort of thing is:

  _, _, _, val1, _, _, _, val2, ..., val3 = some_match.groups()

  Alternatively:

      val1, val2, val3 = some_match.group(4, 8, something)

 Actually, now that I think about it, naming the groups seems like it
 would make this code a lot less brittle.

I was about to suggest that too, but it sounds like the OP has little
or no control, in this case, over the RE itself.  Another thing I
would suggest is using the (?:) syntax--it allows creating a syntactic
group that isn't returned in the list of match groups.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: matplotlib - overlaying plots.

2009-05-14 Thread Hyuga
On May 14, 7:41 am, Ant ant...@gmail.com wrote:
 Hi All,

 I am trying to get matplotlib to overlay a couple of graphs, but am
 getting nowhere. I originally thought that the following may work:

  x = [1,2,3,4,5]
  y = [2,4,6,8,10]
  y2 = [1,4,9,16,25]
  plot(x, y)
  plot(x, y2)

 Now this works as desired, however, the actual case I have is more
 like this:

  x = [1,2,3,4,5]
  y = [2,4,6,8,10]
  y2 = [.0001, .0002, .0003, .0004, .0005]

 Now the graph is useless, since the results are plotted on the same
 axis. What I really want is two different sets of axes, each scaled
 appropriately, but overlayed.

 The data I actually have, is one set of axes plotting distance against
 elevation, and a second plotting distance against speed. The former
 has (y-coord) units in the range 0-2000 ft and the latter 0 - 0.01
 miles/second. I want them on the same graph, so points can be easily
 correlated, but overlayed so that each line has a different scale on
 the y-axis. The closest I can get is to have two subplots, one above
 the other.

 Thanks in advance,

 Ant.

Just scale up the y-axis values of your second graph 200,000 times,
and specify in label that the y-axis for the second graph is velocity
scaled up 20x for comparison purposes.  Nothing wrong with that--
it's done all the time.

On the other hand, I just took a peek at the matplotlib example
gallery, which is very diverse, and it has an example that I think is
exactly what you're looking for: 
http://matplotlib.sourceforge.net/examples/api/two_scales.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need to start a new project , can python do all that ?

2009-04-17 Thread Hyuga
On Apr 15, 10:54 am, Deep_Feelings doctore...@gmail.com wrote:
 On Apr 15, 4:05 pm, Tim Rowe digi...@gmail.com wrote:



  2009/4/15 Deep_Feelings doctore...@gmail.com:

   I want to start programming a new program (electronic health care
   center) in python and before start learning python i wanna make sure
   that python does have all the features i need to accomplish this
   project so i wanna ask you does python able to support these
   features :

   1- cross platform (windows + linux)
   2- mysql database access
   3- 2D graphs (curves)
   4- support of international languages
   5- can access a scanner and input pictures from it.

   and possibly be able to import data from labratory machines (such as
   CBC machines) to automatically register patient investigations result
   into the system (not mandatory)

  What are the safety and security requirements? If you're handling
  patient investigation results then there are certainly security issues
  because of patient confidentiality, and there may be safety issues
  (could a software fault contribute to a patient receiving incorrect
  treatment, or failing to receive necessary treatment?)

  You almost certainly need to contact the appropriate regulatory
  authority to check whether they have any requirements for languages in
  such applications (and for specific development processes), or you
  could find yourself either with an application you can't use or a very
  big lawsuit and possibly jail if it goes wrong.


 thank you so much ,rest assured that the code will me tested very well
 (in real world situation) before using it.

I'm not too assured... What are the actual requirements for this
software?  Is this intended for real world use in health care?  I'm
not too comfortable with a single individual with apparently limited
experience in Python developing something like that.  Not that it's
any of my business...or for all I know it may be!  You might as well
have started this post I want to start programming a new program (air
traffic control system) in python and before start learning python...
--
http://mail.python.org/mailman/listinfo/python-list


Re: setup.py install and bdist_egg

2009-03-16 Thread Hyuga
On Mar 13, 4:41 pm, Jasiu jasi...@gmail.com wrote:
 Hey,

 I work at a company where I'm lucky enough to write web apps using
 Python and WSGI :). We develop more and more stuff in Python and it's
 becoming a mess of dependencies, so we thought we would create a
 guideline for developers that describes the whole process of deploying
 a Python app on a server. Since all of our servers run Debian, all of
 our software has to be installed as Debian packages - other
 departments that don't use Python (shame on them! :D) already follow
 this policy.

 Here is what we have figured so far:
 1) Write your code.
 2) Prepare setup.py, and put names of required eggs in there.
 3) Write a Debian wrapper that uses CDBS Python class, and put names
 of required Debian packages in there.
 4) Build Debian package.
 5) Done! Deploy on server and have fun :).

 This guideline already works pretty well for us, but I thought I could
 tweak it a little. I want to make the Debian package wrapper as thin
 as possible so that if we ever stop using Debian, we will still be
 able to deploy all of our software as eggs. This goal turned to be
 pretty challenging. I have a few questions.

Glad to see I'm not the only one with this sort of challenge.  Though
it sounds like you're already a step ahead of me in that you're
properly maintaining requirements/dependencies for your Python
packages.  When I build my Debian packages I make sure that *they*
have the correct dependencies.  But my setup.py files do not have all
their dependencies listed, so it's a pain to get everything set up
correctly when not doing it through the Debian package system.

 1) Debian has a debian/dirs file where you can list all the
 directories that the package should create, for example those in /var/
 log, /var/lib . I already figured out that I can use setup.py
 'install_data' keyword for that, even for empty directories. Then I
 can use 'setup.py install' command and things work great. But... How
 about eggs? I'd like my egg to somehow contain or create such
 directories. For example, I have a config file that I want to place
 in /etc directory. I can do that using 'setup.py install', but
 'setup.py bdist_egg' will just create an egg containing etc/
 directory. Can I do something about it? Also, why doesn't an egg
 contain empty dirs that I place in install_data?

My approach to this has been to use a postinst script to copy files
out of the eggs (or when I'm not installing as an egg, from /usr/
share) to the correct locations in /etc.  However, this doesn't work
so well if you're not using a Debian package.  But see below:

 2) What about file permissions? Can they be set by setup.py? My
 software runs as www-data user and so /var/log and /var/lib
 directories should have proper owner, group and permissions. I didn't
 figure out a way to change permissions using setup.py. In Debian I can
 use postinst script for that.

I'm also using a postinst script for configuring my system, but I want
to move away from that.  I already have a command-line tool for easily
administering certain aspects of the system.  So my plan is to
implement a deploy command that creates all the directories with the
correct permissions, generates the config files, and performs all the
configuration my postinst script currently does.  Then the postinst
script simply needs to call the deploy command.  That way I can take
advantage of debconf without being dependent on it.

 If anything sounds unclear, blame my bad english :).

Sounds perfectly clear to me!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Guidance on writing a top-like console

2009-03-16 Thread Hyuga
On Feb 27, 6:08 pm, ntwrkd ntw...@gmail.com wrote:
 I am interested in writing an application that functions like a Unix
 or Linux top in the way it displays data.
 It should be command-line based but dynamically refreshing.

 I'm not sure what I should take into account or how I might go about
 implementing this?
 Any suggestions are appreciated.

OT
Do by any chance play TF2?  I've seen someone with the username
'ntwrkd' before.  Not that it's necessarily an uncommon username, but
it was the first thing I thought of when I saw this post.
/OT
--
http://mail.python.org/mailman/listinfo/python-list


Re: Will multithreading make python less popular?

2009-02-17 Thread Hyuga
On Feb 16, 4:34 am, rushen...@gmail.com wrote:
 Hi everybody,
 I am an engineer. I am trying to improve my software development
 abilities. I have started programming with ruby. I like it very much
 but i want to add something more. According to my previous research i
 have designed a learning path for myself. It's like something below.
       1. Ruby (Mastering as much as possible)
       2. Python (Mastering as much as possible)
       3. Basic C++ or Basic Java
 And the story begins here. As i search on the net,  I have found that
 because of the natural characteristics of python such as GIL, we are
 not able to write multi threaded programs. Oooops, in a kind of time
 with lots of cpu cores and we are not able to write multi threaded
 programs. That is out of fashion. How a such powerful language doesn't
 support multi threading. That is a big minus for python. But there is
 something interesting, something like multi processing. But is it a
 real alternative for multi threading. As i searched it is not, it
 requires heavy hardware requirements (lots of memory, lots of cpu
 power). Also it is not easy to implement, too much extra code...

 After all of that, i start to think about omiting python from my
 carrier path and directly choosing c++ or java. But i know google or
 youtube uses python very much. How can they choose a language which
 will be killed by multi threading a time in near future. I like python
 and its syntax, its flexibility.

 What do you think about multi threading and its effect on python. Why
 does python have such a break and what is the fix. Is it worth to make
 investment of time and money to a language it can not take advantage
 of multi cores?

Though I'm sure this has already been shot to death, I would just add
that maybe the better question would be: Will Python make
multithreading less popular?  My answer would be something along the
lines of, that would be nice, but it just depends on how many people
adopt Python for their applications, realize they can't use threads to
take advantage of multiple CPUs, ask this same bloody question for the
thousandth time, and are told to use the multiprocessing module.
--
http://mail.python.org/mailman/listinfo/python-list


Re: I always wonder ...

2008-12-29 Thread Hyuga
On Dec 22, 1:51 pm, Grant Edwards inva...@invalid wrote:
 On 2008-12-22, s...@pobox.com s...@pobox.com wrote:

  ... shouldn't people who spend all their time trolling be
  doing something else: studying, working, writing patches which
  solve the problems they perceive to exist in the troll
  subject?

 I think you misunderstand the point of trolling.  The author of
 a troll post doesn't actually care about the problems (and
 may not even genuinely perceive them as problems).

  Is there some online troll game running where the players earn
  points for generating responses to their posts?

 Yup. It's called Usenet.

a.k.a. multi-player Emacs in deathmatch mode on nightmare
difficulty. ;)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3 __cmp__ semantic change?

2008-11-21 Thread Hyuga
On Nov 21, 4:09 am, Duncan Booth [EMAIL PROTECTED] wrote:
 Johannes Bauer [EMAIL PROTECTED] wrote:
  Seems it was removed on purpose - I'm sure there was a good reason for
  that, but may I ask why? Instead of the sleek __cmp__ function I had
  earlier, I now have code like:

  def __lt__(self, other):
       return self.__cmp__(other)  0

  def __le__(self, other):
       return self.__cmp__(other)  0

 I hope you actually have = here.



  def __gt__(self, other):
       return self.__cmp__(other)  0

  def __ge__(self, other):
       return self.__cmp__(other) = 0

  Does anyone know the reason why __cmp__ was discarded?

 I think it was because __cmp__ was the backward compatible fallback for
 the newer rich comparison methods and Python 3 cleans up a lot of stuff
 left in just for backward compatibility. In this case it is a cleanup
 too far as in most cases (i.e. those cases where you don't need the full
 complexity of the rich comparisons) __cmp__ is a much simpler solution.

 Seehttp://mail.python.org/pipermail/python-dev/2003-March/034073.html
 for Guido's original thoughts. Also, once upon a time pep-3000 referred
 to the removal of __cmp__ but I can't find it in any of the current
 peps. 
 Seehttp://mail.python.org/pipermail/python-checkins/2004-August/042959.html
 andhttp://mail.python.org/pipermail/python-checkins/2004-August/042972.html
 where the reference to removal of __cmp__ became Comparisons other than
 ``==`` and ``!=`` between disparate types will raise an exception unless
 explicitly supported by the type and the reference to Guido's email
 about removing __cmp__ was also removed.

Guido's primary argument for removing it seems to be that the code for
supporting both __cmp__ and the rich comparisons is hairy and that
it felt really satisfying to remove.  I don't think that's a good
enough argument.  It was hairy because there are a lot of cases to
check, but I wouldn't say it was crufty.  It made sense, and the way
it worked seemed logical enough.  I never ran into any problems with
it.  And by and far the most common case is to implement some total
ordering for a class.

Now, as has been pointed out, all you really need to define total
ordering, at least for sorting, is __eq__ and __lt__, which isn't too
bad.  But you still lose the ability to make any other sort of
comparison without implementing all the other comparison operators
too.

Perhaps the code could be made somewhat simpler like this:  If rich
comparisons are defined, use those and *only* those operators that are
defined, and don't try to fall back on __cmp__ otherwise.  If no rich
comparisons are defined, just look for __cmp__.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Hyuga
On Jul 30, 3:53 am, Russ P. [EMAIL PROTECTED] wrote:
 Fair enough. I have no dog in this particular fight. I just think it
 wouldn't hurt to add an isempty() or isnonempty() method to the
 list type, and let people use it if they wish, or continue using if
 x if that's what they prefer.

Go right on ahead.  You could implement it like this:

class superenhancedlist(list):
def isempty(self):
return not self

 a = superenhancedlist()
 a.isempty()
True
 a.append(1)
 a.isempty()
False

Amazingly useful!  Go ahead and use that in all your code.  Anyone
else who comes along and looks at it or tries to maintain it will
really love you for it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: regarding SWIG

2008-07-22 Thread Hyuga
On Jul 22, 5:34 am, Anish Chapagain [EMAIL PROTECTED] wrote:
 Hi..
 I'm new to SWIG and need to create Wrapper for C code,
 so, I have installed the SWIG already but doesnot know how to run it
 for generating Interface file...
 My C code is in message.c so what do i need to do the first
 step..uisng SWIG..i read the documentation but cannot grasp creating
 interface file.

 thank's anish

Not sure where you're having trouble. I can understand if there's a
language barrier, but I think that the introductory SWIG documentation
is pretty darn straightforward, even if you just look at the code, so
I don't think there's anything that could be said here that's any more
clear, as far as the basics are concerned.  You'd have to explain
exactly what it is you're stuck on.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Iterate creating variables?

2008-06-16 Thread Hyuga
On Jun 13, 11:34 am, Reedick, Andrew [EMAIL PROTECTED] wrote:
  -Original Message-
  From: [EMAIL PROTECTED] [mailto:python-
  [EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
  Sent: Friday, June 13, 2008 11:11 AM
  To: [EMAIL PROTECTED]
  Subject: Iterate creating variables?

  I have twenty-five checkboxes I need to create (don't ask):

  self.checkbox1 = ...
  self.checkbox2 = ...
  .
  .
  .
  self.checkbox25 = ...

  Right now, my code has 25 lines in it, one for each checkbox, since
  these are all variables.

  Is there a way to write a loop so that I can have fewer lines of code
  but still keep the variables?

  I've tried:

  for o in xrange(25):
  self.checkbox[o] = ...

  which didn't work, and

  for o in xrange(25):
  self.checkbox[''%d'%(o)] = ...

  which also didn't work.

  Both give the error message: Attribute error: Main.App has no
  attribute checkbox, which clearly indicates that I'm not keeping
  the variability aspect I want.

  Is there a way?

  I appreciate any and all answers!

 Either store the checkboxes in an array or hash/dictionary.  If that's
 not practical, then
 You can use strings to build the code and use eval to execute the string
 as code.  Ex:

 for i in range(10):
 code = %d + %d % (i, i)
 print eval(code)

Don't do this.  You want

for idx in range(10):
setattr(self, 'checkbox_%i' % idx)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Setting Focus

2008-06-13 Thread Hyuga
On Jun 12, 11:04 pm, Gandalf [EMAIL PROTECTED] wrote:
 You know these  application like ICQ or winamp which stay at the front
 of the desktop as long as the user doesn't minimize it. I wont to do
 the same with my application in python.
 I still didn't manage to make pywinauto to auto set my window frame in
 focus reliability so I was hoping this will solve my problem.

 I'm working with WX lib on 2.5 python on Microsoft Windows XP

 if any one {know / heard /think he know /thunk he heard/ sow once
 article that shows} how to do it  I will be happy to know

 thank you in advance

I'm not sure if there's a way to do this purely in wx, as it's sort of
a Windows-specific functionality as far as I know.  I know in win32
you can use SetWindowPos() and pass it HWND_TOP (see
http://msdn.microsoft.com/en-us/library/ms633545(VS.85).aspx).  So you
might have to use win32gui to use SetWindowPos().  You can use
wxWindow.getHandle() to get the HWND reference to pass as the first
argument to SetWindowPos.

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


Re: Setting Focus

2008-06-13 Thread Hyuga
On Jun 13, 9:34 am, Hyuga [EMAIL PROTECTED] wrote:
 On Jun 12, 11:04 pm, Gandalf [EMAIL PROTECTED] wrote:

  You know these  application like ICQ or winamp which stay at the front
  of the desktop as long as the user doesn't minimize it. I wont to do
  the same with my application in python.
  I still didn't manage to make pywinauto to auto set my window frame in
  focus reliability so I was hoping this will solve my problem.

  I'm working with WX lib on 2.5 python on Microsoft Windows XP


 I'm not sure if there's a way to do this purely in wx, as it's sort of
 a Windows-specific functionality as far as I know.  I know in win32
 you can use SetWindowPos() and pass it HWND_TOP 
 (seehttp://msdn.microsoft.com/en-us/library/ms633545(VS.85).aspx).  So you


Sorry, I meant you actually want HWND_TOPMOST as the second argument
to SetWindowPos().  That puts the window above all other windows and
keeps it there.

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


Re: Grabbing previous iteration in a dict

2008-05-09 Thread Hyuga
On May 9, 5:10 am, [EMAIL PROTECTED] wrote:
 I have a dictionary of which i'm itervalues'ing through, and i'll be
 performing some logic on a particular iteration when a condition is
 met with trusty .startswith('foo').  I need to grab the previous
 iteration if this condition is met.  I can do something with an extra
 var to hold every iteration while iterating, but this is hacky and not
 elegant.

Why is that so terrible?
previous = None
for key in mydict:
if key.starswith('foo') and previous is not None:
# ...do stuff...
previous = key

Doesn't seem too ugly to me.

 Is there a mechanism whereby I can just index the dict value
 subscripts like in an array? I could just rewind by 1 if so.

You can't rely on the keys in a dictionary being in any specific
order.  But if you want a list of the keys you can just call
mydict.keys() which will give a copy of the dictionary's keys in a
list.  Then you can iterate that and use it however you would use any
other list.  Note that it's a copy though.  It might help if you
better explained exactly what you need to do.
--
http://mail.python.org/mailman/listinfo/python-list


Re: first time use of swig, python and c++ .. it's a mess ... please advice

2008-02-27 Thread Hyuga
On Feb 26, 3:38 pm, Eric von Horst [EMAIL PROTECTED] wrote:
 Hi,

 we have a third-party product that has a C++ api on HP-UX.

 I would like be able to use the API in Python (as I remember Python is
 good at doing this).

 I have no experience with this so I Googled and tried to find some
 info on what I had to do.

 So, I installed Python 2.4.4 and Swig 1.3.33

 The header file to the library is '/opt/OV/include/opcsvcapi.h'.

 I created a SWIG file with the following content:
 
 %module opcsvcapi
  %{
  /* Includes the header in the wrapper code */
  #include /opt/OV/include/opcsvcapi.h
  %}

  /* Parse the header file to generate wrappers */
  %include /opt/OV/include/opcsvcapi.h
 
 Then I ran the cmd:
 # swig -c++ -python opcsvcapi.i
 with output:
 
 /opt/OV/include/opcsvcapi.h:41: Warning(362): operator= ignored
 /opt/OV/include/opcsvcapi.h:46: Warning(503): Can't wrap 'operator
 Type' unless renamed to a valid identifier.
 

 The result are two files:
 opcsvcapi.py
 opcsvcapi_wrap.cxx

 I created a 'setup.py' file with the following content:
 
 import distutils
 from distutils.core import setup, Extension

 setup(name = opcsvcapi,
       version = 1.0,
       ext_modules = [Extension(_opcsvcapi,
 [opcsvcapi.i,opcsvcapi.cxx])])
 

 Then I run: python setup.py build

 This results in an extra file:
 opcsvcapi_wrap.c and a 'build' directory

 and the following errors:
 
 running build
 running build_ext
 building '_opcsvcapi' extension
 swigging opcsvcapi.i to opcsvcapi_wrap.c
 swig -python -o opcsvcapi_wrap.c opcsvcapi.i
 creating build
 creating build/temp.hp-ux-B.11.11-9000-800-2.4
 gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-
 prototypes -fPIC -I/usr/local/include/python2.4 -c opcsvcapi_wrap.c -o
 build/temp.hp-ux-B.11.11-9000-800-2.4/opcsvcapi_wrap.o
 In file included from /usr/local/include/python2.4/Python.h:8,
                  from opcsvcapi_wrap.c:118:
 /usr/local/include/python2.4/pyconfig.h:851:1: warning:
 _POSIX_C_SOURCE redefined
 command line:1:1: warning: this is the location of the previous
 definition
 In file included from opcsvcapi_wrap.c:2490:
 /opt/OV/include/opcsvcapi.h:12:18: error: vector: No such file or
 directory
 In file included from opcsvcapi_wrap.c:2490:
 /opt/OV/include/opcsvcapi.h:15: error: expected '=', ',', ';', 'asm'
 or '__attribute__' before 'SvcAPI'
 opcsvcapi_wrap.c: In function 'Swig_var_SvcAPI_set':
 opcsvcapi_wrap.c:2505: error: 'SvcAPI' undeclared (first use in this
 function)
 opcsvcapi_wrap.c:2505: error: (Each undeclared identifier is reported
 only once
 opcsvcapi_wrap.c:2505: error: for each function it appears in.)
 opcsvcapi_wrap.c:2505: error: 'namespace' undeclared (first use in
 this function)
 opcsvcapi_wrap.c:2505: error: expected expression before ')' token
 opcsvcapi_wrap.c: In function 'init_opcsvcapi':
 opcsvcapi_wrap.c:3064: error: 'Swig_var_SvcAPI_get' undeclared (first
 use in this function)
 error: command 'gcc' failed with exit status 1
 

 and that's it.

 Any idea what I am doing wrong?

 Any help much appreciated

 Kris

Well, the errors you got from the compiler are just confusing to me,
but I suspect it goes back to the warning you got from SWIG.  Some
class in there is overriding the = operator, but since that can't be
done in Python, you need to give it some special instructions on how
to handle that.

For example, if you have Foo::operator=, in your SWIG header include a
line like:
%rename(assign) Foo::operator=

Then in the Python module, the Foo class will have an assign method.

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


Re: Double underscores -- ugly?

2008-02-19 Thread Hyuga
On Feb 19, 4:01 am, Duncan Booth [EMAIL PROTECTED] wrote:
 Berwyn [EMAIL PROTECTED] wrote:
  Is it just me that thinks __init__ is rather ugly? Not to mention
  if __name__ == '__main__': ...?

  That ugliness has long been my biggest bugbear with python, too.  The
  __name__ == '__main__' thing is something I always have to look up,
  every time I use it, too ... awkward.

  I'd settle for:

  hidden def init(self):  # which could be extended to work
  for everything hidden x=3
  ...

  And for __name__ == '__main__' how about:

  if sys.main():
  ...

 Or even:

   @hidden
   def init(self): ...

 @main
 def mymainfunc():
...


I'd much rather type a few underscores than have to constantly use
decorators.  I don't see what's so ugly about __init__.  To me it just
looks like it's underscored, though maybe that comes from having
worked with a lot of wikis.  But I really don't find it an
encumbrance, and the fact that it requires no special handling from
the parser is just part of the beautiful simplicity of Python.

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


Re: re question

2008-02-08 Thread Hyuga
On Feb 7, 1:47 pm, Amit Gupta [EMAIL PROTECTED] wrote:
 On Feb 7, 10:38 am, Amit Gupta [EMAIL PROTECTED] wrote:



  Python'ites

  I searched around google to find the answer to this question, but I
  can't:

  I have a named regexp : x = re.compile((?Pme[a-z]+))

  What I want is an iterator, that can return me both the groupname
  and the matched string,  e.g:

  m = x.search(aa)

  Somehow, I want to get
  {me : aa}, either as dictionary or some iterable form.

  All I found is, I need to know the groupname to get the
  corresponding match. Any help is appreciated.

  A

 Got It. re.search() has a function groupdict(), doing precisely that.

Just to be pedantic so that no one else who might read this does not
get confused, re.search() does not [have] a function groupdict().
re.search(), like many function in the re module returns a match
object.  Match objects have a groupdict() method.

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


Re: How to autorun a python script when a specific user logs on?

2008-02-05 Thread Hyuga
You know, I'm all for responsible parenting, and teaching kids about
about responsible computer use, and even to an extent checking out
things like browser history to make sure they're up to no good.  But
this is outright spying--a total invasion of privacy.  Might as well
put a hidden web cam in their room to make sure they aren't doing
naughty things like looking at old-media porn or masturbating.  Your
friend should talk to his kids, not automatically assume their guilt.

On Feb 5, 2:57 am, jack trades [EMAIL PROTECTED] wrote:
 I wrote a simple keylogger for a friend of mine that wants to keep track of
 his kid's (12 and 14 yr old boys) computer usage to make sure they aren't
 getting into the naughty parts of the web.  The logger works great (source
 attached at bottom) but I ran into some troubles getting it to autorun on
 login.

 The method I tried was to add a registry entry using the function below.
 def autostartProgram():
   Registers program with the windows registry to autostart on login
   os.system(r'reg add HKLM\software\microsoft\windows\currentversion\run /v
 logger /t REG_SZ /d C:\keylogger\logger.py')

 This starts the program on login, no problem.  However I noticed that after
 logging out and back in on my dev (xp pro) machine that My Network Places
 was gone from my start menu.  I restored the registry and tried again.  It
 happened over and over.  I also had problems with Winamp/Media Player after
 doing this (grrr I hate Windoze).

 Also I noticed that when you switch users using this method, it shows that
 there is 1 program running.  While I'm not trying to be stealthy I don't
 want the kids poking around in his system (probably destroying it) trying to
 find the program that's running.

 How would I SAFELY start the program at login time for a specific user?
 I've been reading google about this for the past 5 hours and I'm stuck,
 please help.
 Note:  I thought about registering it as a system service, but wouldn't that
 make the program start for any user that logs on?

 Thanks for sparing some time,
 Jack Trades

 PS.  The source for the logger is below.  I'll post the source for the
 reader when I'm finished if anyone's interested (I'll also post it to
 uselesspython when they're back up).
 Note:  Currently this program must be stored in a folder named
 C:\keylogger\  (I won't post to uselesspython until I fix this, but it
 seems necessary when autostarting the program through the registry.)

 ## Windows Only Script!!!
 
 #
 ## logger.py | 2008-02-04 | Logs keystrokes and screenshots to disk
 ##
 ##Copyright (C) 2008, Jack Trades
 ##
 ##This program is free software: you can redistribute it and/or modify
 ##it under the terms of the GNU General Public License as published by
 ##the Free Software Foundation, either version 3 of the License, or
 ##(at your option) any later version.
 ##
 ##This program is distributed in the hope that it will be useful,
 ##but WITHOUT ANY WARRANTY; without even the implied warranty of
 ##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ##GNU General Public License for more details.
 ##
 ##You should have received a copy of the GNU General Public License
 ##along with this program.  If not, see http://www.gnu.org/licenses/
 ##
 ## Recent Changes:
 ## Added quality setting to grabScreen
 ## Wrapped all functions in try/except blocks to silently pass over errors
 ##
 ## TODO:
 ## Write function to send data to secure ftp server in local network
 ## Write any errors to a text file
 
 #
 ## Requires: pyHook, win32all, PIL

 import pyHook
 import pythoncom
 import ImageGrab
 from time import time
 from threading import Timer

 
 #
 ## Start-Up
 
 #

 ## The full path is required when started automatically through windows
 registry
 ## Need to find a fix to allow relative paths (this way is UGLY!)
 folder = 'C:\\keylogger\\'

 filename = folder+'data\\'+str(time())  ## Each program start creates a new
 file
 skippedKeys = set( (0,) )

 def offloadData():
   Every time the program starts it should offload its log file and
   screenshots to another computer.  
   pass

 
 #
 ## Keylogger
 
 #
 ## The logger skips over keys defined in the global variable *skippedKeys*

 def writeData(eventWindow, ascii):
   Appends each keystroke to file *filename* as defined at the top
   try:
 eventTime = time()
 f = open(filename, 'a')
 f.write(str( (ascii, eventTime, eventWindow) )+',')
 f.close()
   except:
 pass

 def onKeyboardEvent(event):

Re: Help needed

2008-01-11 Thread Hyuga
On Jan 10, 9:15 pm, tijo [EMAIL PROTECTED] wrote:
 Hi mate

 i need o do a python program to connect 2 systems using TCP/IP and
 UDP. Also i need to check the performance of these two protocols (how
 many bytes received and how much time took). I havent worked in python
 earlier and have no idea of this. Could someone pls help me. I created
 a program which can connect between 2 systems using these UDP and TCP/
 IP protocols. I dont know how to check the rest like how many bytes
 send or how much time taken
 since this is part of my course work could someone please help me
 thanks in advance.

 tijo

The standard library documentation, while lacking in some areas, is
very much your friend here:

From http://docs.python.org/lib/socket-objects.html (emphasis mine)
send(string[, flags])
Send data to the socket. The socket must be connected to a remote
socket. The optional flags argument has the same meaning as for recv()
above. *Returns the number of bytes sent.*

recv(bufsize[, flags])
Receive data from the socket. The return value is a string
representing the data received.

For timing you can probably use the timeit module (http://
docs.python.org/lib/module-timeit.html) but I'm not really sure how
you're defining performance.  I mean, I can already tell you that
overall UDP will be faster, as it has much less overhead.  Surely
your course has covered this...

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


Re: Help with Scons

2008-01-11 Thread Hyuga
On Jan 11, 5:20 am, anush [EMAIL PROTECTED] wrote:
 Can anybody tell how I could go about running python scripts with
 scons.

Have you tried reading the SCons user guide (http://www.scons.org/doc/
production/HTML/scons-user.html)?  It's actually pretty good.
I'm not too clear on what you're asking though.  SCons scripts are
written in Python (as is SCons itself)...

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


Re: help parsing ipv6 addresses and subnets

2007-11-08 Thread Hyuga
On Nov 8, 3:11 am, Thorsten Kampe [EMAIL PROTECTED] wrote:
 * Prabhu Gurumurthy (Wed, 07 Nov 2007 22:34:14 -0800)

  I would like to parse IPv6 addresses and subnet using re module in
  python.

 Just don't:http://pypi.python.org/pypi?%3Aaction=searchterm=ipv6
 submit=search

And even if you do end up doing the IPv6 parsing yourself (which you
shouldn't), regular expressions would be the wrong approach--there's
no way an RE can deal with replacing a :: with the correct number of
zeroes, among other complications.

Hyuga

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


Re: python project ideas

2007-10-25 Thread Hyuga
On Oct 25, 12:09 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 hi to everyone
 I wondered if this might be the right place to ask for some ideas for
 python project for university.
 I'd like it to be something useful and web-based. And the project must
 be complete in 2-3 months by 2-3 person group.
 May be something useful for open source or python community ...
 Well, just post what you think could be appropriate ...

Write a good, clean web-based music library/jukebox.  This is
something I've been thinking of doing for a while, but I welcome
someone to beat me to the punch.  There are a few such things out
there already--the most active is probably Jinzora, but I find it to
be bloated and slow, with a horribly cluttered interface.  And I think
there are some other projects out there, but most of them are
abandoned.  A simple, attractive interface would be good, with a built-
in flash player, and UTF-8 support throughout.

(and though this is a relatively minor detail, for god's sake if a
file has both ID3v1 and ID3v2 tags, use the ID3v2 tags by default.
Jinzora doesn't didn't do this last I tried and it was quite
obnoxious).

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


Re: Pull Last 3 Months

2007-10-18 Thread Hyuga
On Oct 18, 12:25 am, Gabriel Genellina [EMAIL PROTECTED]
wrote:
 I prefer the calendar module in that case:

 py import locale
 py locale.setlocale(locale.LC_ALL, '')
 'Spanish_Argentina.1252'
 py
 py import calendar
 py calendar.month_abbr[12]
 'Dic'
 py def prev_months(since, howmany):
 ...   return [calendar.month_abbr[(since.month-i-2) % 12 + 1] for i in
 range(how
 many)]
 ...
 py import datetime
 py prev_months(datetime.datetime(2005,2,10), 4)
 ['Ene', 'Dic', 'Nov', 'Oct']
 py prev_months(datetime.datetime(2005,10,17), 3)
 ['Sep', 'Ago', 'Jul']

Ah, you beat me to it.  I was going to point out that if you're going
to be using month strings, you should use calendar, since it can also
use the correct locale.  Plus, it offers a ridiculously simple
solution to this problem compared to all the others.

Hyuga

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


Re: Python module for making Quicktime or mpeg movies from images

2007-10-15 Thread Hyuga
On Oct 12, 3:53 pm, jeremito [EMAIL PROTECTED] wrote:
  NodeBox; nodebox.org

  GUI application that creates either PDFs or Quicktime vids from python
  code. Unix/Linux/MacOS.

 I actually found NodeBox in my googling.  This seems to be a stand
 alone application.  I need to be able to convert my images to a movie
 from my code I wrote myself.

Why?  Whether you're using a library or an external application, it's
not code that you wrote yourself.  There's shouldn't be any reason you
couldn't call an application like mencoder from your program.  Either
way you're certainly not going to find anything written in pure Python
for encoding video.

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


Re: Howto Launch a windows application ?

2007-10-08 Thread Hyuga
On Oct 3, 5:39 pm, stef mientki [EMAIL PROTECTED] wrote:

 from subprocess import *

 cmd =[]
 cmd.append ( 'D:\\PIC-tools\\JALxxx\\jalv2_3.exe' )
 cmd.append ( '-long-start' )
 cmd.append ( '-d')
 cmd.append ( '-clear' )
 cmd.append ( '-sD:\\PIC-tools\\JAL\\libs2' )
 cmd.append ( 'd:\\pic-tools\\jal\\programs\\test_rs232\\test_rs232_hw.jal' )
 cmd.append ( 'd:\\data_actueel\\d7_test_browser\\temp.log' )

This is sort of aside from your original question, but I should also
point out how unnecessary all those 'cmd.append's are.  You can
initialize the list all at once simply like so:

cmd =['D:\\PIC-tools\\JALxxx\\jalv2_3.exe',
  '-long-start',
  '-d',
  '-clear',
  '-sD:\\PIC-tools\\JAL\\libs2',
  'd:\\pic-tools\\jal\\programs\\test_rs232\\test_rs232_hw.jal',
  'd:\\data_actueel\\d7_test_browser\\temp.log']

Hyuga

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


Re: Asking all python programmers.

2007-08-30 Thread Hyuga
On Aug 29, 11:09 am, sjpiii [EMAIL PROTECTED] wrote:
 You mean use correct spelling and grammar?  But what about all the time
 we've spent creating cutesy little non-words like l8er?

 Actually, I'm less tolerant of those than of normal spelling and grammar
 errors because of the number of posters here for whom english is not their
 native language.

What I find worst of all, however, are people for whom English is not
their first language, *and* they write in lazy, slangy AOL-speak.
Making mistakes is fine, and even being completely incomprehensible is
bearable if it looks like an effort was made to use the language
correctly.  I don't know about anyone else, but when I'm learning a
new language, spoken or programming, I try my best to use it is
correctly as possible given my level of experience with it.  Using
slang and shorthand correctly really requires you to know what you're
doing--sort of like optimizing.

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


Re: self extracting zipefile (windows) and (standard module) zipefile

2007-08-29 Thread Hyuga
First of all, there's really no such thing as a self extracting
zipefile.  I mean, obviously you have to do something to unzip it.  A
file doesn't just execute itself.  What you're dealing with is not a
_zip file_.  It's an executable that has a zip file bundled with it,
and the code to unzip it, most likely into your current directory
(though some such executables allow you to provide a path to unzip
to).  You'll have to execute it--there's no way you can operate on it
like a normal zip file.

On Aug 29, 7:53 am, Werner [EMAIL PROTECTED] wrote:
 Hi,

 I try to read (and extract) some self extracting zipefiles on a
 Windows system. The standard module zipefile seems not to be able to
 handle this.

  fName = rC:\tmp\mySelfExtratingFile.exe
  import zipfile
  zipefile.is_zipfile(fName))

 False

 Is there a wrapper or has some one experience with other libaries to
 extract those files?

 Thanks in advance
 Werner

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


Re: How to optimise this code?

2007-08-22 Thread Hyuga
On Aug 22, 4:52 am, David N Montgomery [EMAIL PROTECTED]
wrote:
 unittest is the best choice for my needs and works perfectly in Eclipse.
 Unfortunately though it (and many other things) does not work under the
 application we have to use to run our python scripts.

 This leaves me with 'functionToCall = getattr(self, testCase%s % tc)'.
 This achieves the optimisation/simplification I had been looking for.

 Thank you once again.

Just out of curiosity, what about your environment prevents you from
using unittest?

Hyuga

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


Re: Symbolic Link

2007-08-20 Thread Hyuga
On Aug 19, 4:29 pm, mosscliffe [EMAIL PROTECTED] wrote:
 The source file is in an area which python can see, but not the
 browser.  I am trying to make a link in a browser friendly area so I
 can use it to display an image file.

You might want to try using an .htaccess file.  Place a file
called .htaccess in the browser friendly area and place in it the
line:

Options +FollowSymLinks

Assuming your hosting service will allow that, then it should work.
If not, then why not just copy the image files?  Storage is cheap
these days.

Hyuga

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


Re: i am new to python-Please somebody help

2007-08-02 Thread Hyuga
On Aug 2, 8:51 am, Steven D'Aprano
[EMAIL PROTECTED] wrote:
 On Thu, 02 Aug 2007 09:31:43 +, cool.vimalsmail wrote:

 [snip]

 You would be better off actually writing a sensible subject line instead
 of grovelling.

 Subject: How to use gzip in Python? [beginner]

 Then, having written a good subject line, it might have suggested a good
 search string for Google: gzip python

 http://www.google.com.au/search?q=gzip+python

 The first two links found will answer your question.

 --
 Steven.

OT
Unlike gregarican, I mostly agree with the content of your post.
Except for your subject line suggestion.  Why on earth would you
recommend someone use the obnoxious How to __ ? question
format?  Yes, I know it's extremely common, but it's completely
nonsensical English.  Just try saying it out loud with an inquiring
inflection on the last word.  Sounds ridiculous doesn't it?  At least
without the question mark it means that the thread is on the topic of
How to _.
/OT

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


Re: sqlite3 bug??

2007-06-18 Thread Hyuga
On Jun 17, 9:16 am, mark carter [EMAIL PROTECTED] wrote:
 Should I also explicitly close the cursor and connection, or is that
 taken care of automagically?


Somebody correct me if I'm wrong, but I'm pretty sure that the Cursor
and Connection objects properly clean themselves up when deallocated
(when their reference count reaches 0), so not explicitly closing them
isn't a terrible thing.  In fact, I have code in which references to a
db connection are passed around, so I have to be careful about
explicitly closing the connection, lest it be in use by some other
method somewhere.  Maybe people will frown on this, but it's not
uncommon.

Hyuga

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


Re: sqlite3 bug??

2007-06-18 Thread Hyuga
On Jun 18, 11:01 am, Hyuga [EMAIL PROTECTED] wrote:
 In fact, I have code in which references to a
 db connection are passed around, so I have to be careful about
 explicitly closing the connection, lest it be in use by some other
 method somewhere.


Hate to reply to myself, but I should clarify that passing around a
handle to an existing DB connection is necessary as a means of
allowing multiple methods that write to the DB to operate atomically
before calling commit().  So again, if you're doing something like
that, you want to be absolutely certain before you close your
connection that it's not in use elsewhere.

Hyuga

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


Re: otsu threshold in python

2007-06-06 Thread Hyuga
On Jun 6, 7:49 am, azrael [EMAIL PROTECTED] wrote:
 the otsu filter is a filter that takes a image and from its histogram
 calculates the values at which the image should be thresholded to
 acomplish an optimal seperation of a foregtround and background
 object.

So I learned from the PDF I linked you to.  Take a good look at it.
The equation is fairly simple to begin with, and the paper shows how
to simplify the calculation quite a bit.
Also, the Wikipedia article at http://en.wikipedia.org/wiki/Otsu's_method
even gives a simple pseudo-code implementation.  I've tried it myself
in Python, and it seems give good results.

 I didn't hear about, but I used it through the ImageJ tool. It gave me
 optimal results. I'm working on a project for my clases, and the last
 thing I need to accomplish my goal is this filter. Is there anyone who
 implemented it.

 Thanks Hyuga

 On Jun 5, 6:02 pm, Hyuga [EMAIL PROTECTED] wrote:

  On Jun 5, 10:19 am, azrael [EMAIL PROTECTED] wrote:

   Hy guys.
   I'd like to ask you for a favour.
   I tried several times to implement the otsu threshold filter in
   python. but I failed every time. I found the soucre code i n Java from
   the ImageJ project but I never worked in Java and there have been used
   some built in Java functions which I don't know how they behave. I
   also found the otsu threshold in the ia636 python module and would
   like only this filter and don't want to import this library.
   Is there anyone who wold like to help me. I need a function that takes
   a list of 256 elements as an argument and returns the threshold values
   for the threshold according to Otsu.

   In addvance, I don't expect someone to do my homework. I really tried
   it, I have been googling and didn't find a standalone function. I
   wasn't able write a standalone function because I don't understand the
   Otsu method. I just know that it works well and that I need it.

   If there is no one that wants to help me with this problem, can
   someone at least explain me in a detailed way how to implement it.

   Thanks

  What is the whole assignment meant to accomplish?  Is the assignment
  to implement the Otsu method?  If so, you shouldn't be trying to find
  library functions.  Or is it just something you need for some larger
  task?

  I would ask exactly what problems you're running into, but:

   it, I have been googling and didn't find a standalone function. I
   wasn't able write a standalone function because I don't understand the
   Otsu method. I just know that it works well and that I need it.

  How do you know you need it?  Did you learn about this in class?  And
  if so, are you expected to understand it?
  I've never even heard of it, but I googled it, and found the fourth
  hit pretty 
  good:http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/MORSE/thresho...
  This gives a reasonable explanation.  I couldn't tell you *exactly*
  why it works, but it's understandable enough from that that I can see
  that it should work, and to see how to implement it.

  Not to mention that the above PDF basically *gives* you the
  implementation for free (just make sure not to miss the recurrence
  relations at the end of the section on the Otsu method, or else you'll
  be screwing yourself).

  So give that a look and see if it helps.

  Hyuga


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


Re: otsu threshold in python

2007-06-05 Thread Hyuga
On Jun 5, 10:19 am, azrael [EMAIL PROTECTED] wrote:
 Hy guys.
 I'd like to ask you for a favour.
 I tried several times to implement the otsu threshold filter in
 python. but I failed every time. I found the soucre code i n Java from
 the ImageJ project but I never worked in Java and there have been used
 some built in Java functions which I don't know how they behave. I
 also found the otsu threshold in the ia636 python module and would
 like only this filter and don't want to import this library.
 Is there anyone who wold like to help me. I need a function that takes
 a list of 256 elements as an argument and returns the threshold values
 for the threshold according to Otsu.

 In addvance, I don't expect someone to do my homework. I really tried
 it, I have been googling and didn't find a standalone function. I
 wasn't able write a standalone function because I don't understand the
 Otsu method. I just know that it works well and that I need it.

 If there is no one that wants to help me with this problem, can
 someone at least explain me in a detailed way how to implement it.

 Thanks

What is the whole assignment meant to accomplish?  Is the assignment
to implement the Otsu method?  If so, you shouldn't be trying to find
library functions.  Or is it just something you need for some larger
task?

I would ask exactly what problems you're running into, but:
 it, I have been googling and didn't find a standalone function. I
 wasn't able write a standalone function because I don't understand the
 Otsu method. I just know that it works well and that I need it.

How do you know you need it?  Did you learn about this in class?  And
if so, are you expected to understand it?
I've never even heard of it, but I googled it, and found the fourth
hit pretty good: 
http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/MORSE/threshold.pdf
This gives a reasonable explanation.  I couldn't tell you *exactly*
why it works, but it's understandable enough from that that I can see
that it should work, and to see how to implement it.

Not to mention that the above PDF basically *gives* you the
implementation for free (just make sure not to miss the recurrence
relations at the end of the section on the Otsu method, or else you'll
be screwing yourself).

So give that a look and see if it helps.

Hyuga

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