Re: Goto

2018-01-02 Thread John Wong
I think the point is there is not much to discuss. Goto is not going to be
added. Furthermore, for every program language you want to translate from
source, you have to find a workaround. Otherwise, your translation will
only work for languages that have goto. Even so the implementation may not
be exact what C goto is. Who knows. Much like in Go - the other day, slice
there has a different behavior to Python’s slice. I brought this up to show
that don’t expect everything to be equal.

John

On Tue, Jan 2, 2018 at 12:35 bartc  wrote:

> On 02/01/2018 15:20, Chris Angelico wrote:
> > On Wed, Jan 3, 2018 at 1:51 AM, bartc  wrote:
>
> >> I like to write code in a simple, clean, universal style that everyone
> can
> >> understand.
> >>
> >> That doesn't mean it has to look like Fortran.
> >
> > Why are you using a Python interpreter then? Why are you here on
> > python-list, talking about Python? There must be SOME reason for using
> > this language rather than another.
>
> I'm more familiar with Python than any other like languages.
>
> If I desperately needed a dynamic language and I couldn't use my own,
> then I would use Python.
>
> But I would need to use it on my own terms, regardless of whether the
> result is 'pythonic'. If the language had 'goto', then I would use it if
> I found it apt.
>
> However, the discussion here is academic, so it doesn't matter who uses
> what.
>
> Apart from anything else, Python is never going to officially adopt
> 'goto'. (Regardless of some version of it being available as an add-on
> library. Most things seem to be.)
>
>
> --
> bartc
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
Sent from Jeff Dean's printf() mobile console
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Multi-Line Strings: A Modest Proposal

2016-08-13 Thread John Wong
On Sat, Aug 13, 2016 at 8:38 PM, Lawrence D’Oliveiro  wrote:

> Python allows a single string literal to cross multiple lines, provided it
> begins and ends with three quote characters, e.g.
>
> s = """this string continues
> on the next line."""
>
> There is a drawback with this: any whitespace at the start of the
> continuation line is included as part of the string:
>
> >>> print(s)
> this string continues
> on the next line.
>
>
I think you meant both trailing characters and starting characters.

The way I solve it, and I still find that extremely ugly, is

s = ("this string continues " +
   "substring continues")

The blackslash is a method I used to do but I start regretting. I have ran
into issue with blackslash before, can't remember but, but most likely with
escaping.

It's ugly when I am in the middle of a deep indented function call. Imagine
I am writing an exception

def foo(...)
  

  raise SomeErrorKindofLong("This is an exception and I need to
write something long {v1} so I need to wrap around it {v2}".format(v1=v1,
v2=v2))

You get the point... by wrapping, I ended up breaking this into multiple
lines. In some cases I would build the string before calling the exception.

That seems a little tangent, but relevant.

The problem with this proposal is that could break existing application.
It's impossible to switch to this convention.

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


Re: Guys, can you please share me some sites where we can practice python programs for beginners and Intermediate.

2016-06-22 Thread John Wong
On Wed, Jun 22, 2016 at 4:45 AM, Nick Sarbicki 
wrote:

> On Wed, Jun 22, 2016 at 9:42 AM Miki Tebeka  wrote:
>
> > IMO you can do that at https://www.codecademy.com/learn/python
> >
>
> Some people might think differently but I wouldn't recommend a python
> course which teaches 2.7 over 3.x.
>
>
pythontutor does support Python 3. Haven't tried CA for a while.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Don't put your software in the public domain

2016-06-01 Thread John Wong
On Wed, Jun 1, 2016 at 4:45 PM, Lawrence D’Oliveiro 
wrote:

> On Thursday, June 2, 2016 at 3:00:05 AM UTC+12, Steven D'Aprano wrote:
> > ... because it is extremely unlikely to work.
>
> Which is why CC0 https://creativecommons.org/publicdomain/zero/1.0/ was
> invented.
> --
>

This does not solve the dependency copyright issue.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python is an Equal Opportunity Programming Language

2016-05-06 Thread John Wong
On Sat, May 7, 2016 at 12:04 AM, Chris Angelico  wrote:
>
>
> In the case of PyCon questions, I fully agree with it; there were
> enough women present that it wasn't a ridiculous suggestion, and it
> encourages people to speak up who might otherwise have kept quiet. But
> just because that worked well, it doesn't mean we should automatically
> enact quotas everywhere, as some sort of "gender/race/culture
> imbalance panacea", because it isn't.
>

I think it is a good call to ask if non-male attendees would be interested
in asking question. I didn't attend those PyCons so I don't know how many
male and female attendees lined up awaiting to ask Guido questions. If
there were 25 male and 1 female standing in the line, while I do admire
Guido (or just about anybody) encouraging more non-male to speak, is it
worth asking whether we place pressure on the females attendees if were to
say "hey look, we got a lot of male attendees asking, please more female
attendees." I totally understand there is a long history of females being
treated as inferior (even in America here!), but too much encouragement or
too eager to seek more females speaking is almost like saying females are
shy and can't speak up without the presence of a heroic voice.

I am a male and I am Asian so I am usually regarded as majority in the tech
world so I don't always feel underrepresented and can be biased here.
Recently I went to some company's website and on the career page I found a
banner photo full of white males and maybe 3-4 females in the pictures,
holding beers having a great smile posing for a group picture. It could be
really genuine, but I felt so uncomfortable immediately because (1) the
ratio of male:female is so out balanced, (2) I felt the company was selling
the "equal opportunity" sloan too hard. What I am saying is don't try so
hard, people will apply job if they want the job, regardless of gender and
ethnicity. Similarly, if females attendees want to ask questions, they
will. We shouldn't broadcast every single time "we gotta have more females
speaking, or more underrepresented people speaking."

When I am hanging out with my friends, whether they are male or female, I
don't really think of he/she. I think of them as friends, as human being,
no need to differentiate whether they are Mexican or Black or Asian. Just
human being. Sexual assault laws in some countries are pretty stupid in the
sense that female sexual assault offender would receive light punishment
compared to female offender. While social and history would justify such
law (because again, males historically dominated women), we still treat
people inferior by gender and ethnicity.

I don't know, this is a sensitive issue. People are either coerced to
believe in one kind of response, or perceive as anti-X if given a different
kind of response.

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


Re: What should Python apps do when asked to show help?

2016-04-28 Thread John Wong
On Thu, Apr 28, 2016 at 1:02 PM, Dan Strohl via Python-list <
python-list@python.org> wrote:

> I would suggest using argparse
> https://docs.python.org/3/library/argparse.html as it handles all of that
> natively... including validating arguments, showing errors, help, etc...
> however, assuming you don't want to;
>
> Totally agree with this approach. Command line should stick with argparse.
Personally I'd stick with argparse and not other open source projects which
is built on argparse (or optparse, the one you don't want to use, but eh
some people decided to do that anyway because of some limitations in
argparse).

In fact you shouldn't need to implement -h/--help when you use argparse. If
a user is going to use the command line, you can almost always assume the
user can use -h/--help, or for those familiar with Linux just provide a man
page.

After all, what you need is a very clear documentation upfront prior to the
installation so your users can refer to that for ultimate help.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is wrong in this example code?

2015-11-12 Thread John Wong
If you are using Python 3 you will need to change xrange to range, but the
error shouldn't be invalid syntax. I remember it should just name name not
found/not defined. So if you are not using Python 3, range and xrange do
still in Python 2 and they have different use case.

So i am really curious how you fixed it. It sounds more like some issue
with space rather, but still glad you solved it somehow.

On Thu, Nov 12, 2015 at 9:07 AM, fl  wrote:

> On Thursday, November 12, 2015 at 8:58:33 AM UTC-5, fl wrote:
> > Hi,
> >
> > I run a code snippet from link:
> > http://www.python-course.eu/inheritance_example.php
> >
> > It is found that there is an error in this loop:
> >
> > for i in xrange(1):
> > x.tick()
> > print(x)
> > SyntaxError: invalid syntax
> >
> >
> > I have modified it to:
> > for i in x range(1):
> > x.tick()
> > print(x)
> > SyntaxError: invalid syntax
> >
> > it still has an error. What could be wrong?
> >
> > Thanks,
> >
> >
> > 
> > class Clock(object):
> >
> > def __init__(self,hours=0, minutes=0, seconds=0):
> > self.__hours = hours
> > self.__minutes = minutes
> > self.__seconds = seconds
> >
> > def set(self,hours, minutes, seconds=0):
> > self.__hours = hours
> > self.__minutes = minutes
> > self.__seconds = seconds
> >
> > def tick(self):
> > """ Time will be advanced by one second """
> > if self.__seconds == 59:
> > self.__seconds = 0
> > if (self.__minutes == 59):
> > self.__minutes = 0
> > self.__hours = 0 if self.__hours==23  else self.__hours+1
> >   else:
> >   self.__minutes += 1;
> >   else:
> > self.__seconds += 1;
> >
> > def display(self):
> > print("%d:%d:%d" % (self.__hours, self.__minutes,
> self.__seconds))
> >
> > def __str__(self):
> > return "%2d:%2d:%2d" % (self.__hours, self.__minutes,
> self.__seconds)
> >
> > x = Clock()
> > print(x)
> > for i in xrange(1):
> > x.tick()
> > print(x)
>
> Solved it by this:
> print(x)
> for i in range(1, 1):
>  x.tick()
> print(x)
>
> Thanks,
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Linux Mint installation of Python 3.5

2015-09-30 Thread John Wong
On Tue, Sep 29, 2015 at 10:37 PM, Mario Figueiredo  wrote:

> Hello everyone,
>
> Under Linux Mint it is not a good idea to just go ahead and replace the
> system installed Python versions and their packages. And yet I wish to
> both update the 3.4 modules and install Python 3.5. I understand that
> for the first I just need to use virtualenv.
>

Late to the party but this goes for every system. Never a good idea to
replace system files.
There are tools out there to manage multiple versions of python, you can
give those a try, otherwise I prefer sticking native solution.

This may not be a Python discussion, but I don't think update-alterantives
works for python right? I've used that for Java. Not that this actually
applies for the usage parent is thinking
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Automating build from source (was: Automating Sphinx generated documentation)

2015-09-18 Thread John Wong
On Fri, Sep 18, 2015 at 2:50 AM, Peter Otten <__pete...@web.de> wrote:

> Ben Finney wrote:
>
> > David Aldrich  writes:
> >
> >> I have setup Sphinx for my Python project. We keep all our code and
> >> documentation in Subversion.
> >
> > It's a good idea to keep *source* files in VCS.
> >
> > The VCS should track only those files that humans edit directly.
>
> Isn't this a case of purity versus practicality? I imagine it might be nice
> to get fairly up-to-date documentation along with your source code checkout
> "for free".


IMO, this is a decision an organization / individual has to make. But
nothing stops anybody from using branch (and tags in hg) to differentiate
pure source and pure build.

On Thu, Sep 17, 2015 at 9:54 PM, Grant Edwards 
 wrote:

> On 2015-09-17, Ben Finney  wrote:
>
> > The VCS should track only those files that humans edit directly.
>
> While I agree that files automatically generated shouldn't be checked
> in to a VCS, I'm in favor of putting key binary files under VCS if
> they are required to do the build.


if you are okay with cloning a huge repository then I don't see a problem.
You could have a separate repository for binary data, after VCS is just a
software implements some smart versioning of an object in some format
stored on somewhere.

I know of no convenient mechanism to reduce size of my .git or my .hg once
I committed my binary in my history. What I would do is provide the script
a URL where you can get your files. Imagine infrastructure as code, I can't
commit my oracle jdk/jre file all the time. I have a huge infrastructure to
manage and it would be GBs to clone. It happened to me once and I regret it.

Thanks.

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


Re: [Tutor] Is context manager the answer to synchronous function calls?

2015-09-16 Thread John Wong
On Wed, Sep 16, 2015 at 7:54 AM, Mark Lawrence 
wrote:

>
> Assuming your (Alan's) guess is correct, and I certainly agree it's
> plausible, I suspect this might be better asked on the main Python mailing
> list, I don't see this as tutor material.
>
> Sorry first time posting to tutor / general list. Usually on TIP list. As
per Mark's recommendation, now posting to python-list@python.org.


On Wed, Sep 16, 2015 at 6:56 AM, Alan Gauld 
wrote:

>
> You don't actually specify but I'm guessing VM
> means Virtual Machine? Is it a specific type
> of VM? eg VMWare/VirtualBox or somesuch, or is
> it more of a sandbox environment like virtualenv?
> That might help us understand the restrictions better.


In my case my underlying functions will use boto (Amazon Web Service's
Python SDK) but I thought to abstract the details away from posting because
as you know I want to simply return an object. But yes, boto will simply
return the call with a response object. For example, to create an RDS
database, the call is returned and I will to query for the status of the
database before I can perform further actions to the instance such as
changing password (which is covered in the modify_vm function call). But
creating VM such as EC2 has an equal synchronous nature.

I would be tempted to use an asynchronous approach with a
> when_ready() function that takes my function as an input
> parameter. You could then run the when_ready in a thread
> or, I suspect, utilize the asyncio or asyncore modules,
> although I haven't tried using them for this kind of
> thing myself.
>
The bottom line is you need to wait for the status to
> change. How you do that wait is up to you but you can
> make it more readable for the user. The easier it is for
> the user the harder it will be for you.
>
>
Sounds like to make it readable and user friendly, also to have separation
of concern, I almost am locked into implementing in OOP style. Imperative
seems to be okay but lack the "shininess."

 Thank you.

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


Re: [Tutor] Is context manager the answer to synchronous function calls?

2015-09-16 Thread John Wong
Ah. Thanks.. I removed the previous code. Please excuse me. I will rewrite
the question so it is clear.

Here is my current solution in an imperative way. My application will work
with AWS boto library to create EC2 instances and RDS instances. Assuming
my API will simply send the request, and return if the request is accepted,
I need to lock until the instance is ready before I can start the next
operation.

def create_vm(.):
# returns vm object

def modify_vm(.):
return new vm object

def get_vm_status(.):
return status


# NOTE: This is obviously a simplified version, but pretty much half
of the code.
def lock_until_ready(conn, get_status_func, _id, max_wait=60):
wait_count = 1
status = get_status_func(conn, _id)
while status != 'available' and wait_count < max_wait:
print("Querying status (attempt {i}): {status}".format(
i=wait_count, status=status))
wait_count += 1
time.sleep(10)
status = get_status_func(conn, _id)


def clone(data_center, image_id, options):

conn = get_connection(data_center)
vm_id = create_vm(conn, image_id, )
lock_until_ready(conn, get_vm_status, vm_id, max_wait=30)
modify_vm(conn, options)
lock_until_ready(conn, get_vm_status, vm_id, max_wait=30)


I hope this doesn't come across as a code review. This works. I made my
lock function extensible and testable, but I feel like there should be a
better more user-friendly way, even in the imperative world in Python. I
thought of context manager because I can do some clean up on entry (verify
the db name has not been taken), and exit (if fail rollback). If you are
familiar with cloudformation, it almost seems like that's what I am doing.
I am writing this because I have custom needs that cloudformation can't do
elegantly without many hops. API is much more flexible for my current task,
FYI.

Any feedback is welcome. Thank you.

John

On Wed, Sep 16, 2015 at 10:53 AM, Chris Angelico <ros...@gmail.com> wrote:

> On Thu, Sep 17, 2015 at 12:34 AM, John Wong <gokoproj...@gmail.com> wrote:
> > Sorry first time posting to tutor / general list. Usually on TIP list. As
> > per Mark's recommendation, now posting to python-list@python.org.
>
> But, sadly, without a lot of context. When you change lists, it's
> helpful to include a lot of extra verbiage so folks who don't follow
> the other list can pick up where you were.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Let child process to run while parent is out (multiprocessing)

2012-07-19 Thread John Wong
def main(...):
build_id = create_build_id(...)
build_stuff
return build_id

Suppose build_stuff compiles a C program. It could take days to finish, and
notify users their builds are ready. I was thinking about using
mutliprocessing to handle the build_stuff.

So here is a sample:

#!/usr/bin/python

import multiprocessing as mp
import time

def build():
print 'I am building HUGE things'
time.sleep(10)

def main():
build_p = mp.Process(name='build process', target=build)
build_p.start()
return 'abcd12345'

if __name__ == '__main__':

v = main()
print v
print 'done'

Here is output:
yeukhon@fermat:~$ python c2.py
abcd12345
done  [now hangs for 10 seconds]
I build things

When I looked at `ps -elf|grep python`, I can see two processes running,
and one of the python c2.py process is `wait`.  But this is not ideal,
especially this is a web app. I can't implement any advanced queue / event
system right now (I use Pylon, I believe I have gevent installed). But just
with multiprocessing, is it possible to send the id first, while running
child in the backgroud?

Right now it hangs there as long as the child process is alive. Any
solutions?

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