Re: New to Python - block grouping (spaces)

2015-04-19 Thread CHIN Dihedral
On Thursday, April 16, 2015 at 11:06:28 PM UTC+8, Mark Lawrence wrote:
> On 16/04/2015 15:52, Blake McBride wrote:
> 
> > So, Python may be a cute language for you to use as an individual, but it 
> > is unwieldy in a real development environment.
> >
> 
> Thanks for this, one of the funniest comments I've read here in years. 
> It's good to see that new people share the humourous side of the Python 
> programming culture.  Long may it continue.
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

Python is a cross-platform computer
language with dynamical types, 
functional programming featuers, oops, and generic programming featuers 
designed in the language.

Now the generic part is the main
progress in the software and IT
sectors 



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


Re: generator/coroutine terminology

2015-04-18 Thread CHIN Dihedral
On Friday, March 13, 2015 at 5:36:35 PM UTC+8, Marko Rauhamaa wrote:
> Rustom Mody :
> 
> > Nice demo of the same confusing terminology we are talking about.
> 
> Why don't you just stick with the terminology of the language
> specification? I think your students are going to be more confused if
> you try to come up with something better.
> 
> > When I say "expect generators to close" I mean 'generator-instances'
> > ie at runtime
> >
> > When you say "expect both to close with return" you are talking of
> > program-texts ie the 'factory'
> >
> > [Or I am guilty of the same I am accusing python of]
> 
> Your 'factory' is a:
> 
> generator
> A function which returns an iterator.
> https://docs.python.org/3/glossary.html>
> 
> Your 'generator-instance' is an:
> 
> iterator
> An object representing a stream of data.
> https://docs.python.org/3/glossary.html>
> 
> I don't think you should read much into what str(obj) returns. It's not
> much more than a random printable some CPython coder has cooked up in
> the heat of the moment.
> 
> 
> Marko

Well, the functional that returns a function instance which can be used
as an interator  is also a function. 

Well, some might use terms in generics programming as described in the book by 
Gangs of 4. 

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


Re: What is elegant way to do configuration on server app

2015-03-27 Thread CHIN Dihedral
On Thursday, March 26, 2015 at 4:19:33 PM UTC+8, Jerry OELoo wrote:
> Hi.
> I have used python to provide a web service app, it will running 7*24,
> and it will return some data to client by API.

http://jonpy.sourceforge.net/modpy.html

Check the page of modpy and django.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basic Python V3 Search Tool using RE module

2015-03-26 Thread CHIN Dihedral
> Gregg Dotoli

Are you reminding everyone who had a PC running DOS2.X-3X in 1990. 

It was really a pain at that time 
that a hard disk of an intel-MS based PC was sold hundreds of dollars, and 
another pain was that the buyer had to use the disabled 
dir in DOS after buying a HD.


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


Re: fibonacci series what Iam is missing ?

2015-03-24 Thread CHIN Dihedral
On Tuesday, March 24, 2015 at 10:24:59 PM UTC+8, Ian wrote:
> On Tue, Mar 24, 2015 at 12:20 AM, Rustom Mody  wrote:
> > On Tuesday, March 24, 2015 at 10:51:11 AM UTC+5:30, Ian wrote:
> >> Iteration in log space. On my desktop, this calculates fib(1000) in
> >> about 9 us, fib(10) in about 5 ms, and fib(1000) in about 7
> >> seconds.
> >>
> >> def fib(n):
> >> assert n >= 0
> >> if n == 0:
> >> return 0
> >>
> >> a = b = x = 1
> >> c = y = 0
> >> n -= 1
> >>
> >> while True:
> >> n, r = divmod(n, 2)
> >> if r == 1:
> >> x, y = x*a + y*b, x*b + y*c
> >> if n == 0:
> >> return x
> >> b, c = a*b + b*c, b*b + c*c
> >> a = b + c
> >
> > This is rather arcane!
> > What are the identities used above?
> 
> It's essentially the same matrix recurrence that Gregory Ewing's
> solution uses, but without using numpy (which doesn't support
> arbitrary precision AFAIK) and with a couple of optimizations.
> 
> The Fibonacci recurrence can be expressed using linear algebra as:
> 
> F_1 = [ 1 0 ]
> 
> T = [ 1 1 ]
> [ 1 0 ]
> 
> F_(n+1) = F_n * T
> 
> I.e., given that F_n is a vector containing fib(n) and fib(n-1),
> multiplying by the transition matrix T results in a new vector
> containing fib(n+1) and fib(n). Therefore:
> 
> F_n = F_1 * T ** (n-1)
> 
> The code above evaluates this expression by multiplying F_1 by powers
> of two of T until n-1 is reached. x and y are the two elements of the
> result vector, which at the end of the loop are fib(n) and fib(n-1).
> a, b, and c are the three elements of the (symmetric) transition
> matrix T ** p, where p is the current power of two.
> 
> The last two lines of the loop updating a, b, and c could equivalently
> be written as:
> 
> a, b, c = a*a + b*b, a*b + b*c, b*b + c*c
> 
> A little bit of algebra shows that if a = b + c before the assignment,
> the equality is maintained after the assignment (in fact the elements
> of T ** n are fib(n+1), fib(n), and fib(n-1)), so the two
> multiplications needed to update a can be optimized away in favor of a
> single addition.

Well, solving a  homogeneous difference equation of 2 degrees 
and generating the solution sequence 
for a particular one like the Finbnaci series is a good programming practice.

A more general programming practice 
is to generate the solution series 
of an arbitrary   homogeneous 
difference euqation of integer coefficients when a real or complex solution 
does exist.

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


Re: fibonacci series what Iam is missing ?

2015-03-24 Thread CHIN Dihedral
On Tuesday, March 24, 2015 at 6:54:20 AM UTC+8, Terry Reedy wrote:
> On 3/23/2015 2:44 PM, Dave Angel wrote:
> 
> > ## Example 2: Using recursion with caching
> > cache = [0, 1]
> > def fib4(n):
> >  if len(cache) <= n:
> >  value = fib4(n-2) + fib4(n-1)
> >  cache.append(value)
> >  return cache[n]
> >
> > This one takes less than a millisecond up to n=200 or so.
> 
> Iteration with caching, using a mutable default arg to keep the cache 
> private and the function self-contained.  This should be faster.
> 
> def fib(n, _cache=[0,1]):
>  '''Return fibonacci(n).
> 
>  _cache is initialized with base values and augmented as needed.
>  '''
>  for k in range(len(_cache), n+1):
>  _cache.append(_cache[k-2] + _cache[k-1])
>  return _cache[n]
> 
> print(fib(1), fib(3), fib(6), fib(5))
> # 1 2 8 5
> 
> Either way, the pattern works with any matched pair of base value list 
> and recurrence relation where f(n), n a count, depends on one or more 
> f(k), k < n.  'Matched' means that the base value list is as least as 
> long as the maximum value of n - k.  For fib, the length and max are both 2.
> 
> -- 
> Terry Jan Reedy
How about adding a new type of 
numbers of the form:
 (a+sqrt(r0)+ swrt(r1))/b with proper operations, and  then one can compute 
the Fib term directly in a 
field. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: fibonacci series what Iam is missing ?

2015-03-23 Thread CHIN Dihedral
On Tuesday, March 24, 2015 at 1:00:11 AM UTC+8, Chris Angelico wrote:
> On Tue, Mar 24, 2015 at 3:16 AM, Dave Angel  wrote:
> > An entirely separate question is whether you can gain performance by caching
> > intermediate values.  For example, if you capture values in a list, you
> > could potentially save a lot of time, at least for non-trivial values of n.
> 
> If you take a step back and seek to print a sequence of Fibonacci
> numbers, rather than calculating specific ones based on their indices,
> then you don't even need to consider caching. As soon as you've
> printed out a number, you move right along.
> 
> ChrisA

Well, the good part is that the python version can compute the right
result for a  much larger n in 
fib(n). 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Windows service in production?

2015-03-19 Thread CHIN Dihedral

Please check wxpython and there was
 an example.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Example of python service running under systemd?

2014-09-12 Thread CHIN Dihedral
On Friday, September 12, 2014 1:48:37 AM UTC+8, Travis Griggs wrote:
> I've been reading lots of systemd docs. And blogs. Etc. At this point, I 
> think I would benefit from learning by example...
> 
> 
> 
> Does anyone have an example .service file that they use to launch a long 
> running service written as a python program?
> 
> 
> 
> If there is any example of what you changed to your python program itself, 
> that to would be really instructional for me.

Please check the examples in wxpython
and boa.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why can not initialize the class?

2014-08-23 Thread CHIN Dihedral
On Saturday, August 23, 2014 7:29:44 AM UTC+8, luofeiyu wrote:
> One final version:
> 
> 
> 
> class Contact(object):
> 
>  def __init__(self, email="haha@haha"):
> 
>  self.email = email
> 
>  def _get_email(self):
> 
>  return self._the_secret_private_email
> 
>  def _set_email(self, value):
> 
>  self.self._the_secret_private_email = value
> 
>  email = property(_get_email, _set_email)
> 
> 
> 
> contact = Contact()
> 
> print(contact.email)
> 
> 
> 
> There is a little mistake here. It is
> 
> 
> 
> self._the_secret_private_email = value
> 
> 
> 
> not
> 
> 
> 
> self.self._the_secret_private_email = value
> 
> 
> 
> think for your demo .The value in `def _set_email(self, value):` is the value 
> of self.email .

Well, an object in python can add
properties in the run-time to evolve
steadily and stealthly.

Those unnessary set-get-C++ methods
are not very important in PYTHON.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: the output in reference of descriptor.

2014-08-22 Thread CHIN Dihedral
On Friday, August 22, 2014 9:25:02 AM UTC+8, luofeiyu wrote:
> class C(object):
> 

Well, in python class is treated 
as onte of the first class built in
operations.

class "new_class_ame" ( parentclasses)


Please check this syntax first in Python.
>  a = 'abc'
> 
>  def __getattribute__(self, *args, **kwargs):
> 
>  print("__getattribute__() is called")
> 
>  return object.__getattribute__(self, *args, **kwargs)
> 
>  def __getattr__(self, name):
> 
>  print("__getattr__() is called ")
> 
>  return name + " from getattr"
> 
>  def __get__(self, instance, owner):
> 
>  print("__get__() is called", instance, owner)
> 
>  return self
> 
>  def foo(self, x):
> 
>  print(x)
> 
> 
> 
> 
> 
>  class C2(object):
> 
>  d = C()
> 
> 
> 
> 
> 
>  >>> c2.d
> 
> __get__() is called <__main__.C2 object at 0x0297BE10>  
> '__main__.
> 
> C2'>
> 
> <__main__.C object at 0x0297BBA8>
> 
> 
> 
> I understant the result ,c2.d trigger the __get__ method in class C.
> 
>  def __get__(self, instance, owner):
> 
>  print("__get__() is called", instance, owner)
> 
>  return self
> 
> 
> 
> It print "__get__() is called", instance, owner and return self 
> 
> `<__main__.C object at 0x0297BBA8>`
> 
> 
> 
> 
> 
>  >>> c2.d.a
> 
> __get__() is called <__main__.C2 object at 0x0297BE10>  
> '__main__.
> 
> C2'>
> 
> __getattribute__() is called
> 
> 'abc'
> 
> 
> 
> Why the result of c2.d.a  is not :
> 
> 
> 
> __get__() is called <__main__.C2 object at 0x0297BE10>  
> '__main__.
> 
> C2'>
> 
> __getattribute__() is called
> 
> 'abc'
> 
> 
> 
> Why the` return self` in the __get__ method in class C  does not work?

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


Re: Python vs C++

2014-08-22 Thread CHIN Dihedral
On Friday, August 22, 2014 8:26:00 AM UTC+8, Chris Angelico wrote:
> On Fri, Aug 22, 2014 at 4:05 AM, Joseph Martinot-Lagarde
> 
>  wrote:
> 
> > For information, Cython works with C++ now:
> 
> > http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html.
> 
> 
> 
> Now isn't that cool!
> 
> 
> 
> Every time Cython gets discussed, I get a renewed desire to learn it.
> 
> Trouble is, I don't have any project that calls for it - there's
> 
> nothing I'm desperately wanting to do that involves both Python and
> 
> C/C++. Anyone got any suggestions? :)
> 
> 
> 
> ChrisA

Don't you use C as a portable assembler
in Python?

PYTHON->C->HW_BOUNDED_ASSEMBLY

That is the way to speed up python
programs using critical heavy 
computing functions.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: try/exception - error block

2014-08-03 Thread CHIN Dihedral
On Sunday, August 3, 2014 10:39:19 PM UTC+8, Roy Smith wrote:
> In article ,
> 
>  bruce  wrote:
> 
> 
> 
> > I'm posting the test code I'm using. Pointers/comments would be 
> 
> > helpful/useful.
> 
> 
> 
> It would be really helpful if you could post a minimal code example 
> 
> which demonstrates the problem you're having.  Leave out everything 
> 
> (including the commented-out code) which isn't necessary to demonstrate 
> 
> the behavior.

Oh, I remember I was working with 
a professional programer who agreed
with me that a subroutine or function
longer than 80 lines in C/C++/PASCAL/Fortan, etc. must explain the 
reason in the commented preamble claearly for other programer to check
the necessity of the unusual length.

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


Re: one to many (passing variables)

2014-07-28 Thread CHIN Dihedral
On Tuesday, July 29, 2014 3:29:04 AM UTC+8, Terry Reedy wrote:
> On 7/25/2014 9:47 PM, C.D. Reimer wrote:
> 
> >
> 
> > On 7/24/2014 2:58 AM, Ben Finney wrote:
> 
> >> Here is an article on good API design; the principles apply to Python
> 
> >> http://blog.isnotworking.com/2007/05/api-design-guidelines.html>.
> 
> >> You know your API and its requirements better than we; see whether that
> 
> >> sheds any light on improvements to make.
> 
> > Thank you for the link. I'm curious about one item mentioned in the
> 
> > article: "Avoid return values that Demand Exceptional Processing: return
> 
> > zero-length array or empty collection, not null"
> 
> >
> 
> > Isn't a zero-length array, empty collection and null all the same thing?
> 
> 
> 
> No. [] is an empty list, None is a null.
> 
> 
> 
> > Or does the "Demand Exceptional Processing" comes from testing to see if
> 
> > the object is empty versus being null?
> 
> 
> 
> Testing whether null or not.
> 
> 
> 
> > And does this apply to Python?
> 
> 
> 
> Yes. If a function always returns a iterable, sometimes empty, it can be 
> 
> used as follows:
> 
> 
> 
> for item in f(): process(item)
> 
> 
> 
> If the iterable is empty, nothing happens.  If the function returns None 
> 
> instead of empty, then the use has to write the following to get the 
> 
> same result.
> 
> 
> 
> result = f()
> 
> if result is not None:
> 
>for item in f(): process(item)
> 
> 
> 
> The function user may *elect* to give special processing to empty 
> 
> iterables.  A None return *demands* special processing, even if not 
> 
> needed, as above.
> 
> 
> 
> -- 
> 
> Terry Jan Reedy

Oh, iterators are better to shoot 
targets in the L1 and L2 cache memory,
but it is not  the same as the old
 reading the whole list way.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Anything better than asyncio.as_completed() and asyncio.wait() to manage execution of large amount of tasks?

2014-07-22 Thread CHIN Dihedral
On Thursday, July 17, 2014 7:09:02 AM UTC+8, Maxime Steisel wrote:
> 2014-07-15 14:20 GMT+02:00 Valery Khamenya :
> 
> > Hi,
> 
> >
> 
> > both asyncio.as_completed() and asyncio.wait() work with lists only. No
> 
> > generators are accepted. Are there anything similar to those functions that
> 
> > pulls Tasks/Futures/coroutines one-by-one and processes them in a limited
> 
> > task pool?
> 
> 
> 
> 
> 
> Something like this (adapted from as_completed) should do the work:
> 
> 
> 
> import asyncio
> 
> from concurrent import futures
> 
> 
> 
> def parallelize(tasks, *, loop=None, max_workers=5, timeout=None):
> 
> loop = loop if loop is not None else asyncio.get_event_loop()
> 
> workers = []
> 
> pending = set()
> 
> done = asyncio.Queue(maxsize=max_workers)
> 
> exhausted = False
> 
> 
> 
> @asyncio.coroutine
> 
> def _worker():
> 
> nonlocal exhausted
> 
> while not exhausted:
> 
> try:
> 
> t = next(tasks)
> 
> pending.add(t)
> 
> yield from t
> 
> yield from done.put(t)
> 
> pending.remove(t)
> 
> except StopIteration:
> 
> exhausted = True
> 
> 
> 
> def _on_timeout():
> 
> for f in workers:
> 
> f.cancel()
> 
> workers.clear()
> 
> #Wake up _wait_for_one()
> 
> done.put_nowait(None)
> 
> 
> 
> @asyncio.coroutine
> 
> def _wait_for_one():
> 
> f = yield from done.get()
> 
> if f is None:
> 
> raise futures.TimeoutError()
> 
> return f.result()
> 
> 
> 
> workers = [asyncio.async(_worker()) for i in range(max_workers)]
> 
> 
> 
> if workers and timeout is not None:
> 
> timeout_handle = loop.call_later(timeout, _on_timeout)
> 
> 
> 
> while not exhausted or pending or not done.empty():
> 
> yield _wait_for_one()
> 
> 
> 
> timeout_handle.cancel()

Well, I think you are missing the 
task managers as workers in your flow
of logics. 

I suggest a better version is 
with a global signal of 8 to 16 times clock of the normal worker pace in 
order to cope with ASYN events 
accordingly for the workers which colud be  decorated to yield, but not in the 
worker's funtions.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Network/multi-user program

2014-07-21 Thread CHIN Dihedral

> > almost nothing about JS.  I worked thru a short generic tutorial a couple
> 
Please check Pyjs and Python with flash
in http://pyjs.org/examples/Space.html
for the front end part of GUI under a
browser.

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


Re: Python and IDEs [was Re: Python 3 is killing Python]

2014-07-21 Thread CHIN Dihedral
On Sunday, July 20, 2014 9:53:02 AM UTC+8, C.D. Reimer wrote:
> On 7/19/2014 6:23 PM, Steven D'Aprano wrote:
> 
> > I haven't used Python on Windows much, but when I did use it, I found 
> 
> > the standard Python interactive interpreter running under cmd.exe to 
> 
> > be bare- bones but usable for testing short snippets. If I recall 
> 
> > correctly, it is missing any sort of command history or line editing 
> 
> > other than backspace, which I guess it would have been painful to use 
> 
> > for extensive interactive work, but when I started using Python on 
> 
> > Linux the interactive interpreter had no readline support either so it 
> 
> > was just like old times :-)
> 
> 
> 
> Windows PowerShell supports very basic Linux commands and has a command 
> 
> history. I'm always typing "ls" for a directory listing when I'm on a 
> 
> Windows machine. The regular command line would throw a DOS fit. 
> 
> PowerShell lets me get away with it.
> 
> 
> 
> http://en.wikipedia.org/wiki/Windows_PowerShell#Comparison_of_cmdlets_with_similar_commands
> 
> 
> 
> I prefer working on my vintage 2006 Black MacBook. Alas, the CPU fan is 
> 
> dying and MacBook shuts down after 15 minutes. I'm surprised at how well 
> 
> I was able to set up a equivalent programming environment on Windows.
> 
> 
> 
> Chris Reimer

Well, Python could be used as a 
scripting  language for routine jobs
in various Oses. 

But Python has been designed to be 
a cross-platform high-level general 
purpose programming  language from
the birth.

One can be sure that the investing in most of the programming concepts and 
skills  in Python 2.XX is still valid in Python 3.XX. 

Forget those non-investing imitators'  flase spamming claims.




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


Re: Confused with Functions and decorators

2014-07-21 Thread CHIN Dihedral
On Saturday, July 19, 2014 8:44:25 PM UTC+8, Wojciech Giel wrote:
> On 19/07/14 12:40, Jerry lu wrote:
> 
> > oh yeah i forgot about the decorators. Um say that you wanted to decorate a 
> > function with the outer() func you would just put @outer on top of it? And 
> > this is the same as passing another func into the outer func?
> 
> yes.
> 
> syntax was added because with very long function definitions it was 
> 
> dificult  to track reassignment to the name when it followed definition 
> 
> of the function. decorators is just abbreviation.
> 
> 
> 
>  >>> def outer(f):
> 
> ... def inner(*args, **kwargs):
> 
> ... print("inner function")
> 
> ... return f(*args, **kwargs)
> 
> ... return inner
> 
> ...
> 
>  >>> @outer
> 
> ... def myfunc(x):
> 
> ... print("Myfunc", x)
> 
> ...
> 
>  >>> myfunc("test")
> 
> inner function
> 
> Myfunc test
> 
> 
> 
> it is exactly equivalent to:
> 
> 
> 
>  >>> def outer(f):
> 
> ... def inner(*args, **kwargs):
> 
> ... print("inner function")
> 
> ... return f(*args, **kwargs)
> 
> ... return inner
> 
> ...
> 
>  >>> def myfunc(x):
> 
> ...  print("Myfunc", x)
> 
> ...
> 
>  >>> myfunc = outer(myfunc)
> 
>  >>> myfunc("test")
> 
> inner function
> 
> Myfunc test
> 
> 
> 
> cheers
> 
> Wojciech
> 
> >
> 
> > and also with the first example you say x is in the scope when is was 
> > created can you define x in the outer func and refer to it in the inner 
> > func?
> 
> check nonlocal.

Uhn, a local object inside a function
can be passed back in Python.

Of course, a local function is treated
as an object in Python,and the GC is
built-in. 



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


Re: OT: This Swift thing

2014-06-15 Thread CHIN Dihedral
On Wednesday, June 4, 2014 10:53:13 PM UTC+8, Mark H. Harris wrote:
> On 6/4/14 9:24 AM, Skip Montanaro wrote:
> 
> > Surely your local colleagues realize that Python has been around for
> 
> > 20-odd years now, that indentation-based block structure has been
> 
> > there since Day One, and that it's not going to change, right?
> 
> >
> 
>  Yup. Its the primary argument on the side for indentation. "... and 
> 
> don't call me Surely":-)
> 
> 
> 
> > {snip}
> 
> >
> 
> > Why are you people even having this discussion?
> 
> >
> 
> 
> 
>  The topic came up because the C/C++ coders were being encouraged to 
> 
> try Python3 as the language of choice for a new project, and someone 
> 
> said they would never consider Python for a project primary language 
> 
> because of indentation block delimiting. The whole debate, as in most 
> 
> flames, was stupid. The primary paradigm on this topic locally is that 
> 
> indents are bad because malformed or mangled code cannot be reformatted 
> 
> easily (if at all).
> 
> 
> 
>  From my own perspective, if you tell me I need to use END, ok.  If 
> 
> I need to use {} , well ok, and if the BDFL says we use indents here, 
> 
> well that's cool tool.
> 
> 
> 
>  Getting back to Swift, did they choose {} braces because JS uses 
> 
> them, or did they choose {} braces because 'they' think most people will 
> 
> want that style?
> 
> 
> 
> marcus

Well, I think a tool kit such as the 
Pascal to C translator can solve the 
problem. 

Since Python is OOP and functional with
dynamic typing,  a Python to Go or Swift translator can be written in Python. 

Of course some features of Python might be restricted.

We need to chunk out fashion jobs in 
different  commercial platforms to draw attentions from non-programmers
whose roles are to pay for fashion HW/SW products.  






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


Re: Windows automatic rebooting due to faulty code

2014-05-23 Thread CHIN Dihedral
On Saturday, May 24, 2014 12:08:24 AM UTC+8, Ronak Dhakan wrote:
> It is a small file to draw an approximate circle using Turtle. The reboot 
> does not happen consistently. Here is the code: http://pastebin.com/8T3aRCEd
> 
> 
> 
> I was thinking whether there is a way to run python in a virtual environment.

Check colinux or VMWARE.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to implement key of key in python?

2014-05-09 Thread CHIN Dihedral
On Saturday, May 10, 2014 9:22:43 AM UTC+8, eckh...@gmail.com wrote:
> I'm migrating from Perl to Python and unable to identify the equivalent of 
> key of key concept. The following codes run well,
> 
> 
> 
> import csv
>
> 
> 
> 
> attr = {} 
>
> 
>   
>
> 
> with open('test.txt','rb') as tsvin:  
>  
> 
> tsvin = csv.reader(tsvin, delimiter='\t') 
>
> 
>   
>
> 
> for row in tsvin: 
>
> 
> ID = row[1]   
>   
> 
> 
> 
> 
> 
> until:
> 
> attr[ID]['adm3'] = row[2]  
> 
> 
> 
> I then try:
> 
> attr[ID].adm3 = row[2]
> 
> 
> 
> still doesn't work. Some posts suggest using module dict but some do not. I'm 
> a bit confused now. Any suggestions?

Please check your attr as an empty dictionary or so-called a hash in perl.

The syntax of adding a (K,V) pair 
is different between python and perl.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Tutorials for Reorganizing Spreadsheet Data

2014-05-05 Thread CHIN Dihedral
On Wednesday, April 16, 2014 9:50:25 PM UTC+8, joseph...@gmail.com wrote:
> Hello, I'm a high school physics teacher and while I've played with Python 
> enough to make a rock paper scissors program or animation of a bouncing ball 
> (with air resistance!), I've never used it to work with data from a 
> spreadsheet.
> 
> 
> 
> I have a large spreadsheet with a number of different student responses to a 
> weekly prompt in various cells depending on which question they chose to 
> answer. I'd like to organize these responses into something that make it easy 
> for students to look back through their responses over time, and see how 
> they've changed.
> 
> 
> 
> This is obviously possible in Python, but I don't know where to begin 
> learning the details of what I'll need to know to build it. Can anyone give 
> me a specific recommendation of tutorials where I might begin?
> 
> 
> 
> Thanks!
> 
> 
> 
>   Joe

Check the source code here:
http://manns.github.io/pyspread/  and 
http://www.python-excel.org/ .

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


Re: socket client and server in one application?

2014-05-05 Thread CHIN Dihedral
On Monday, May 5, 2014 11:33:38 PM UTC+8, ch...@freeranger.com wrote:
> I have a python script that uses a serial port to read data from an xbee 
> radio and it delivers the data to a socket server.
> 
> 
> 
> Now I need to retrieve the data from a socket client so I can send data out 
> on the common serial port.
> 
> 
> 
> I think I need a combination of threads, queues, socket client and sever.
> 
> 
> 
> Anyone have ideas about how I might frame this out?
> 
> 
> 
> Thanks in advance,
> 
> Chris.
I did this kind of projects in 1999-2002 for taxie call out services in object 
pascal from Borland in paid jobs.

In python, check the urlib.



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


Re: object().__dict__

2014-04-23 Thread CHIN Dihedral
On Wednesday, April 23, 2014 10:21:26 PM UTC+8, Amirouche Boubekki wrote:
> 2014-04-23 15:59 GMT+02:00 Phil Connell :
> 
> 
> 
> On Wed, Apr 23, 2014 at 03:48:32PM +0200, Amirouche Boubekki wrote:
> 
> > 2014-04-23 8:11 GMT+02:00 Cameron Simpson :
> 
> 
> > > Look up the "__slots__" dunder var in the Python doco index:
> 
> > >
> 
> > >   https://docs.python.org/3/glossary.html#term-slots
> 
> > >
> 
> > > You'll see it as a (rarely used, mostly discouraged) way to force a fixed
> 
> > > set of attributes onto a class. As with object, this brings a smaller
> 
> > > memory footprint and faster attribute access, but the price is 
> > > flexibility.
> 
> > >
> 
> >
> 
> > True, still can be the only way to save few MB or... GB without falling
> 
> > back to C or PyPy.
> 
> >
> 
> > Have a look at PyPy to how to save memory (and speed things up) without
> 
> > slots:
> 
> > http://morepypy.blogspot.fr/2010/11/efficiently-implementing-python-objects.html
> 
> 
> 
> Is there any analysis of how this balances increased memory usage from the JIT
> 
> vs the CPython VM (with a reasonable amount of code)?
> 
> 
> 
> I'd thought that one of the main disadvantages of PyPy was drastically
> 
> increased memory usage for any decent-sized program. Would be interested to
> 
> know if this was not the case :)
> 
> 
> 
> I have a similar thought, I don't how that memory consumption increase (a 
> constant? a factor? probably both...)
> 
> but if the program use an absurd amount of memory even in CPython then PyPy 
> will be able to catchup based on comment #1 of a PyPy core dev in 
> http://tech.oyster.com/save-ram-with-python-slots/ see also 
> http://pypy.readthedocs.org/en/latest/interpreter-optimizations.html#dictionary-optimizations
> 
> 
> 
> 
> Still it requires more analysis. When does PyPy trigger the optimization?
> 
>  
> 
> 
> 
> 
> 
> 
> Cheers,
> 
> Phil
> 
> 
> 
> --
> 
> https://mail.python.org/mailman/listinfo/python-list

 The auto-code generation  of valid python codes in PyPy is helpful in CAD/CAM 
and non-idiot robot brains.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why Python 3?

2014-04-20 Thread CHIN Dihedral
On Saturday, April 19, 2014 12:50:09 PM UTC+8, Ethan Furman wrote:
> On 04/18/2014 08:28 PM, Anthony Papillion wrote:
> 
> >
> 
> > What is the general feel of /this/ community? I'm about to start a
> 
> > large scale Python project. Should it be done in 2 or 3? What are the
> 
> > benefits, aside from the 'it's the future' argument?
> 
> 
> 
> This community is also split.  ;)
> 
> 
> 
> Use Python 3 if you can.  The best reason not to is if you have some critical 
> library that you absolutely need and it's 
> 
> not yet available on 3.  In which case, program as if your code base was 
> going to run on both 2 and 3 so you can update 
> 
> easily once your dependency upgrades.
> 
> 
> 
> --
> 
> ~Ethan~

OK, I'll suggest to use Python 2.7X with pytoexe buldled as an executable 
to be called by the shell from Python 3.X for programs that need to mix Python 
2.X and Python 3.X together.
-- 
https://mail.python.org/mailman/listinfo/python-list