ANN: eGenix pyOpenSSL Distribution 0.13.5

2014-10-24 Thread eGenix Team: M.-A. Lemburg

ANNOUNCING

   eGenix.com pyOpenSSL Distribution

 Version 0.13.5


 An easy-to-install and easy-to-use distribution
 of the pyOpenSSL Python interface for OpenSSL -
available for Windows, Mac OS X and Unix platforms


This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-pyOpenSSL-Distribution-0.13.5.html


INTRODUCTION

The eGenix.com pyOpenSSL Distribution includes everything you need to
get started with SSL in Python.

It comes with an easy-to-use installer that includes the most recent
OpenSSL library versions in pre-compiled form, making your application
independent of OS provided OpenSSL libraries:

http://www.egenix.com/products/python/pyOpenSSL/

pyOpenSSL is an open-source Python add-on that allows writing SSL/TLS-
aware network applications as well as certificate management tools:

https://launchpad.net/pyopenssl/

OpenSSL is an open-source implementation of the SSL/TLS protocol:

http://www.openssl.org/


NEWS

This new release of the eGenix.com pyOpenSSL Distribution updates the
included OpenSSL version to the latest OpenSSL 1.0.1h version and adds
a few more context options:

New in OpenSSL
--

 * Updated included OpenSSL libraries from OpenSSL 1.0.1i to
   1.0.1j. See https://www.openssl.org/news/secadv_20141015.txt for a
   complete list of changes. The following fixes are relevant for
   pyOpenSSL applications:

   - CVE-2014-3567: Memory leak in OpenSSL session ticket management.

   - OpenSSL has added support for TLS_FALLBACK_SCSV to allow
 applications to block the ability for a MITM attacker to force a
 protocol downgrade, e.g. to enable a POODLE (CVE-2014-3566)
 attack by forcing a downgrade to SSLv3. This is enabled
 automatically for servers.

   - CVE-2014-3568: OpenSSL configured with no-ssl3 would still
 allow a complete SSL 3.0 handshake to run.

New in pyOpenSSL


 * Dropped zlib support from OpenSSL builds to more easily prevent the
   CRIME attack without having to use special SSL context options.

 * Disabled the SSLv2 support in OpenSSL builds. SSLv2 has long been
   broken and this simplifies writing secure servers/clients.

 * Updated the included CA root certificate bundles to Mozilla's
   2014-08-26 update.

 * Improved cipher list in https_client.py example which prefers the
   newer AES128-GCM and elliptic curve DH over over ciphers.

 * Added new context flag MODE_SEND_FALLBACK_SCSV. Documented
   previously undocumented MODE_RELEASE_BUFFERS and removed
   non-existing MODE_NO_COMPRESSION from the documentation.

 * Added web installer package to the Python Package Index (PyPI)
   which simplifies installation.

 * In addition to the usual ways of installing eGenix pyOpenSSL, we
   have uploaded a web installer to PyPI, so that it is now also
   possible to use one of these installation methods on all supported
   platforms (Windows, Linux, Mac OS X):

   - easy_install egenix-pyopenssl via PyPI
   - pip install egenix-pyopenssl via PyPI
   - egg reference in zc.buildout via PyPI
   - running python setup.py install in the unzipped web installer
 archive directory

   The web installer will automatically detect the platform and choose
   the right binary download package for you. All downloads are
   verified before installation.

 * Resolved a problem with a pyOpenSSL test for certificate
   extensions: OpenSSL 1.0.1i+ wants a signature algorithm to be
   defined when loading PEM certificates.

 * Moved eGenix additions to pyOpenSSL to a new extras/ dir in the
   source distribution.

 * In previous releases, we also added the OpenSSL version number to
   the package version. Since this causes very long version numbers,
   we have dropped the OpenSSL version starting with 0.13.5 and will
   only increase the main version number from now on. In the future,
   we plan to switch to a new version scheme that is compatible with
   our normal version number scheme for products.

pyOpenSSL / OpenSSL Binaries Included
-

In addition to providing sources, we make binaries available that
include both pyOpenSSL and the necessary OpenSSL libraries for all
supported platforms: Windows x86 and x64, Linux x86 and x64, Mac OS X
PPC, x86 and x64.

We've also added egg-file distribution versions of our eGenix.com
pyOpenSSL Distribution for Windows, Linux and Mac OS X to the
available download options. These make setups using e.g. zc.buildout
and other egg-file based installers a lot easier.


DOWNLOADS

The download archives and instructions for installing the 

pytest-2.6.4: bugfix release

2014-10-24 Thread holger krekel
Hi all,

just pushed pytest-2.6.4 to pypi, a small bug fix release.  pytest is a
popular and mature Python testing tool with more than a 1100 tests
against itself, passing on many different interpreters and platforms.
This release is drop-in compatible to 2.5.2 and 2.6.X.  See below for
the changes and see docs at:

http://pytest.org

Thanks to all who contributed, among them:

Bruno Oliveira
Floris Bruynooghe
Dinu Gherman
Anatoly Bubenkoff

best,
holger krekel, merlinux GmbH


2.6.4
--

- Improve assertion failure reporting on iterables, by using ndiff and pprint.

- removed outdated japanese docs from source tree.

- docs for pytest_addhooks hook.  Thanks Bruno Oliveira.

- updated plugin index docs.  Thanks Bruno Oliveira.

- fix issue557: with -k we only allow the old style - for negation
  at the beginning of strings and even that is deprecated.  Use not instead.
  This should allow to pick parametrized tests where - appeared in the 
parameter.

- fix issue604: Escape % character in the assertion message.

- fix issue620: add explanation in the --genscript target about what
  the binary blob means. Thanks Dinu Gherman.

- fix issue614: fixed pastebin support.

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

Support the Python Software Foundation:
http://www.python.org/psf/donations/


devpi-{server-2.1.2,web-2.2.1}: bugfixes, streamlined web templates

2014-10-24 Thread holger krekel

devpi-server-2.1.2 and devpi-web-2.2.1 bring a host of fixes to
the private pypi server system.  You can upgrade without migrating
your data if you run already with devpi-server-2.1.X. 

Find docs as usual at:

http://doc.devpi.net

Many thanks to Florian Schulze who did most of the changes in devpi-web.

Have fun,

holger krekel, merlinux GmbH

devpi-server-2.1.2
--

- fix issue172: avoid traceback when user/index/name/version is accessed.

- fix issue170: ensure that we parse the prospective pip-6.0 user agent
  string properly so that using the username/index url works with pip.
  Thanks Donald Stufft and Florian Schulze.

- fix issue158: redirect to normalized projectname for all GET views.

- fix issue169: change /+status to expose event_serial as the last
  event serial that was processed.  document serial and
  event-serial and also refine internals wrt to event-serial so that
  it means the last serial for which events have been processed


devpi-web-2.2.1
---

- require devpi-server=2.1.2

- fix issue175: use normalized name of projects, so redirects from unnormalized
  names works.  NOTE that if you had issues with documentation uploads
  not appearing because of normalization issues (- or _ appearing 
  in the name for example) you need to re-upload the docs or 
  do a full export/import cycle.  

- fix view when tox results can not be parsed. 

- version.pt: removed code tag around overwrite count.

- macros.pt: added footer tag around the whole footer part.

- version.pt: moved file type, python version and size info from their own
  columns into the file column.

- version.pt: moved history column from before the tox results column to behind
  the tox results.

- version.pt: removed last modified from history column

- version.pt: removed timestamp from replaced action in history column

- version.pt: add link to PyPI page if applicable.

- fix project page view if there are downloads with filenames which can't be
  parsed as packages with version number

- fix notfound-redirect when serving under an outside URL with a sub path


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

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: (test) ? a:b

2014-10-24 Thread ast



48K? Luxury!


ZX81 had an option for 64K
--
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Mark Lawrence

On 22/10/2014 21:30, Seymore4Head wrote:

def nametonumber(name):
 lst=[]
 for x,y in enumerate (name):
 lst=lst.append(y)
 print (lst)
 return (lst)
a=[1-800-getcharter]
print (nametonumber(a))#18004382427837


The syntax for when to use a () and when to use [] still throws me a
curve.

For now, I am trying to end up with a list that has each character in
a as a single item.

I get:
None
None



Following on from the numerous responses you've had here, I've no idea 
if this helps your thought processes but there's only one way for you to 
find out http://www.greenteapress.com/thinkpython/ :)


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: When to use assert

2014-10-24 Thread Steven D'Aprano
Dan Stromberg wrote:

 I like to use assertions and if cond: raise ValueError('foo') a lot.
 
 I think Eiffel may be the poster-child for a language with
 pre-conditions, post-conditions and assertions.

Yes. I don't think Eiffel is the only language with explicit support for
testing invariants, but it's probably the best known one.

https://archive.eiffel.com/doc/online/eiffel50/intro/language/invitation-07.html

Others include Ada2012, Mercury, D, Perl6, Cobra, Clojure, and others. Cobra
is especially interesting as the syntax is heavily influenced by Python's.

http://cobra-language.com/trac/cobra/wiki/Contracts


 I think you're in good company - a lot of developers don't use assertions
 much.

You in this context is Chris Angelico.


 I like assertions, because they tend to stop bugs pretty quickly.  If
 you have 3 functions, one calling another calling another, assertions
 in each can keep you from having to backtrack among them when
 debugging, instead going directly to the problem's source.

Yes, the purpose of assertions is to help errors be discovered as close to
the cause as possible, rather than somewhere much later on. Consider:

addresses = [get_address(name) for name in database]
# ... much later on ...
for i, address in enumerate(addresses):
if some_condition():
addresses[i] = modify(address)
# ... much later on ...
for address in list_of_addresses:
process_non_empty_address(address)

where you can't easily modify or check the get_address() and modify()
functions. If you have a failure in process_non_empty_address, due to a
violation of the address must not be empty invariant, which function is
to blame?

You could wrap them and find out that way:

from somewhere import get_address as _get_addr

def get_address(*args, **kwargs):
result = _get_addr(*args, **kwargs)
if not result:
raise RuntimeError(bug in get_address)
return result


and under some circumstances that's a good strategy, but often you just want
to determine which function is violating the constraint, fix that one, and
leave the other unmodified.

addresses = [get_address(name) for name in database]
assert all(address for address in addresses)
# ... much later on ...
for i, address in enumerate(addresses):
if some_condition():
addresses[i] = modify(address)
assert addresses[i]


will either identify the culprit, or at least prove that neither
get_address() nor modify() are to blame. Because you're using an assertion,
it's easy to leave the asserts in place forever, and disable them by
passing -O to the Python interpreter in production.

[Aside: it would be nice if Python did it the other way around, and require
a --debugging switch to turn assertions on. Oh well.]


 This is the job of a test suite.
 
 Test suites are great, and I can't really question your reliance on
 them.  I love having lots of automated tests.  But for the reason I
 described above, I still like having lots of assertions.

Assertions and test suites are complementary, not in opposition, like belt
and braces. Assertions insure that the code branch will be tested if it is
ever exercised, something test suites can't in general promise. Here's a
toy example:

def some_function(value):
import random
random.seed(value)
if random.random() == 0.25000375:
assert some_condition
else:
pass


Try writing a unit test that guarantees to test the some_condition
branch :-)

[Actually, it's not that hard, if you're willing to monkey-patch the random
module. But you may have reasons for wanting to avoid such drastic
measures.]

I don't know what value will cause some_function() to take the
some_condition branch, but I know that if it ever takes that branch, the
assert will guard it, regardless of whether or not I've written a unit test
to cover that situation.


 You don't pepper your code with
 assertions to the effect that I just pushed something onto my queue,
 it should now have this item in it; you create a test case for it,
 and verify your function there. In the rest of the code, you trust
 that your test suite passes, and don't waste time with assertions.
 
 I wouldn't test that a value was added to a queue immediately after
 adding it.  That's excessive, and may even require an abstraction
 violation.
 
 But if, for example, I have a string with 3 known-good values, I'll
 if/elif/elif/else, and make the else raise an AssertionError.  The
 assertion should never fire, but if the code changes, it could, and if
 there's a typo somewhere, it could then too.

I like this style:

assert x in (a, b, c)
if x == a:
do_this()
elif x == b:
do_that()
else:
assert x == c
do_something_else()


Why do I prefer that? To defend against future code changes. Defensive
programming can defend not only against bugs in the current code, but also
bugs in *future* code. Consider this common case:

# x is either a or b.
if x == a:
do_this()
elif x == b:
do_that()
else:  # x must 

ANN: eGenix pyOpenSSL Distribution 0.13.5

2014-10-24 Thread eGenix Team: M.-A. Lemburg

ANNOUNCING

   eGenix.com pyOpenSSL Distribution

 Version 0.13.5


 An easy-to-install and easy-to-use distribution
 of the pyOpenSSL Python interface for OpenSSL -
available for Windows, Mac OS X and Unix platforms


This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-pyOpenSSL-Distribution-0.13.5.html


INTRODUCTION

The eGenix.com pyOpenSSL Distribution includes everything you need to
get started with SSL in Python.

It comes with an easy-to-use installer that includes the most recent
OpenSSL library versions in pre-compiled form, making your application
independent of OS provided OpenSSL libraries:

http://www.egenix.com/products/python/pyOpenSSL/

pyOpenSSL is an open-source Python add-on that allows writing SSL/TLS-
aware network applications as well as certificate management tools:

https://launchpad.net/pyopenssl/

OpenSSL is an open-source implementation of the SSL/TLS protocol:

http://www.openssl.org/


NEWS

This new release of the eGenix.com pyOpenSSL Distribution updates the
included OpenSSL version to the latest OpenSSL 1.0.1h version and adds
a few more context options:

New in OpenSSL
--

 * Updated included OpenSSL libraries from OpenSSL 1.0.1i to
   1.0.1j. See https://www.openssl.org/news/secadv_20141015.txt for a
   complete list of changes. The following fixes are relevant for
   pyOpenSSL applications:

   - CVE-2014-3567: Memory leak in OpenSSL session ticket management.

   - OpenSSL has added support for TLS_FALLBACK_SCSV to allow
 applications to block the ability for a MITM attacker to force a
 protocol downgrade, e.g. to enable a POODLE (CVE-2014-3566)
 attack by forcing a downgrade to SSLv3. This is enabled
 automatically for servers.

   - CVE-2014-3568: OpenSSL configured with no-ssl3 would still
 allow a complete SSL 3.0 handshake to run.

New in pyOpenSSL


 * Dropped zlib support from OpenSSL builds to more easily prevent the
   CRIME attack without having to use special SSL context options.

 * Disabled the SSLv2 support in OpenSSL builds. SSLv2 has long been
   broken and this simplifies writing secure servers/clients.

 * Updated the included CA root certificate bundles to Mozilla's
   2014-08-26 update.

 * Improved cipher list in https_client.py example which prefers the
   newer AES128-GCM and elliptic curve DH over over ciphers.

 * Added new context flag MODE_SEND_FALLBACK_SCSV. Documented
   previously undocumented MODE_RELEASE_BUFFERS and removed
   non-existing MODE_NO_COMPRESSION from the documentation.

 * Added web installer package to the Python Package Index (PyPI)
   which simplifies installation.

 * In addition to the usual ways of installing eGenix pyOpenSSL, we
   have uploaded a web installer to PyPI, so that it is now also
   possible to use one of these installation methods on all supported
   platforms (Windows, Linux, Mac OS X):

   - easy_install egenix-pyopenssl via PyPI
   - pip install egenix-pyopenssl via PyPI
   - egg reference in zc.buildout via PyPI
   - running python setup.py install in the unzipped web installer
 archive directory

   The web installer will automatically detect the platform and choose
   the right binary download package for you. All downloads are
   verified before installation.

 * Resolved a problem with a pyOpenSSL test for certificate
   extensions: OpenSSL 1.0.1i+ wants a signature algorithm to be
   defined when loading PEM certificates.

 * Moved eGenix additions to pyOpenSSL to a new extras/ dir in the
   source distribution.

 * In previous releases, we also added the OpenSSL version number to
   the package version. Since this causes very long version numbers,
   we have dropped the OpenSSL version starting with 0.13.5 and will
   only increase the main version number from now on. In the future,
   we plan to switch to a new version scheme that is compatible with
   our normal version number scheme for products.

pyOpenSSL / OpenSSL Binaries Included
-

In addition to providing sources, we make binaries available that
include both pyOpenSSL and the necessary OpenSSL libraries for all
supported platforms: Windows x86 and x64, Linux x86 and x64, Mac OS X
PPC, x86 and x64.

We've also added egg-file distribution versions of our eGenix.com
pyOpenSSL Distribution for Windows, Linux and Mac OS X to the
available download options. These make setups using e.g. zc.buildout
and other egg-file based installers a lot easier.


DOWNLOADS

The download archives and instructions for installing the 

Re: I am out of trial and error again Lists

2014-10-24 Thread Mark Lawrence

On 24/10/2014 08:05, Mark Lawrence wrote:

On 22/10/2014 21:30, Seymore4Head wrote:

def nametonumber(name):
 lst=[]
 for x,y in enumerate (name):
 lst=lst.append(y)
 print (lst)
 return (lst)
a=[1-800-getcharter]
print (nametonumber(a))#18004382427837


The syntax for when to use a () and when to use [] still throws me a
curve.

For now, I am trying to end up with a list that has each character in
a as a single item.

I get:
None
None



Following on from the numerous responses you've had here, I've no idea
if this helps your thought processes but there's only one way for you to
find out http://www.greenteapress.com/thinkpython/ :)



And another http://tinyurl.com/k26vjhr

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: When to use assert

2014-10-24 Thread Chris Angelico
On Fri, Oct 24, 2014 at 6:49 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 addresses = [get_address(name) for name in database]
 assert all(address for address in addresses)
 # ... much later on ...
 for i, address in enumerate(addresses):
 if some_condition():
 addresses[i] = modify(address)
 assert addresses[i]


 will either identify the culprit, or at least prove that neither
 get_address() nor modify() are to blame. Because you're using an assertion,
 it's easy to leave the asserts in place forever, and disable them by
 passing -O to the Python interpreter in production.

The first assertion is fine, assuming that the emptiness of your
address corresponds to falsiness as defined in Python. (This could be
safe to assume, if the address is an object that knows how to boolify
itself.) The second assertion then proves that modify() isn't
returning nothing, but that might be better done by sticking the
assertion into modify itself.

And that's what I'm talking about: checking a function's postcondition
with an assert implies putting that assertion after every call, and
anything that you have to do every time you call a function belongs
inside that function. Imagine writing this kind of defensive code, and
then having lots of places that call modify()... and missing the
assert in some of them. Can you trust what you're getting back?

 [Aside: it would be nice if Python did it the other way around, and require
 a --debugging switch to turn assertions on. Oh well.]

Maybe. But unless someone actually tests that their assertions are
being run, there's the risk that they're flying blind and assuming
that it's all happening. There'll be all these lovely checked
comments... or so people think. Nobody ever runs the app with
--debugging, so nobody ever sees anything.

 Assertions and test suites are complementary, not in opposition, like belt
 and braces. Assertions insure that the code branch will be tested if it is
 ever exercised, something test suites can't in general promise. Here's a
 toy example:

 def some_function(value):
 import random
 random.seed(value)
 if random.random() == 0.25000375:
 assert some_condition
 else:
 pass


 Try writing a unit test that guarantees to test the some_condition
 branch :-)

 [Actually, it's not that hard, if you're willing to monkey-patch the random
 module. But you may have reasons for wanting to avoid such drastic
 measures.]

Easy. You craft a test case that passes the right argument, and then
have the test case test itself. You will want to have a script that
figures out what seed value to use:

def find_seed(value):
import random
for seed in range(100): # Restrict to not-too-many tries
random.seed(seed)
if random.random() == value: return seed

I didn't say it'd be efficient to run, but hey, it's easy. I've no
idea how many bits of internal state the default Python RNGs use, but
testing a million seeds took a notable amount of time, so I told it to
fail after that many. (And I didn't find one that gave that result.)

But actually, it would be really simple to monkey-patch. And in any
non-toy situation, there's probably something more significant being
tested here... unless you really are probing a random number generator
or something, in which case you probably know more about its
internals.

 I like this style:

 assert x in (a, b, c)
 if x == a:
 do_this()
 elif x == b:
 do_that()
 else:
 assert x == c
 do_something_else()

If all your branches are simple function calls, I'd be happy with a
KeyError instead of an AssertionError or RuntimeError.

{a:do_this, b:do_that, c:do_something_else}[x]()

I was talking to a student this week who had a long if/elif chain that
translated keywords into values, something like this:

def get_whatever_value(kwd):
if kwd == 'value_should_be_50':
return 50
elif kwd == 'value_wants_to_be_75':
return 75
elif kwd == 'one_hundred':
return 100

There was no 'else' clause, so in the event of an incorrect keyword,
it would return None. Now, I could have advised adding an else
ValueError or an assertion, but my preferred technique here is a
simple dict lookup. Simpler AND guarantees that all inputs are
checked.

 Or is that insufficiently paranoid?

 With good tests, you're probably fine.

 Is it possible to be too paranoid when it comes to tests?

Yeah, it is. I said earlier about checking that len() returns an
integer. The only way[1] for len(some_object) to return a non-integer
is for someone to have shadowed len, and if you're asserting to see if
someone's maliciously shadowing builtins, you *really* need a hobby.
But hey. Maybe asserting *is* your hobby!

ChrisA

[1] Cue the response pointing out some way that it'll return something
else. I wasn't able to break it, though.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (test) ? a:b

2014-10-24 Thread Steven D'Aprano
Marko Rauhamaa wrote:

 BartC b...@freeuk.com:
 
 Ah, but what would

 x = [f, g][cond]()

 produce?

 It will select f or g (which should refer to functions), and call one of
 those depending on cond. That's not a problem.

 The problem is it will still evaluate both f and g,
 
 That's not really the problem. The problem is in readability.


I don't get why that's considered hard to read. We write things like this
all the time:

item = somelist[index]
value = data[key]

Presumably people won't have a problem with:

values = [f(), g(), h()]
value = values[index]

(If they do, they're going to have a bad time with Python.) They probably
won't even mind if we skip the temporary variable:

value = [f(), g(), h()][index]

and if they're experienced with languages that treat functions as
first-class values, they'll be fine with factoring out the function call:

value = [f, g, h][index]()


So why is it hard to read when the index is a flag?

value = [f, g][cond]()


Of course one can write hard-to-read code using any idiom by sheer weight of
complexity or obfuscated naming:

value = [some_function(arg)[23]['key'] or 
 another_function.method((x + y)/(z-x**(y-4)))*
 some_list[get_index(a)].spam(eggs=False, tomato='yum'),
 something.do_this(p|q).get(alpha, beta) ^
 aardvark.bobble(string%s % carrot.gamma(rs)*
 (this  that).fetch(83, 36, when=when or now)
 ][cond or flag or foo(42)-1  17 or bar(b)  thingy(c) or not d]


but re-writing that using ternary if operator won't help one iota. I don't
see why `[a, b][flag]` is inherently less readable than `b if flag else a`.



-- 
Steven

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


Re: (test) ? a:b

2014-10-24 Thread Chris Angelico
On Fri, Oct 24, 2014 at 7:38 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 Of course one can write hard-to-read code using any idiom by sheer weight of
 complexity or obfuscated naming:

 value = [some_function(arg)[23]['key'] or
  another_function.method((x + y)/(z-x**(y-4)))*
  some_list[get_index(a)].spam(eggs=False, tomato='yum'),
  something.do_this(p|q).get(alpha, beta) ^
  aardvark.bobble(string%s % carrot.gamma(rs)*
  (this  that).fetch(83, 36, when=when or now)
  ][cond or flag or foo(42)-1  17 or bar(b)  thingy(c) or not d]


I can see where your problem is. It is a cardinal error in readability
to have (x + y) followed by z-x. No wonder it's hard to read.

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


Re: (test) ? a:b

2014-10-24 Thread Marko Rauhamaa
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info:

 So why is it hard to read when the index is a flag?

 value = [f, g][cond]()

So, subjectively, which syntax would you prefer:

if j  10:
j += 1
else:
j = 3

or:

j = j + 1 if j  10 else 3

or:

j = (lambda: 3, lambda: j + 1)[j  10]()


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


Re: setuptools + data_files = 2

2014-10-24 Thread luc2
On 2014-10-23, Simon Kennedy sffjun...@gmail.com wrote:

 If you're creating an sdist then you'll need to create a MANIFEST.in
 file in the same folder as setup.py with the following contents

 include share/test_file.txt

 If you're creating a bdist (egg or wheel) the parameter name you need
 is

 package_data={'share': [share/test_file.txt]},

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


Re: (test) ? a:b

2014-10-24 Thread Steven D'Aprano
Marko Rauhamaa wrote:

 Steven D'Aprano steve+comp.lang.pyt...@pearwood.info:
 
 So why is it hard to read when the index is a flag?

 value = [f, g][cond]()
 
 So, subjectively, which syntax would you prefer:

Depends on what else the code is doing. But my personal preference is a red
herring: you didn't say that you liked or preferred one version over
the other, you said that the problem with the [f, g][cond] idiom is
readability, implying that it is hard to read. I'm not asking for your
personal preference, I'm asking for justification for your suggestion that
it is hard to read.


 if j  10:
 j += 1
 else:
 j = 3
 
 or:
 
 j = j + 1 if j  10 else 3
 
 or:
 
 j = (lambda: 3, lambda: j + 1)[j  10]()

Certainly not the third one. That's needlessly obfuscated for the sake of
premature optimization. This version is much better, and probably not only
simpler and easier to read but probably more efficient too:

j = (3, j + 1)[j  10]



-- 
Steven

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


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Thu, 23 Oct 2014 21:56:31 -0700 (PDT), Rustom Mody
rustompm...@gmail.com wrote:

On Thursday, October 23, 2014 10:33:57 PM UTC+5:30, Seymore4Head wrote:
 On Thu, 23 Oct 2014 15:55:35 + (UTC), Denis McMahon wrote:
 
 On Thu, 23 Oct 2014 10:04:56 -0400, Seymore4Head wrote:
 
  On Thu, 23 Oct 2014 09:15:16 + (UTC), Denis McMahon wrote:
 
 Try the following 3 commands at the console:
 
 You obviously didn't, so I'll try again. Try each of the following three 
 commands in the python console at the  prompt.
 
 1) 10
 10
 
 2) range(10)
 range(0, 10)
 
 3) str(range(10))
 'range(0, 10)'
 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 
 Show *and* describe the output in each case. Describing the output that 
 you see is actually the key here, as it will allow us to assess whether 
 you understand what you are actually seeing or not, and if you don't 
 understand the output you see in the console, then we need to fix that 
 very fundamental and basic issue before moving on to more complex stuff!
 
  Ok Thanks
 
 You were expected to answer the question in the original. I have now set 
 it as a clearer and more specific task.
 
 If you're not going to do these things that are intended to help you 
 learn some of the basic features of the language, then I and everyone 
 else here that has so far been attempting to help you are wasting our 
 time.
 
 I did try them.  I may have missed replying your to your specific
 comment, but I tried them.
 
 BTW str(range (10)) does work with Python 2 which is where I may have
 got the idea.  I happened to be using Python 3 at the time I tried to
 implement it.  It is a little confusing jumping back and forth, but
 for the moment, I am going to tough it out.
 
 I do appreciate all the help too.

Hi Seymore!

Happy to see that you are moving on from
reading much; understanding nothing; thrashing

to

reading a bit; understanding a bit
[And thanks to Denis to getting you out of your confusion-hole]

So heres a small additional question set that I promise will more than repay
you your time.

Better done in python 2. But if you use python3, below replace
range(10)
with
list(range(10))

So now in the python console, please try

a.
 range(10)

and 

b.
 print (range(10))

And then post back (without consulting google!!)¹

1. Are they same or different?

2. If same, how come different expressions are same?

3. If different whats the difference?

4. [Most important]: When would you prefer which?

=
¹ Actually its ok to consult google AFTER you try

I do get the difference.  I don't actually use Python 2.  I use
CodeSkulptor.  I do have Python 3 installed.  Actually I have Python 2
installed but IDLE defaults to Python 3.  So it is a pain to actually
load Python 2.

Range(10) stores the min max values and loads each number in between
when needed.  Ian explained that very clearly.

I tried list(range(10)  I thought that would work in Python 3.  It
didn't.  I spent quite a bit of time last night trying to come up with
the right combination of str and int commands to make range(10) work
with my simple example.   It didn't.  I am pretty frustrated.  I am
just skipping that little bit of code for the moment.

Thanks everyone for your suggestions.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Fri, 24 Oct 2014 08:05:01 +0100, Mark Lawrence
breamore...@yahoo.co.uk wrote:

On 22/10/2014 21:30, Seymore4Head wrote:
 def nametonumber(name):
  lst=[]
  for x,y in enumerate (name):
  lst=lst.append(y)
  print (lst)
  return (lst)
 a=[1-800-getcharter]
 print (nametonumber(a))#18004382427837


 The syntax for when to use a () and when to use [] still throws me a
 curve.

 For now, I am trying to end up with a list that has each character in
 a as a single item.

 I get:
 None
 None


Following on from the numerous responses you've had here, I've no idea 
if this helps your thought processes but there's only one way for you to 
find out http://www.greenteapress.com/thinkpython/ :)

I have at least 10 ebooks.  I will get around to reading them soon.
http://i.imgur.com/rpOcKP8.jpg

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


Re: I am out of trial and error again Lists

2014-10-24 Thread Chris Angelico
On Sat, Oct 25, 2014 at 1:38 AM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 I tried list(range(10)  I thought that would work in Python 3.  It
 didn't.

This is your problem: You say it didn't work. That is almost *never*
the right thing to say or to think. What happened when you tried that?
Did you get a SyntaxError because of the omitted close parenthesis?
Did the interpreter prompt for more input? Did a velociraptor come out
of nowhere and try to kill you [1]?

When you come back to python-list, you should say exactly what you did
and exactly what happened, not I tried X and it didn't work. Copy
and paste from your interactive session - do NOT retype, because you
introduce new errors. It's very hard to help you when you don't
explain what you're doing, and just keep on telling us how frustrated
you are.

ChrisA

[1] http://xkcd.com/292/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Fri, 24 Oct 2014 09:12:28 +0100, Mark Lawrence
breamore...@yahoo.co.uk wrote:

On 24/10/2014 08:05, Mark Lawrence wrote:
 On 22/10/2014 21:30, Seymore4Head wrote:
 def nametonumber(name):
  lst=[]
  for x,y in enumerate (name):
  lst=lst.append(y)
  print (lst)
  return (lst)
 a=[1-800-getcharter]
 print (nametonumber(a))#18004382427837


 The syntax for when to use a () and when to use [] still throws me a
 curve.

 For now, I am trying to end up with a list that has each character in
 a as a single item.

 I get:
 None
 None


 Following on from the numerous responses you've had here, I've no idea
 if this helps your thought processes but there's only one way for you to
 find out http://www.greenteapress.com/thinkpython/ :)


And another http://tinyurl.com/k26vjhr

Google.   I have heard of that.  :)  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Sat, 25 Oct 2014 01:51:41 +1100, Chris Angelico ros...@gmail.com
wrote:

On Sat, Oct 25, 2014 at 1:38 AM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 I tried list(range(10)  I thought that would work in Python 3.  It
 didn't.

This is your problem: You say it didn't work. That is almost *never*
the right thing to say or to think. What happened when you tried that?
Did you get a SyntaxError because of the omitted close parenthesis?
Did the interpreter prompt for more input? Did a velociraptor come out
of nowhere and try to kill you [1]?

I understand that it makes it easier for you if I can describe better
the error I get, but by the time I ask for help here I have tried many
different things to get the error to go away.

I will try in the future to do better at this.  For now, I am just
putting that exercise behind me.  I do try to find out how to do
things before asking first.

I tried so many things last night, I had to go back to an old message
to get code that worked again.

Thanks

When you come back to python-list, you should say exactly what you did
and exactly what happened, not I tried X and it didn't work. Copy
and paste from your interactive session - do NOT retype, because you
introduce new errors. It's very hard to help you when you don't
explain what you're doing, and just keep on telling us how frustrated
you are.

ChrisA

[1] http://xkcd.com/292/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Chris Angelico
On Sat, Oct 25, 2014 at 2:04 AM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 I understand that it makes it easier for you if I can describe better
 the error I get, but by the time I ask for help here I have tried many
 different things to get the error to go away.

That's part of the problem. You let yourself get frustrated and
confused, and you still have no idea what you're doing. Ask sooner, if
you have to; or develop the discipline to keep track of what you do
and what happens. But regardless of what actually happens, it didn't
work is not a helpful thing to say.

Trust me, making it easier for us will make everything easier for you
too. Even if we were to never answer a single question of yours ever
again, learning to read error messages will benefit you more than you
can imagine.

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


Re: I am out of trial and error again Lists

2014-10-24 Thread Rustom Mody
On Friday, October 24, 2014 8:11:12 PM UTC+5:30, Seymore4Head wrote:
 On Thu, 23 Oct 2014 21:56:31 -0700 (PDT), Rustom Mody wrote:
 
 On Thursday, October 23, 2014 10:33:57 PM UTC+5:30, Seymore4Head wrote:
  On Thu, 23 Oct 2014 15:55:35 + (UTC), Denis McMahon wrote:
  
  On Thu, 23 Oct 2014 10:04:56 -0400, Seymore4Head wrote:
  
   On Thu, 23 Oct 2014 09:15:16 + (UTC), Denis McMahon wrote:
  
  Try the following 3 commands at the console:
  
  You obviously didn't, so I'll try again. Try each of the following three 
  commands in the python console at the  prompt.
  
  1) 10
  10
  
  2) range(10)
  range(0, 10)
  
  3) str(range(10))
  'range(0, 10)'
  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  
  Show *and* describe the output in each case. Describing the output that 
  you see is actually the key here, as it will allow us to assess whether 
  you understand what you are actually seeing or not, and if you don't 
  understand the output you see in the console, then we need to fix that 
  very fundamental and basic issue before moving on to more complex stuff!
  
   Ok Thanks
  
  You were expected to answer the question in the original. I have now set 
  it as a clearer and more specific task.
  
  If you're not going to do these things that are intended to help you 
  learn some of the basic features of the language, then I and everyone 
  else here that has so far been attempting to help you are wasting our 
  time.
  
  I did try them.  I may have missed replying your to your specific
  comment, but I tried them.
  
  BTW str(range (10)) does work with Python 2 which is where I may have
  got the idea.  I happened to be using Python 3 at the time I tried to
  implement it.  It is a little confusing jumping back and forth, but
  for the moment, I am going to tough it out.
  
  I do appreciate all the help too.
 
 Hi Seymore!
 
 Happy to see that you are moving on from
 reading much; understanding nothing; thrashing
 
 to
 
 reading a bit; understanding a bit
 [And thanks to Denis to getting you out of your confusion-hole]
 
 So heres a small additional question set that I promise will more than repay
 you your time.
 
 Better done in python 2. But if you use python3, below replace
 range(10)
 with
 list(range(10))

Other details skipped

 
 I tried list(range(10)  I thought that would work in Python 3.  It
 didn't.  I spent quite a bit of time last night trying to come up with
 the right combination of str and int commands to make range(10) work
 with my simple example.   It didn't.  I am pretty frustrated.  I am
 just skipping that little bit of code for the moment.

I asked you to try
list(range(10))

Did you try EXACTLY (cut-paste) that?

You are claiming to have tried
list(range(10)

Thats one closing parenthesis less

The interaction with your version would go something like this:
[Two versions 
The KeyboardInterrupt comes from giving a control-C
Dunno what happens in codeskulptor
]

 list(range(10)
... 
... 
... 
... )
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 list(range(10)
... 
KeyboardInterrupt


 
 Thanks everyone for your suggestions.

1. You are reading too much
2. Trying to hard

Think of riding a bicycle.
Cant do it by reading many books on cycling -- thats 1.
Nor by holding the handle so hard you tremble -- thats 2.

Just relax a bit...
And take small steps

Chill... as Chris joked, no monster in the computer (or on this list!)


 Range(10) stores the min max values and loads each number in between
 when needed.

It loads?? As in 'load-up-a-van'??

When you see:

 10
10

1. Does someone (a clerk maybe) in the computer count to 10?
2. Or do you, seeing that interaction, count to 10?
   [If you do, replace the 10 by 1000]
3. Or do you, remember what it means to count to 10 without having to do it?

Now go back to your statement about 'loading' and find a better verb
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread giacomo boffi
ERRATA CORRIGE:

 many different circumstances, by the very, very helpful folks of clp.
  many different circumstances, by the very, very helpful folks of clpy

-- 
sapete contare fino a venticinque?
Olimpia Milano Jugoplastika Split Partizan Beograd
Roberto Premier Duska Ivanovic Zarko Paspalj
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Ian Kelly
On Fri, Oct 24, 2014 at 9:56 AM, Rustom Mody rustompm...@gmail.com wrote:
 Range(10) stores the min max values and loads each number in between
 when needed.

 It loads?? As in 'load-up-a-van'??

As in loads into memory.

 When you see:

 10
 10

 1. Does someone (a clerk maybe) in the computer count to 10?
 2. Or do you, seeing that interaction, count to 10?
[If you do, replace the 10 by 1000]
 3. Or do you, remember what it means to count to 10 without having to do it?

I don't understand why you think any of these are implied by the word load.

 Now go back to your statement about 'loading' and find a better verb

I presume he used load because that was the word I used in my
explanatory post about the difference between range in Python 2 and
Python 3 yesterday.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Fri, 24 Oct 2014 08:56:31 -0700 (PDT), Rustom Mody
rustompm...@gmail.com wrote:

On Friday, October 24, 2014 8:11:12 PM UTC+5:30, Seymore4Head wrote:
 On Thu, 23 Oct 2014 21:56:31 -0700 (PDT), Rustom Mody wrote:
 
 On Thursday, October 23, 2014 10:33:57 PM UTC+5:30, Seymore4Head wrote:
  On Thu, 23 Oct 2014 15:55:35 + (UTC), Denis McMahon wrote:
  
  On Thu, 23 Oct 2014 10:04:56 -0400, Seymore4Head wrote:
  
   On Thu, 23 Oct 2014 09:15:16 + (UTC), Denis McMahon wrote:
  
  Try the following 3 commands at the console:
  
  You obviously didn't, so I'll try again. Try each of the following three 
  commands in the python console at the  prompt.
  
  1) 10
  10
  
  2) range(10)
  range(0, 10)
  
  3) str(range(10))
  'range(0, 10)'
  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  
  Show *and* describe the output in each case. Describing the output that 
  you see is actually the key here, as it will allow us to assess whether 
  you understand what you are actually seeing or not, and if you don't 
  understand the output you see in the console, then we need to fix that 
  very fundamental and basic issue before moving on to more complex stuff!
  
   Ok Thanks
  
  You were expected to answer the question in the original. I have now set 
  it as a clearer and more specific task.
  
  If you're not going to do these things that are intended to help you 
  learn some of the basic features of the language, then I and everyone 
  else here that has so far been attempting to help you are wasting our 
  time.
  
  I did try them.  I may have missed replying your to your specific
  comment, but I tried them.
  
  BTW str(range (10)) does work with Python 2 which is where I may have
  got the idea.  I happened to be using Python 3 at the time I tried to
  implement it.  It is a little confusing jumping back and forth, but
  for the moment, I am going to tough it out.
  
  I do appreciate all the help too.
 
 Hi Seymore!
 
 Happy to see that you are moving on from
 reading much; understanding nothing; thrashing
 
 to
 
 reading a bit; understanding a bit
 [And thanks to Denis to getting you out of your confusion-hole]
 
 So heres a small additional question set that I promise will more than repay
 you your time.
 
 Better done in python 2. But if you use python3, below replace
 range(10)
 with
 list(range(10))

Other details skipped

 
 I tried list(range(10)  I thought that would work in Python 3.  It
 didn't.  I spent quite a bit of time last night trying to come up with
 the right combination of str and int commands to make range(10) work
 with my simple example.   It didn't.  I am pretty frustrated.  I am
 just skipping that little bit of code for the moment.

I asked you to try
list(range(10))

Did you try EXACTLY (cut-paste) that?

You are claiming to have tried
list(range(10)

Thats one closing parenthesis less

The interaction with your version would go something like this:
[Two versions 
The KeyboardInterrupt comes from giving a control-C
Dunno what happens in codeskulptor
]

 list(range(10)
... 
... 
... 
... )
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 list(range(10)
... 
KeyboardInterrupt


 
 Thanks everyone for your suggestions.

1. You are reading too much
2. Trying to hard

Think of riding a bicycle.
Cant do it by reading many books on cycling -- thats 1.
Nor by holding the handle so hard you tremble -- thats 2.

Just relax a bit...
And take small steps

Chill... as Chris joked, no monster in the computer (or on this list!)


 Range(10) stores the min max values and loads each number in between
 when needed.

It loads?? As in 'load-up-a-van'??

When you see:

 10
10

1. Does someone (a clerk maybe) in the computer count to 10?
2. Or do you, seeing that interaction, count to 10?
   [If you do, replace the 10 by 1000]
3. Or do you, remember what it means to count to 10 without having to do it?

Now go back to your statement about 'loading' and find a better verb

If I could explain to you why something doesn't work then I could fix
it myself.  I don't understand why it doesn't work.  The best I can do
is repost the code. 

When I use list(range(10)) I get:
Traceback (most recent call last):
  File C:/Functions/name to number digit.py, line 37, in module
print (nametonumber(a))#1800 438 2427 837
  File C:/Functions/name to number digit.py, line 10, in
nametonumber
if y in lst(range(1,10)):
TypeError: 'list' object is not callable

All the lines I have commented out work.  Trying to use
list(range(10)) doesn't.  (Python 3)
http://i.imgur.com/LtiCyZS.jpg

It doesn't work.
It's broke.  :)
I don't know what else to say.

import string
def nametonumber(name):
lst=[]
nx=[]
digit=[]
digit=.join(str(i) for i in range(10))
for x in name:
lst.append(x)
for y in (lst):
if y in lst(range(1,10)):
#if y in 1234567890:
#if y.isdigit():
#if y in digit:   
#if y in string.digits:
nx.append(y)
if y in  -():

Re: I am out of trial and error again Lists

2014-10-24 Thread Albert-Jan Roskam

-
On Fri, Oct 24, 2014 5:56 PM CEST Rustom Mody wrote:

On Friday, October 24, 2014 8:11:12 PM UTC+5:30, Seymore4Head wrote:
 On Thu, 23 Oct 2014 21:56:31 -0700 (PDT), Rustom Mody wrote:
 
 On Thursday, October 23, 2014 10:33:57 PM UTC+5:30, Seymore4Head wrote:
  On Thu, 23 Oct 2014 15:55:35 + (UTC), Denis McMahon wrote:
  
  On Thu, 23 Oct 2014 10:04:56 -0400, Seymore4Head wrote:
  
   On Thu, 23 Oct 2014 09:15:16 + (UTC), Denis McMahon wrote:
  
  Try the following 3 commands at the console:
  
  You obviously didn't, so I'll try again. Try each of the following three 
  commands in the python console at the  prompt.
  
  1) 10
  10
  
  2) range(10)
  range(0, 10)
  
  3) str(range(10))
  'range(0, 10)'
  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  
  Show *and* describe the output in each case. Describing the output that 
  you see is actually the key here, as it will allow us to assess whether 
  you understand what you are actually seeing or not, and if you don't 
  understand the output you see in the console, then we need to fix that 
  very fundamental and basic issue before moving on to more complex stuff!
  
   Ok Thanks
  
  You were expected to answer the question in the original. I have now set 
  it as a clearer and more specific task.
  
  If you're not going to do these things that are intended to help you 
  learn some of the basic features of the language, then I and everyone 
  else here that has so far been attempting to help you are wasting our 
  time.
  
  I did try them.  I may have missed replying your to your specific
  comment, but I tried them.
  
  BTW str(range (10)) does work with Python 2 which is where I may have
  got the idea.  I happened to be using Python 3 at the time I tried to
  implement it.  It is a little confusing jumping back and forth, but
  for the moment, I am going to tough it out.


u0_a100@condor_umts:/ $ python
Python 3.2.2 (default, Jun 23 2014, 00:13:13)
[GCC 4.8] on linux-armv7l
Type help, copyright, credits or license for more information.
 list(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]



  I do appreciate all the help too.
 
 Hi Seymore!
 
 Happy to see that you are moving on from
 reading much; understanding nothing; thrashing
 
 to
 
 reading a bit; understanding a bit
 [And thanks to Denis to getting you out of your confusion-hole]
 
 So heres a small additional question set that I promise will more than repay
 you your time.
 
 Better done in python 2. But if you use python3, below replace
 range(10)
 with
 list(range(10))

Other details skipped


1. You are reading too much
2. Trying to hard

Think of riding a bicycle.
Cant do it by reading many books on cycling -- thats 1.
Nor by holding the handle so hard you tremble -- thats 2.

Just relax a bit...
And take small steps

Chill... as Chris joked, no monster in the computer (or on this list!)

+1 for that remark. Talking about chill: grab a couple of beers (suggest: 
sixpack) and enjoy an evening of Python!




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


Re: I am out of trial and error again Lists

2014-10-24 Thread Chris Angelico
On Sat, Oct 25, 2014 at 3:37 AM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 When I use list(range(10)) I get:
 Traceback (most recent call last):
   File C:/Functions/name to number digit.py, line 37, in module
 print (nametonumber(a))#1800 438 2427 837
   File C:/Functions/name to number digit.py, line 10, in
 nametonumber
 if y in lst(range(1,10)):
 TypeError: 'list' object is not callable

Now, finally, you're showing us an actual line of code and an actual
traceback. And from here, we can see that you misspelled list.
That's why it isn't working.

Several people have told you to use the interactive interpreter. Please do so.

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


Re: I am out of trial and error again Lists

2014-10-24 Thread Rustom Mody
Totally befuddled myself!

Are you deliberately misspelling list to lst
and hoping the error will go away.

And Puh LEESE
dont post screen shots of good ol ASCII text
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Rustom Mody
On Friday, October 24, 2014 10:18:12 PM UTC+5:30, Chris Angelico wrote:
 On Sat, Oct 25, 2014 at 3:37 AM, Seymore4Head wrote:
  When I use list(range(10)) I get:
  Traceback (most recent call last):
File C:/Functions/name to number digit.py, line 37, in module
  print (nametonumber(a))#1800 438 2427 837
File C:/Functions/name to number digit.py, line 10, in
  nametonumber
  if y in lst(range(1,10)):
  TypeError: 'list' object is not callable
 
 Now, finally, you're showing us an actual line of code and an actual
 traceback. And from here, we can see that you misspelled list.
 That's why it isn't working.
 
 Several people have told you to use the interactive interpreter. Please do so.
 
 ChrisA

Right.
Good.
Sorry for being impatient Seymore

You are now making progress
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Ian Kelly
On Fri, Oct 24, 2014 at 10:37 AM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 If I could explain to you why something doesn't work then I could fix
 it myself.  I don't understand why it doesn't work.  The best I can do
 is repost the code.

You don't need to be able to explain why it doesn't work. You just
need to be able to explain what you expected it to do and what it
actually did. Posting the code and the traceback that you get is a
fine start.

 if y in lst(range(1,10)):

The name of the builtin is list. It's a function* that takes an
argument and uses it to construct a list, which it returns.

lst is the name of some specific list that you're using in your
code. It's not a function, which is why the error is complaining that
it isn't callable.

*Actually it's a type object, and calling it causes an instance of the
type to be constructed, but for all intents and purposes here it works
exactly like a function.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Sat, 25 Oct 2014 03:47:51 +1100, Chris Angelico ros...@gmail.com
wrote:

On Sat, Oct 25, 2014 at 3:37 AM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 When I use list(range(10)) I get:
 Traceback (most recent call last):
   File C:/Functions/name to number digit.py, line 37, in module
 print (nametonumber(a))#1800 438 2427 837
   File C:/Functions/name to number digit.py, line 10, in
 nametonumber
 if y in lst(range(1,10)):
 TypeError: 'list' object is not callable

Now, finally, you're showing us an actual line of code and an actual
traceback. And from here, we can see that you misspelled list.
That's why it isn't working.

Several people have told you to use the interactive interpreter. Please do so.

ChrisA

Actually I was a little frustrated when I added that line back in as
the other lines all work.
Using list(range(10)) Doesn't throw an error but it doesn't work.

http://i.imgur.com/DTc5zoL.jpg

The interpreter.   I don't know how to use that either.

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


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Fri, 24 Oct 2014 09:54:23 -0700 (PDT), Rustom Mody
rustompm...@gmail.com wrote:

Totally befuddled myself!

Are you deliberately misspelling list to lst
and hoping the error will go away.

And Puh LEESE
dont post screen shots of good ol ASCII text

I didn't do that on purpose.  I make a lot of typing mistakes.
Sorry
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Rustom Mody
On Friday, October 24, 2014 10:06:47 PM UTC+5:30, Ian wrote:
 On Fri, Oct 24, 2014 at 9:56 AM, Rustom Mody wrote:
  Range(10) stores the min max values and loads each number in between
  when needed.
 
  It loads?? As in 'load-up-a-van'??
 
 As in loads into memory.
 
  When you see:
 
  10
  10
 
  1. Does someone (a clerk maybe) in the computer count to 10?
  2. Or do you, seeing that interaction, count to 10?
 [If you do, replace the 10 by 1000]
  3. Or do you, remember what it means to count to 10 without having to do it?
 
 I don't understand why you think any of these are implied by the word load.
 
  Now go back to your statement about 'loading' and find a better verb
 
 I presume he used load because that was the word I used in my
 explanatory post about the difference between range in Python 2 and
 Python 3 yesterday.

I would be very surprised (Ian) if we had any essential disagreement on this
subject. [JFTR I see nothing wrong with your explanation]

I would also be (pleasantly) surprised if Seymore were to benefit by these
discussions at this stage.

So is it ok if we drop it here (or start a new thread)?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Chris Angelico
On Sat, Oct 25, 2014 at 4:05 AM, Ian Kelly ian.g.ke...@gmail.com wrote:
 The name of the builtin is list. It's a function* that takes an
 argument and uses it to construct a list, which it returns.

 *Actually it's a type object, and calling it causes an instance of the
 type to be constructed, but for all intents and purposes here it works
 exactly like a function.

It's callable, that's all that matters.

callable(object) - bool
Return whether the object is callable (i.e., some kind of function).

:)

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


Re: I am out of trial and error again Lists

2014-10-24 Thread Albert Visser
On Fri, 24 Oct 2014 19:03:47 +0200, Seymore4Head  
Seymore4Head@hotmail.invalid wrote:




http://i.imgur.com/DTc5zoL.jpg

The interpreter.   I don't know how to use that either.



It's what's on the left hand side of your screenshot. You can simply type  
Python statements following the  prompt and hit enter to examine the  
result, instead of pushing F5 to run your code


--
Vriendelijke groeten / Kind regards,

Albert Visser

Using Opera's mail client: http://www.opera.com/mail/
--
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Rustom Mody
On Friday, October 24, 2014 10:37:45 PM UTC+5:30, Seymore4Head wrote:
 On Fri, 24 Oct 2014 09:54:23 -0700 (PDT), Rustom Mody wrote:
 
 Totally befuddled myself!
 
 Are you deliberately misspelling list to lst
 and hoping the error will go away.
 
 And Puh LEESE
 dont post screen shots of good ol ASCII text
 
 I didn't do that on purpose.  I make a lot of typing mistakes.
 Sorry

Right
No sweat!

I was genuinely asking:
- Did you mis-spell list as lst?
- Or did you go thrashing (Steven gave a picturesque description)
just changing things until the error went?

[Believe you me, I do the same when I am in a strange place and I
am searching for something in my (suit|brief)case
]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (test) ? a:b

2014-10-24 Thread Dan Stromberg
On Fri, Oct 24, 2014 at 1:38 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 I don't get why that's considered hard to read.

 So why is it hard to read when the index is a flag?

 value = [f, g][cond]()

It's clear to you, it's clear to me, but is it clear to everyone?  I
very much doubt it.

Also, you've gone to the trouble of def'ing two functions here - you
may as well do a function for the if/else.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (test) ? a:b

2014-10-24 Thread Tobiah

On 10/22/2014 01:29 AM, ast wrote:

Hello

Is there in Python something like:

j = (j = 10) ? 3 : j+1;

as in C language ?

thx



Out of all of the replies, I don't think anyone
actually offered the answer:


a if condition else b



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


Re: (test) ? a:b

2014-10-24 Thread Chris Angelico
On Sat, Oct 25, 2014 at 4:23 AM, Tobiah t...@tobiah.org wrote:
 Out of all of the replies, I don't think anyone
 actually offered the answer:


 a if condition else b

Jean-Michel did, the very first response.

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


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Fri, 24 Oct 2014 19:18:12 +0200, Albert Visser
albert.vis...@gmail.com wrote:

On Fri, 24 Oct 2014 19:03:47 +0200, Seymore4Head  
Seymore4Head@hotmail.invalid wrote:


 http://i.imgur.com/DTc5zoL.jpg

 The interpreter.   I don't know how to use that either.


It's what's on the left hand side of your screenshot. You can simply type  
Python statements following the  prompt and hit enter to examine the  
result, instead of pushing F5 to run your code

I guess I am confusing the Interpreter with the debugger.  Someone
suggested I use the Interpreter to step through line by line.
I don't know how to do that.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Rustom Mody
On Friday, October 24, 2014 10:55:44 PM UTC+5:30, Seymore4Head wrote:
 On Fri, 24 Oct 2014 19:18:12 +0200, Albert Visser wrote:
 
 On Fri, 24 Oct 2014 19:03:47 +0200, Seymore4Head  wrote:
 
 
  http://i.imgur.com/DTc5zoL.jpg
 
  The interpreter.   I don't know how to use that either.
 
 
 It's what's on the left hand side of your screenshot. You can simply type  
 Python statements following the  prompt and hit enter to examine the  
 result, instead of pushing F5 to run your code
 
 I guess I am confusing the Interpreter with the debugger.  Someone
 suggested I use the Interpreter to step through line by line.
 I don't know how to do that.

Dont bother with the debugger just yet.
For most python programmers, sticking a few print statements 
(expressions in python 3) in adroitly is good enough.*

For now best if you concentrate on
1. What are the features of python -- the language
2. What are the standard data types and functions -- the libraries
3. How to use and jump between the two windows of your screenshot most
   effectively. What you should and should not type in each etc

* One neat trick of using the print to debug.
Say you have a line like

nx.append(2)

and nx is not getting to be what you expect.
Change it to

nx.append(2); print(nx)

Cleaning up the print after debugging is easier than if you use a
separate line like so

nx.append(2)
print(nx)

[I think I learnt this trick from Mark Lawrence]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Ian Kelly
On Fri, Oct 24, 2014 at 11:03 AM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 Actually I was a little frustrated when I added that line back in as
 the other lines all work.
 Using list(range(10)) Doesn't throw an error but it doesn't work.

 http://i.imgur.com/DTc5zoL.jpg

 The interpreter.   I don't know how to use that either.

Try both of these in the interpreter, and observe the difference:

7 in range(10)

7 in range(10)

Do you understand what the difference between 7 and 7 is?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (-1)**1000

2014-10-24 Thread Dave Angel
Terry Reedy tjre...@udel.edu Wrote in message:
 On 10/22/2014 4:27 AM, ast wrote:
 Hello

 If i am writing (-1)**1000 on a python program, will the
 interpreter do (-1)*(-1)*...*(-1) or something clever ?
 
 The answer depends on the implementation.
 
 In fact i have (-1)**N with N an integer potentially big.

 I do some tests that suggest that Python is clever
 
 You probably mean CPython is clever.  Other implementations may or may 
 not have the same optimizations.
 

I can see several potential optimizations for x**n. Some the
 CPython implementation does, others I don't know.

First, if the two component numbers are known at function compile
 time, evaluate at compile time.

If x is known at compile time to be -1, and n is a non negative
 integer, just mask the bottom bit of n, and choose -1 or 1 based
 on that bit. There are other special values, such as 0,
 -1.

If x is a power of 2, and n is an int, then count the trailing
 zeroes of x, multiply that by n, and construct a (binary) value
 with that many trailing zeroes.

If x isn't any of the above, but n is a postive int, use the
 square and multiply technique, which is of order log(n). In
 particular for n of a billion (10**9), it can be done in about 60
 multiplies.

If neither value is known at compile time,  it may still be worth
 checking for some of these, such as the last. And if x is a
 float,  the last optimization has the advantage of improving
 accuracy as well as speed.

-- 
DaveA

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


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Fri, 24 Oct 2014 10:42:08 -0700 (PDT), Rustom Mody
rustompm...@gmail.com wrote:

On Friday, October 24, 2014 10:55:44 PM UTC+5:30, Seymore4Head wrote:
 On Fri, 24 Oct 2014 19:18:12 +0200, Albert Visser wrote:
 
 On Fri, 24 Oct 2014 19:03:47 +0200, Seymore4Head  wrote:
 
 
  http://i.imgur.com/DTc5zoL.jpg
 
  The interpreter.   I don't know how to use that either.
 
 
 It's what's on the left hand side of your screenshot. You can simply type  
 Python statements following the  prompt and hit enter to examine the  
 result, instead of pushing F5 to run your code
 
 I guess I am confusing the Interpreter with the debugger.  Someone
 suggested I use the Interpreter to step through line by line.
 I don't know how to do that.

Dont bother with the debugger just yet.
For most python programmers, sticking a few print statements 
(expressions in python 3) in adroitly is good enough.*

For now best if you concentrate on
1. What are the features of python -- the language
2. What are the standard data types and functions -- the libraries
3. How to use and jump between the two windows of your screenshot most
   effectively. What you should and should not type in each etc

* One neat trick of using the print to debug.
Say you have a line like

nx.append(2)

and nx is not getting to be what you expect.
Change it to

nx.append(2); print(nx)

Cleaning up the print after debugging is easier than if you use a
separate line like so

nx.append(2)
print(nx)

[I think I learnt this trick from Mark Lawrence]

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


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Fri, 24 Oct 2014 11:52:15 -0600, Ian Kelly ian.g.ke...@gmail.com
wrote:

On Fri, Oct 24, 2014 at 11:03 AM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 Actually I was a little frustrated when I added that line back in as
 the other lines all work.
 Using list(range(10)) Doesn't throw an error but it doesn't work.

 http://i.imgur.com/DTc5zoL.jpg

 The interpreter.   I don't know how to use that either.

Try both of these in the interpreter, and observe the difference:

7 in range(10)

7 in range(10)

Do you understand what the difference between 7 and 7 is?

I do understand that.  7 is a number and 7 is a string.
What my question was...and still is...is why
Python 3 fails when I try using
y=1 800 get charter

y in range str(range(10))
should work because y is a string and str(range(10)) should be
y in str(1) fails.
It doesn't give an error it's just not True when y is a number.

These hints are just not working.  I am too thick for hints. :)
If you could use it in the code, I might understand.
The other work arounds that were posted work.
I have used them.  str(range(10)) doesn't work.

import string
def nametonumber(name):
lst=[]
nx=[]
digit=[]
digit=.join(str(i) for i in range(10))
for x in name:
lst.append(x)
for y in (lst):
if y in list(range(1,10)):
#if y in 1234567890:
#if y.isdigit():
#if y in digit:   
#if y in string.digits:
nx.append(y)
if y in  -():
nx.append(y)
if y in abc:
nx.append(2)
if y in def:
nx.append(3)
if y in ghi:
nx.append(4)
if y in jkl:
nx.append(5)
if y in mno:
nx.append(6)
if y in pqrs:
nx.append(7)
if y in tuv:
nx.append(8)
if y in wxyz:
nx.append(9)
number=.join(e for e in nx)
return number
a=1-800-getcharter
print (nametonumber(a))#1800 438 2427 837
a=1-800-leo laporte
print (nametonumber(a))
a=1 800 dialaho
print (nametonumber(a))

Please


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


Re: (test) ? a:b

2014-10-24 Thread Ian Kelly
On Fri, Oct 24, 2014 at 7:07 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info  if j  10:
 j += 1
 else:
 j = 3

 or:

 j = j + 1 if j  10 else 3

 or:

 j = (lambda: 3, lambda: j + 1)[j  10]()

 Certainly not the third one. That's needlessly obfuscated for the sake of
 premature optimization. This version is much better, and probably not only
 simpler and easier to read but probably more efficient too:

 j = (3, j + 1)[j  10]

Yes, the lambda approach falls victim to function calls being slow.

$ python3 -m timeit -s j = 5 if j  10: j+=1
 else: j=3
1000 loops, best of 3: 0.0513 usec per loop
$ python3 -m timeit -s j = 5 j = j + 1 if j  10 else 3
1000 loops, best of 3: 0.0519 usec per loop
$ python3 -m timeit -s j = 5 j = (3, j+1)[j  10]
1000 loops, best of 3: 0.0883 usec per loop
$ python3 -m timeit -s j = 5 j = (lambda: 3, lambda: j+1)[j  10]()
100 loops, best of 3: 0.312 usec per loop
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
I meant to type:
if y in range(1,10) doesn't work.
Sigh
Sorry

On Fri, 24 Oct 2014 14:15:13 -0400, Seymore4Head
Seymore4Head@Hotmail.invalid wrote:

On Fri, 24 Oct 2014 11:52:15 -0600, Ian Kelly ian.g.ke...@gmail.com
wrote:

On Fri, Oct 24, 2014 at 11:03 AM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 Actually I was a little frustrated when I added that line back in as
 the other lines all work.
 Using list(range(10)) Doesn't throw an error but it doesn't work.

 http://i.imgur.com/DTc5zoL.jpg

 The interpreter.   I don't know how to use that either.

Try both of these in the interpreter, and observe the difference:

7 in range(10)

7 in range(10)

Do you understand what the difference between 7 and 7 is?

I do understand that.  7 is a number and 7 is a string.
What my question was...and still is...is why
Python 3 fails when I try using
y=1 800 get charter

y in range str(range(10))
should work because y is a string and str(range(10)) should be
y in str(1) fails.
It doesn't give an error it's just not True when y is a number.

These hints are just not working.  I am too thick for hints. :)
If you could use it in the code, I might understand.
The other work arounds that were posted work.
I have used them.  str(range(10)) doesn't work.

import string
def nametonumber(name):
lst=[]
nx=[]
digit=[]
digit=.join(str(i) for i in range(10))
for x in name:
lst.append(x)
for y in (lst):
if y in list(range(1,10)):
#if y in 1234567890:
#if y.isdigit():
#if y in digit:   
#if y in string.digits:
nx.append(y)
if y in  -():
nx.append(y)
if y in abc:
nx.append(2)
if y in def:
nx.append(3)
if y in ghi:
nx.append(4)
if y in jkl:
nx.append(5)
if y in mno:
nx.append(6)
if y in pqrs:
nx.append(7)
if y in tuv:
nx.append(8)
if y in wxyz:
nx.append(9)
number=.join(e for e in nx)
return number
a=1-800-getcharter
print (nametonumber(a))#1800 438 2427 837
a=1-800-leo laporte
print (nametonumber(a))
a=1 800 dialaho
print (nametonumber(a))

Please

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


Re: I am out of trial and error again Lists

2014-10-24 Thread Mark Lawrence

On 24/10/2014 18:03, Seymore4Head wrote:


Actually I was a little frustrated when I added that line back in as
the other lines all work.
Using list(range(10)) Doesn't throw an error but it doesn't work.

http://i.imgur.com/DTc5zoL.jpg

The interpreter.   I don't know how to use that either.



You've stated that you can use google so why not try it to find out 
about the interpreter?  Or simply navigate to docs.python.org and see 
what the contents or index tell you?  Failing that carry on charging 
around like a headless chicken and hope that the extremely patient folk 
here keep helping you out.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: (test) ? a:b

2014-10-24 Thread Tobiah

On 10/24/2014 10:27 AM, Chris Angelico wrote:

On Sat, Oct 25, 2014 at 4:23 AM, Tobiah t...@tobiah.org wrote:

Out of all of the replies, I don't think anyone
actually offered the answer:


 a if condition else b


Jean-Michel did, the very first response.

ChrisA




I had to search for it.  For some reason Thunderbird
didn't thread that message with all the others.


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


Re: I am out of trial and error again Lists

2014-10-24 Thread Mark Lawrence

On 24/10/2014 19:20, Seymore4Head wrote:

I meant to type:
if y in range(1,10) doesn't work.
Sigh
Sorry



How many more times, state what you expect to happen and what actually 
happens.  doesn't work is useless.  Please read this http://sscce.org/


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: (test) ? a:b

2014-10-24 Thread Marko Rauhamaa
Ian Kelly ian.g.ke...@gmail.com:

 j = (lambda: 3, lambda: j + 1)[j  10]()

 Yes, the lambda approach falls victim to function calls being slow.

That's just a deficiency in the compiler. There's nothing there that
prevents the optimizer from translating the expression into the
equivalent if statement.

At any rate, the only issue at hand is the obviousness of the idiom. You
should generally choose the syntax that best expresses the logic of the
program.


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


Re: I am out of trial and error again Lists

2014-10-24 Thread sohcahtoa82
On Friday, October 24, 2014 11:17:53 AM UTC-7, Seymore4Head wrote:
 On Fri, 24 Oct 2014 11:52:15 -0600, Ian Kelly ian.g.ke...@gmail.com
 wrote:
 
 On Fri, Oct 24, 2014 at 11:03 AM, Seymore4Head
 Seymore4Head@hotmail.invalid wrote:
  Actually I was a little frustrated when I added that line back in as
  the other lines all work.
  Using list(range(10)) Doesn't throw an error but it doesn't work.
 
  http://i.imgur.com/DTc5zoL.jpg
 
  The interpreter.   I don't know how to use that either.
 
 Try both of these in the interpreter, and observe the difference:
 
 7 in range(10)
 
 7 in range(10)
 
 Do you understand what the difference between 7 and 7 is?
 
 I do understand that.  7 is a number and 7 is a string.
 What my question was...and still is...is why
 Python 3 fails when I try using
 y=1 800 get charter
 
 y in range str(range(10))
 should work because y is a string and str(range(10)) should be
 y in str(1) fails.
 It doesn't give an error it's just not True when y is a number.
 
 These hints are just not working.  I am too thick for hints. :)
 If you could use it in the code, I might understand.
 The other work arounds that were posted work.
 I have used them.  str(range(10)) doesn't work.
 
 import string
 def nametonumber(name):
 lst=[]
 nx=[]
 digit=[]
 digit=.join(str(i) for i in range(10))
 for x in name:
 lst.append(x)
 for y in (lst):
 if y in list(range(1,10)):
 #if y in 1234567890:
 #if y.isdigit():
 #if y in digit:   
 #if y in string.digits:
 nx.append(y)
 if y in  -():
 nx.append(y)
 if y in abc:
 nx.append(2)
 if y in def:
 nx.append(3)
 if y in ghi:
 nx.append(4)
 if y in jkl:
 nx.append(5)
 if y in mno:
 nx.append(6)
 if y in pqrs:
 nx.append(7)
 if y in tuv:
 nx.append(8)
 if y in wxyz:
 nx.append(9)
 number=.join(e for e in nx)
 return number
 a=1-800-getcharter
 print (nametonumber(a))#1800 438 2427 837
 a=1-800-leo laporte
 print (nametonumber(a))
 a=1 800 dialaho
 print (nametonumber(a))
 
 Please

Your code here is actually pretty close to a correct answer.  Just a few things 
to consider...

- Why are you converting your name string to a list?  It is unnecessary.  When 
you do for y in some string, then y will still be single characters on each 
iteration of the loop.

- if y in string.digits should work fine.

- if y in list(range(1,10) won't work for two reasons: First, it creates a 
list of numbers, not strings.  Second, even if it did, it would be missing the 
0 digit.

- At the end, when you convert your list to a string, you don't need to use 
list comprehension, since nx is already a list.  number = .join(nx) should 
work fine.

Also, in general, you need to stop and slow down and think like a programmer.  
If you get an error, your instinct shouldn't be to just hack at it to make the 
error go away.  Look at the error and try to make sense of it.  Learn what the 
error means and try to fix the core problem.

And for @#$%'s sake...stop saying It isn't working and not elaborating.  
You've been told by every other post in this thread to show us what you did and 
what the error was.  You've also been told to *NOT* retype what you see and to 
copy/paste your code and the error because when you make a typo when copying, 
we might see a problem that doesn't exist and then you just get more confused.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Fri, 24 Oct 2014 19:40:39 +0100, Mark Lawrence
breamore...@yahoo.co.uk wrote:

On 24/10/2014 19:20, Seymore4Head wrote:
 I meant to type:
 if y in range(1,10) doesn't work.
 Sigh
 Sorry


How many more times, state what you expect to happen and what actually 
happens.  doesn't work is useless.  Please read this http://sscce.org/

Good suggestion.
OK  how is this?
It doesn't print what I expect.
Does it print what you expect?

name=123-xyz-abc
for x in name:
if x in range(10):
print (Range,(x))
if x in str(range(10)):
print (String range,(x))

http://i.imgur.com/EGKUpAb.jpg
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Fri, 24 Oct 2014 11:57:12 -0700 (PDT), sohcahto...@gmail.com wrote:

On Friday, October 24, 2014 11:17:53 AM UTC-7, Seymore4Head wrote:
 On Fri, 24 Oct 2014 11:52:15 -0600, Ian Kelly ian.g.ke...@gmail.com
 wrote:
 
 On Fri, Oct 24, 2014 at 11:03 AM, Seymore4Head
 Seymore4Head@hotmail.invalid wrote:
  Actually I was a little frustrated when I added that line back in as
  the other lines all work.
  Using list(range(10)) Doesn't throw an error but it doesn't work.
 
  http://i.imgur.com/DTc5zoL.jpg
 
  The interpreter.   I don't know how to use that either.
 
 Try both of these in the interpreter, and observe the difference:
 
 7 in range(10)
 
 7 in range(10)
 
 Do you understand what the difference between 7 and 7 is?
 
 I do understand that.  7 is a number and 7 is a string.
 What my question was...and still is...is why
 Python 3 fails when I try using
 y=1 800 get charter
 
 y in range str(range(10))
 should work because y is a string and str(range(10)) should be
 y in str(1) fails.
 It doesn't give an error it's just not True when y is a number.
 
 These hints are just not working.  I am too thick for hints. :)
 If you could use it in the code, I might understand.
 The other work arounds that were posted work.
 I have used them.  str(range(10)) doesn't work.
 
 import string
 def nametonumber(name):
 lst=[]
 nx=[]
 digit=[]
 digit=.join(str(i) for i in range(10))
 for x in name:
 lst.append(x)
 for y in (lst):
 if y in list(range(1,10)):
 #if y in 1234567890:
 #if y.isdigit():
 #if y in digit:   
 #if y in string.digits:
 nx.append(y)
 if y in  -():
 nx.append(y)
 if y in abc:
 nx.append(2)
 if y in def:
 nx.append(3)
 if y in ghi:
 nx.append(4)
 if y in jkl:
 nx.append(5)
 if y in mno:
 nx.append(6)
 if y in pqrs:
 nx.append(7)
 if y in tuv:
 nx.append(8)
 if y in wxyz:
 nx.append(9)
 number=.join(e for e in nx)
 return number
 a=1-800-getcharter
 print (nametonumber(a))#1800 438 2427 837
 a=1-800-leo laporte
 print (nametonumber(a))
 a=1 800 dialaho
 print (nametonumber(a))
 
 Please

Your code here is actually pretty close to a correct answer.  Just a few 
things to consider...

- Why are you converting your name string to a list?  It is unnecessary.  When 
you do for y in some string, then y will still be single characters on 
each iteration of the loop.

- if y in string.digits should work fine.

- if y in list(range(1,10) won't work for two reasons: First, it creates a 
list of numbers, not strings.  Second, even if it did, it would be missing the 
0 digit.

- At the end, when you convert your list to a string, you don't need to use 
list comprehension, since nx is already a list.  number = .join(nx) should 
work fine.

Also, in general, you need to stop and slow down and think like a programmer.  
If you get an error, your instinct shouldn't be to just hack at it to make the 
error go away.  Look at the error and try to make sense of it.  Learn what the 
error means and try to fix the core problem.

And for @#$%'s sake...stop saying It isn't working and not elaborating.  
You've been told by every other post in this thread to show us what you did 
and what the error was.  You've also been told to *NOT* retype what you see 
and to copy/paste your code and the error because when you make a typo when 
copying, we might see a problem that doesn't exist and then you just get more 
confused.

Ok  I think I may have the question you guys are looking for.
I just posted it.
See above.

But it's still broke.  :( 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread sohcahtoa82
On Friday, October 24, 2014 12:12:10 PM UTC-7, Seymore4Head wrote:
 On Fri, 24 Oct 2014 11:57:12 -0700 (PDT), sohcahto...@gmail.com wrote:
 
 On Friday, October 24, 2014 11:17:53 AM UTC-7, Seymore4Head wrote:
  On Fri, 24 Oct 2014 11:52:15 -0600, Ian Kelly ian.g.ke...@gmail.com
  wrote:
  
  On Fri, Oct 24, 2014 at 11:03 AM, Seymore4Head
  Seymore4Head@hotmail.invalid wrote:
   Actually I was a little frustrated when I added that line back in as
   the other lines all work.
   Using list(range(10)) Doesn't throw an error but it doesn't work.
  
   http://i.imgur.com/DTc5zoL.jpg
  
   The interpreter.   I don't know how to use that either.
  
  Try both of these in the interpreter, and observe the difference:
  
  7 in range(10)
  
  7 in range(10)
  
  Do you understand what the difference between 7 and 7 is?
  
  I do understand that.  7 is a number and 7 is a string.
  What my question was...and still is...is why
  Python 3 fails when I try using
  y=1 800 get charter
  
  y in range str(range(10))
  should work because y is a string and str(range(10)) should be
  y in str(1) fails.
  It doesn't give an error it's just not True when y is a number.
  
  These hints are just not working.  I am too thick for hints. :)
  If you could use it in the code, I might understand.
  The other work arounds that were posted work.
  I have used them.  str(range(10)) doesn't work.
  
  import string
  def nametonumber(name):
  lst=[]
  nx=[]
  digit=[]
  digit=.join(str(i) for i in range(10))
  for x in name:
  lst.append(x)
  for y in (lst):
  if y in list(range(1,10)):
  #if y in 1234567890:
  #if y.isdigit():
  #if y in digit:   
  #if y in string.digits:
  nx.append(y)
  if y in  -():
  nx.append(y)
  if y in abc:
  nx.append(2)
  if y in def:
  nx.append(3)
  if y in ghi:
  nx.append(4)
  if y in jkl:
  nx.append(5)
  if y in mno:
  nx.append(6)
  if y in pqrs:
  nx.append(7)
  if y in tuv:
  nx.append(8)
  if y in wxyz:
  nx.append(9)
  number=.join(e for e in nx)
  return number
  a=1-800-getcharter
  print (nametonumber(a))#1800 438 2427 837
  a=1-800-leo laporte
  print (nametonumber(a))
  a=1 800 dialaho
  print (nametonumber(a))
  
  Please
 
 Your code here is actually pretty close to a correct answer.  Just a few 
 things to consider...
 
 - Why are you converting your name string to a list?  It is unnecessary.  
 When you do for y in some string, then y will still be single characters 
 on each iteration of the loop.
 
 - if y in string.digits should work fine.
 
 - if y in list(range(1,10) won't work for two reasons: First, it creates a 
 list of numbers, not strings.  Second, even if it did, it would be missing 
 the 0 digit.
 
 - At the end, when you convert your list to a string, you don't need to use 
 list comprehension, since nx is already a list.  number = .join(nx) should 
 work fine.
 
 Also, in general, you need to stop and slow down and think like a 
 programmer.  If you get an error, your instinct shouldn't be to just hack at 
 it to make the error go away.  Look at the error and try to make sense of 
 it.  Learn what the error means and try to fix the core problem.
 
 And for @#$%'s sake...stop saying It isn't working and not elaborating.  
 You've been told by every other post in this thread to show us what you did 
 and what the error was.  You've also been told to *NOT* retype what you see 
 and to copy/paste your code and the error because when you make a typo when 
 copying, we might see a problem that doesn't exist and then you just get 
 more confused.
 
 Ok  I think I may have the question you guys are looking for.
 I just posted it.
 See above.
 
 But it's still broke.  :(

str(range(10)) doesn't do what you think it does.

Run 'print(str(range(10)))' and look at what you get.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Fri, 24 Oct 2014 12:25:33 -0700 (PDT), sohcahto...@gmail.com wrote:

On Friday, October 24, 2014 12:12:10 PM UTC-7, Seymore4Head wrote:
 On Fri, 24 Oct 2014 11:57:12 -0700 (PDT), sohcahto...@gmail.com wrote:
 
 On Friday, October 24, 2014 11:17:53 AM UTC-7, Seymore4Head wrote:
  On Fri, 24 Oct 2014 11:52:15 -0600, Ian Kelly ian.g.ke...@gmail.com
  wrote:
  
  On Fri, Oct 24, 2014 at 11:03 AM, Seymore4Head
  Seymore4Head@hotmail.invalid wrote:
   Actually I was a little frustrated when I added that line back in as
   the other lines all work.
   Using list(range(10)) Doesn't throw an error but it doesn't work.
  
   http://i.imgur.com/DTc5zoL.jpg
  
   The interpreter.   I don't know how to use that either.
  
  Try both of these in the interpreter, and observe the difference:
  
  7 in range(10)
  
  7 in range(10)
  
  Do you understand what the difference between 7 and 7 is?
  
  I do understand that.  7 is a number and 7 is a string.
  What my question was...and still is...is why
  Python 3 fails when I try using
  y=1 800 get charter
  
  y in range str(range(10))
  should work because y is a string and str(range(10)) should be
  y in str(1) fails.
  It doesn't give an error it's just not True when y is a number.
  
  These hints are just not working.  I am too thick for hints. :)
  If you could use it in the code, I might understand.
  The other work arounds that were posted work.
  I have used them.  str(range(10)) doesn't work.
  
  import string
  def nametonumber(name):
  lst=[]
  nx=[]
  digit=[]
  digit=.join(str(i) for i in range(10))
  for x in name:
  lst.append(x)
  for y in (lst):
  if y in list(range(1,10)):
  #if y in 1234567890:
  #if y.isdigit():
  #if y in digit:   
  #if y in string.digits:
  nx.append(y)
  if y in  -():
  nx.append(y)
  if y in abc:
  nx.append(2)
  if y in def:
  nx.append(3)
  if y in ghi:
  nx.append(4)
  if y in jkl:
  nx.append(5)
  if y in mno:
  nx.append(6)
  if y in pqrs:
  nx.append(7)
  if y in tuv:
  nx.append(8)
  if y in wxyz:
  nx.append(9)
  number=.join(e for e in nx)
  return number
  a=1-800-getcharter
  print (nametonumber(a))#1800 438 2427 837
  a=1-800-leo laporte
  print (nametonumber(a))
  a=1 800 dialaho
  print (nametonumber(a))
  
  Please
 
 Your code here is actually pretty close to a correct answer.  Just a few 
 things to consider...
 
 - Why are you converting your name string to a list?  It is unnecessary.  
 When you do for y in some string, then y will still be single 
 characters on each iteration of the loop.
 
 - if y in string.digits should work fine.
 
 - if y in list(range(1,10) won't work for two reasons: First, it creates 
 a list of numbers, not strings.  Second, even if it did, it would be 
 missing the 0 digit.
 
 - At the end, when you convert your list to a string, you don't need to use 
 list comprehension, since nx is already a list.  number = .join(nx) 
 should work fine.
 
 Also, in general, you need to stop and slow down and think like a 
 programmer.  If you get an error, your instinct shouldn't be to just hack 
 at it to make the error go away.  Look at the error and try to make sense 
 of it.  Learn what the error means and try to fix the core problem.
 
 And for @#$%'s sake...stop saying It isn't working and not elaborating.  
 You've been told by every other post in this thread to show us what you did 
 and what the error was.  You've also been told to *NOT* retype what you see 
 and to copy/paste your code and the error because when you make a typo when 
 copying, we might see a problem that doesn't exist and then you just get 
 more confused.
 
 Ok  I think I may have the question you guys are looking for.
 I just posted it.
 See above.
 
 But it's still broke.  :(

str(range(10)) doesn't do what you think it does.

Run 'print(str(range(10)))' and look at what you get.

Yeah, I know that.  My question is why?
The answer was that Python 3 only stores the min and max values but
you can still iterate over them.
I don't think that means what I think it means.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread sohcahtoa82
On Friday, October 24, 2014 12:36:23 PM UTC-7, Seymore4Head wrote:
 On Fri, 24 Oct 2014 12:25:33 -0700 (PDT), sohcahto...@gmail.com wrote:
 
 On Friday, October 24, 2014 12:12:10 PM UTC-7, Seymore4Head wrote:
  On Fri, 24 Oct 2014 11:57:12 -0700 (PDT), sohcahto...@gmail.com wrote:
  
  On Friday, October 24, 2014 11:17:53 AM UTC-7, Seymore4Head wrote:
   On Fri, 24 Oct 2014 11:52:15 -0600, Ian Kelly ian.g.ke...@gmail.com
   wrote:
   
   On Fri, Oct 24, 2014 at 11:03 AM, Seymore4Head
   Seymore4Head@hotmail.invalid wrote:
Actually I was a little frustrated when I added that line back in as
the other lines all work.
Using list(range(10)) Doesn't throw an error but it doesn't work.
   
http://i.imgur.com/DTc5zoL.jpg
   
The interpreter.   I don't know how to use that either.
   
   Try both of these in the interpreter, and observe the difference:
   
   7 in range(10)
   
   7 in range(10)
   
   Do you understand what the difference between 7 and 7 is?
   
   I do understand that.  7 is a number and 7 is a string.
   What my question was...and still is...is why
   Python 3 fails when I try using
   y=1 800 get charter
   
   y in range str(range(10))
   should work because y is a string and str(range(10)) should be
   y in str(1) fails.
   It doesn't give an error it's just not True when y is a number.
   
   These hints are just not working.  I am too thick for hints. :)
   If you could use it in the code, I might understand.
   The other work arounds that were posted work.
   I have used them.  str(range(10)) doesn't work.
   
   import string
   def nametonumber(name):
   lst=[]
   nx=[]
   digit=[]
   digit=.join(str(i) for i in range(10))
   for x in name:
   lst.append(x)
   for y in (lst):
   if y in list(range(1,10)):
   #if y in 1234567890:
   #if y.isdigit():
   #if y in digit:   
   #if y in string.digits:
   nx.append(y)
   if y in  -():
   nx.append(y)
   if y in abc:
   nx.append(2)
   if y in def:
   nx.append(3)
   if y in ghi:
   nx.append(4)
   if y in jkl:
   nx.append(5)
   if y in mno:
   nx.append(6)
   if y in pqrs:
   nx.append(7)
   if y in tuv:
   nx.append(8)
   if y in wxyz:
   nx.append(9)
   number=.join(e for e in nx)
   return number
   a=1-800-getcharter
   print (nametonumber(a))#1800 438 2427 837
   a=1-800-leo laporte
   print (nametonumber(a))
   a=1 800 dialaho
   print (nametonumber(a))
   
   Please
  
  Your code here is actually pretty close to a correct answer.  Just a few 
  things to consider...
  
  - Why are you converting your name string to a list?  It is unnecessary.  
  When you do for y in some string, then y will still be single 
  characters on each iteration of the loop.
  
  - if y in string.digits should work fine.
  
  - if y in list(range(1,10) won't work for two reasons: First, it 
  creates a list of numbers, not strings.  Second, even if it did, it would 
  be missing the 0 digit.
  
  - At the end, when you convert your list to a string, you don't need to 
  use list comprehension, since nx is already a list.  number = .join(nx) 
  should work fine.
  
  Also, in general, you need to stop and slow down and think like a 
  programmer.  If you get an error, your instinct shouldn't be to just hack 
  at it to make the error go away.  Look at the error and try to make sense 
  of it.  Learn what the error means and try to fix the core problem.
  
  And for @#$%'s sake...stop saying It isn't working and not elaborating. 
   You've been told by every other post in this thread to show us what you 
  did and what the error was.  You've also been told to *NOT* retype what 
  you see and to copy/paste your code and the error because when you make a 
  typo when copying, we might see a problem that doesn't exist and then you 
  just get more confused.
  
  Ok  I think I may have the question you guys are looking for.
  I just posted it.
  See above.
  
  But it's still broke.  :(
 
 str(range(10)) doesn't do what you think it does.
 
 Run 'print(str(range(10)))' and look at what you get.
 
 Yeah, I know that.  My question is why?
 The answer was that Python 3 only stores the min and max values but
 you can still iterate over them.
 I don't think that means what I think it means.

You can iterate over them pretty much just means you can use them as the 
source of a 'for' loop.  But in your case, when you're calling 'for y in 
str(range(10))', you're not using 'range(10)' as the source of your loop, 
you're using the result of a str() function call, and you're calling str() on 
range(), which doesn't return a concrete value in Python 3.  If you try to 
print a range(), you're just getting a string containing your original call to 
range.

And that's why you're seeing 

Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Fri, 24 Oct 2014 12:55:19 -0700 (PDT), sohcahto...@gmail.com wrote:

On Friday, October 24, 2014 12:36:23 PM UTC-7, Seymore4Head wrote:
 On Fri, 24 Oct 2014 12:25:33 -0700 (PDT), sohcahto...@gmail.com wrote:
 
 On Friday, October 24, 2014 12:12:10 PM UTC-7, Seymore4Head wrote:
  On Fri, 24 Oct 2014 11:57:12 -0700 (PDT), sohcahto...@gmail.com wrote:
  
  On Friday, October 24, 2014 11:17:53 AM UTC-7, Seymore4Head wrote:
   On Fri, 24 Oct 2014 11:52:15 -0600, Ian Kelly ian.g.ke...@gmail.com
   wrote:
   
   On Fri, Oct 24, 2014 at 11:03 AM, Seymore4Head
   Seymore4Head@hotmail.invalid wrote:
Actually I was a little frustrated when I added that line back in as
the other lines all work.
Using list(range(10)) Doesn't throw an error but it doesn't work.
   
http://i.imgur.com/DTc5zoL.jpg
   
The interpreter.   I don't know how to use that either.
   
   Try both of these in the interpreter, and observe the difference:
   
   7 in range(10)
   
   7 in range(10)
   
   Do you understand what the difference between 7 and 7 is?
   
   I do understand that.  7 is a number and 7 is a string.
   What my question was...and still is...is why
   Python 3 fails when I try using
   y=1 800 get charter
   
   y in range str(range(10))
   should work because y is a string and str(range(10)) should be
   y in str(1) fails.
   It doesn't give an error it's just not True when y is a number.
   
   These hints are just not working.  I am too thick for hints. :)
   If you could use it in the code, I might understand.
   The other work arounds that were posted work.
   I have used them.  str(range(10)) doesn't work.
   
   import string
   def nametonumber(name):
   lst=[]
   nx=[]
   digit=[]
   digit=.join(str(i) for i in range(10))
   for x in name:
   lst.append(x)
   for y in (lst):
   if y in list(range(1,10)):
   #if y in 1234567890:
   #if y.isdigit():
   #if y in digit:   
   #if y in string.digits:
   nx.append(y)
   if y in  -():
   nx.append(y)
   if y in abc:
   nx.append(2)
   if y in def:
   nx.append(3)
   if y in ghi:
   nx.append(4)
   if y in jkl:
   nx.append(5)
   if y in mno:
   nx.append(6)
   if y in pqrs:
   nx.append(7)
   if y in tuv:
   nx.append(8)
   if y in wxyz:
   nx.append(9)
   number=.join(e for e in nx)
   return number
   a=1-800-getcharter
   print (nametonumber(a))#1800 438 2427 837
   a=1-800-leo laporte
   print (nametonumber(a))
   a=1 800 dialaho
   print (nametonumber(a))
   
   Please
  
  Your code here is actually pretty close to a correct answer.  Just a few 
  things to consider...
  
  - Why are you converting your name string to a list?  It is unnecessary. 
   When you do for y in some string, then y will still be single 
  characters on each iteration of the loop.
  
  - if y in string.digits should work fine.
  
  - if y in list(range(1,10) won't work for two reasons: First, it 
  creates a list of numbers, not strings.  Second, even if it did, it 
  would be missing the 0 digit.
  
  - At the end, when you convert your list to a string, you don't need to 
  use list comprehension, since nx is already a list.  number = 
  .join(nx) should work fine.
  
  Also, in general, you need to stop and slow down and think like a 
  programmer.  If you get an error, your instinct shouldn't be to just 
  hack at it to make the error go away.  Look at the error and try to make 
  sense of it.  Learn what the error means and try to fix the core problem.
  
  And for @#$%'s sake...stop saying It isn't working and not 
  elaborating.  You've been told by every other post in this thread to 
  show us what you did and what the error was.  You've also been told to 
  *NOT* retype what you see and to copy/paste your code and the error 
  because when you make a typo when copying, we might see a problem that 
  doesn't exist and then you just get more confused.
  
  Ok  I think I may have the question you guys are looking for.
  I just posted it.
  See above.
  
  But it's still broke.  :(
 
 str(range(10)) doesn't do what you think it does.
 
 Run 'print(str(range(10)))' and look at what you get.
 
 Yeah, I know that.  My question is why?
 The answer was that Python 3 only stores the min and max values but
 you can still iterate over them.
 I don't think that means what I think it means.

You can iterate over them pretty much just means you can use them as the 
source of a 'for' loop.  But in your case, when you're calling 'for y in 
str(range(10))', you're not using 'range(10)' as the source of your loop, 
you're using the result of a str() function call, and you're calling str() on 
range(), which doesn't return a concrete value in Python 3.  If you try to 
print a range(), you're just getting a 

Re: I am out of trial and error again Lists

2014-10-24 Thread Denis McMahon
On Fri, 24 Oct 2014 10:38:31 -0400, Seymore4Head wrote:

 I tried list(range(10)  

This is missing a )

It probably sat there waiting for you to finish the line.

list(range(10))

You have two ( in the line, you need two ) to match them. 

 I thought that would work in Python 3.  It
 didn't.

It does if you enter it properly.

also try:

str(list(range(10))) 

Note that that has three ( and three ) on the line.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (test) ? a:b

2014-10-24 Thread alister
On Fri, 24 Oct 2014 10:20:30 -0700, Dan Stromberg wrote:

 On Fri, Oct 24, 2014 at 1:38 AM, Steven D'Aprano
 steve+comp.lang.pyt...@pearwood.info wrote:
 I don't get why that's considered hard to read.
 
 So why is it hard to read when the index is a flag?

 value = [f, g][cond]()
 
 It's clear to you, it's clear to me, but is it clear to everyone?  I
 very much doubt it.

I had to mentally step through this before it became apparent what it was 
doing,  can see places where it could be usefull (a switch replacement) 
but it is not instantly obvious

a = value if condition else another Value

is instantly obvious (at least to a native English speaker anyway)
 
 Also, you've gone to the trouble of def'ing two functions here - you may
 as well do a function for the if/else.





-- 
Humor is a drug which it's the fashion to abuse.
-- William Gilbert
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (test) ? a:b

2014-10-24 Thread Marko Rauhamaa
alister alister.nospam.w...@ntlworld.com:

 a = value if condition else another Value

 is instantly obvious (at least to a native English speaker anyway)

And you can go further down that road. For example, you could say things
like:

die unless everything is OK


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


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Fri, 24 Oct 2014 20:37:31 + (UTC), Denis McMahon
denismfmcma...@gmail.com wrote:

On Fri, 24 Oct 2014 10:38:31 -0400, Seymore4Head wrote:

 I tried list(range(10)  

This is missing a )

It probably sat there waiting for you to finish the line.

list(range(10))

You have two ( in the line, you need two ) to match them. 

 I thought that would work in Python 3.  It
 didn't.

It does if you enter it properly.

also try:

str(list(range(10))) 

Note that that has three ( and three ) on the line.

I make lots of typing mistakes.  It is not that. Did you see the short
example I posted?

name=123-xyz-abc
for x in name:
if x in range(10):
print (Range,(x))
if x in str(range(10)):
print (String range,(x))

It doesn't throw an error but it doesn't print what you would expect.

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


Re: I am out of trial and error again Lists

2014-10-24 Thread alister
On Fri, 24 Oct 2014 16:58:00 -0400, Seymore4Head wrote:

 On Fri, 24 Oct 2014 20:37:31 + (UTC), Denis McMahon
 denismfmcma...@gmail.com wrote:
 
On Fri, 24 Oct 2014 10:38:31 -0400, Seymore4Head wrote:

 I tried list(range(10)

This is missing a )

It probably sat there waiting for you to finish the line.

list(range(10))

You have two ( in the line, you need two ) to match them.

 I thought that would work in Python 3.  It didn't.

It does if you enter it properly.

also try:

str(list(range(10)))

Note that that has three ( and three ) on the line.
 
 I make lots of typing mistakes.  It is not that. Did you see the short
 example I posted?
 
 name=123-xyz-abc
 for x in name:
 if x in range(10):
 print (Range,(x))
 if x in str(range(10)):
 print (String range,(x))
 
 It doesn't throw an error but it doesn't print what you would expect.

it prints what I expect, it probably does not print what you expect

you have may times been told that str(range(10)) does not do what you 
expect but you keep failing to test

you think that it crates a list of strings ['1','2','3'] but it does 
not
it creates a list  then turns the whole list into a string '[1,2,3...]'

people are suggesting you try this things in the interactive prompt 
because doing teaches far better than just reading.




-- 
Honesty's the best policy.
-- Miguel de Cervantes
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread mm0fmf

On 24/10/2014 15:47, Seymore4Head wrote:

I have at least 10 ebooks.  I will get around to reading them soon.


Sooner would be better.

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


Re: I am out of trial and error again Lists

2014-10-24 Thread Ian Kelly
On Fri, Oct 24, 2014 at 2:58 PM, Seymore4Head
Seymore4Head@hotmail.invalid wrote:
 name=123-xyz-abc
 for x in name:
 if x in range(10):
 print (Range,(x))
 if x in str(range(10)):
 print (String range,(x))

 It doesn't throw an error but it doesn't print what you would expect.

That prints exactly what I expect it to. The first if prints nothing,
because you're testing whether a string is contained in a sequence of
ints. That will always be false. The second if prints those characters
from name that happen to be in the string range(10). That's the 1
and the a.

Apparently it doesn't print what *you* expect, which is why you need
to make your expectation clear and not assume that we will just read
your mind and immediately understand what you expect the code to do.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Denis McMahon
On Fri, 24 Oct 2014 14:15:13 -0400, Seymore4Head wrote:

 I do understand that.  7 is a number and 7 is a string.
 What my question was...and still is...is why Python 3 fails when I try
 using y=1 800 get charter
 
 y in range str(range(10))
 should work because y is a string and str(range(10)) should be y in
 str(1) fails.
 It doesn't give an error it's just not True when y is a number.

This is because str(range(10)) does not do what you think it does.

In python 2.x, str(range(10)) creates a string representation of the 
complete list, not a list of the string representation of the separate 
list elements. '[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]'

In python 3.x, str(range(10)) creates a string representation of the list 
object. 'range(0, 10)'

the only single digit strings in the python3 representation are 0 and 
1

To recreate the python2 behaviour in python 3, use:

str(list(range(10)))

which gives

'[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]'

howver the test:

if x.isdigit():

is much better.

But finally, with your telephone number decoder, look at:

http://www.codeskulptor.org/#user38_QnR06Upp4AH6h0Q.py

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Fri, 24 Oct 2014 21:19:22 + (UTC), Denis McMahon
denismfmcma...@gmail.com wrote:

On Fri, 24 Oct 2014 14:15:13 -0400, Seymore4Head wrote:

 I do understand that.  7 is a number and 7 is a string.
 What my question was...and still is...is why Python 3 fails when I try
 using y=1 800 get charter
 
 y in range str(range(10))
 should work because y is a string and str(range(10)) should be y in
 str(1) fails.
 It doesn't give an error it's just not True when y is a number.

This is because str(range(10)) does not do what you think it does.

In python 2.x, str(range(10)) creates a string representation of the 
complete list, not a list of the string representation of the separate 
list elements. '[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]'

In python 3.x, str(range(10)) creates a string representation of the list 
object. 'range(0, 10)'

the only single digit strings in the python3 representation are 0 and 
1

To recreate the python2 behaviour in python 3, use:

str(list(range(10)))

which gives

'[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]'

howver the test:

if x.isdigit():

is much better.

But finally, with your telephone number decoder, look at:

http://www.codeskulptor.org/#user38_QnR06Upp4AH6h0Q.py

That is much cleaner than mine.  Nice.

I did make one more change to mine that makes it easier to read.
I changed treating all  -()  With a space.
I am still thinking about how to treat the large space if it is a
digit instead:
1 800 555 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Denis McMahon
On Fri, 24 Oct 2014 10:38:31 -0400, Seymore4Head wrote:

 Thanks everyone for your suggestions.

Try loading the following in codeskulptor:

http://www.codeskulptor.org/#user38_j6kGKgeOMr_0.py

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Denis McMahon
On Fri, 24 Oct 2014 15:07:06 -0400, Seymore4Head wrote:

 On Fri, 24 Oct 2014 19:40:39 +0100, Mark Lawrence
 breamore...@yahoo.co.uk wrote:
 
On 24/10/2014 19:20, Seymore4Head wrote:
 I meant to type:
 if y in range(1,10) doesn't work.
 Sigh Sorry


How many more times, state what you expect to happen and what actually
happens.  doesn't work is useless.  Please read this http://sscce.org/
 
 Good suggestion.
 OK  how is this?
 It doesn't print what I expect.
 Does it print what you expect?
 
 name=123-xyz-abc
 for x in name:
 if x in range(10):
 print (Range,(x))
 if x in str(range(10)):
 print (String range,(x))
 
 http://i.imgur.com/EGKUpAb.jpg

I suspect you're discovering the difference between the python2 and 
python3 range() functions, and what happens when you encapsulate them in 
string.

I've already posted about this once this evening.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Dave Angel
Seymore4Head Seymore4Head@Hotmail.invalid Wrote in message:
 On Fri, 24 Oct 2014 09:54:23 -0700 (PDT), Rustom Mody
 rustompm...@gmail.com wrote:
 
Totally befuddled myself!

Are you deliberately misspelling list to lst
and hoping the error will go away.

And Puh LEESE
dont post screen shots of good ol ASCII text
 
 I didn't do that on purpose.  I make a lot of typing mistakes.
 Sorry
 

That's what copy/paste are for. Copy from your console, and paste
 into your email. Don't ever retype unless you're trying to
 frustrate us,

-- 
DaveA

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


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Fri, 24 Oct 2014 21:48:14 + (UTC), Denis McMahon
denismfmcma...@gmail.com wrote:

On Fri, 24 Oct 2014 10:38:31 -0400, Seymore4Head wrote:

 Thanks everyone for your suggestions.

Try loading the following in codeskulptor:

http://www.codeskulptor.org/#user38_j6kGKgeOMr_0.py

That is a useful way to test.
Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head
Seymore4Head@Hotmail.invalid wrote:

Thanks for all the helpful replies.  I just discovered that there is
something wrong with my news feed.  Some of the messages did not make
it to me.  I can go back and read this thread in Google Groups but I
can't reply to it.

If I missed thanking or replying to anyone, that is the reason.

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


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Fri, 24 Oct 2014 18:09:59 -0400 (EDT), Dave Angel
da...@davea.name wrote:

Seymore4Head Seymore4Head@Hotmail.invalid Wrote in message:
 On Fri, 24 Oct 2014 09:54:23 -0700 (PDT), Rustom Mody
 rustompm...@gmail.com wrote:
 
Totally befuddled myself!

Are you deliberately misspelling list to lst
and hoping the error will go away.

And Puh LEESE
dont post screen shots of good ol ASCII text
 
 I didn't do that on purpose.  I make a lot of typing mistakes.
 Sorry
 

That's what copy/paste are for. Copy from your console, and paste
 into your email. Don't ever retype unless you're trying to
 frustrate us,

I promise I am not trying to frustrate anyone.  I know I have.
Sorry
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head
Seymore4Head@Hotmail.invalid wrote:

name=123-xyz-abc 
a=range(10)
b=list(range(10))
c=str(list(range(10)))
print (a,(a))
print (b,(b))
print (c,(c))

for x in name:
if x in a:
print (a,(x))  
if x in b:
print (b,(x))  
if x in c:
print (c,(x))

B is type list and C is type str.
I guess I am still a little too thick.  I would expect b and c to
work. 
http://i.imgur.com/dT3sEQq.jpg
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Rustom Mody
On Saturday, October 25, 2014 4:00:01 AM UTC+5:30, Seymore4Head wrote:
 On Fri, 24 Oct 2014 18:09:59 -0400 (EDT), Dave Angel wrote:
  Don't ever retype unless you're trying to
  frustrate us,
 
 I promise I am not trying to frustrate anyone.  I know I have.
 Sorry

No issues Seymore :-)

As far as I am concerned this has been useful and educative for me --
I found out about codeskulptor.

Though I am a bit conflicted whether it helps or confuses students.

Also many other things... What I take as minor distinctions 
between 
python 2 and 3 may not be so minor if one doesn't know whats going on.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Denis McMahon
On Fri, 24 Oct 2014 17:35:34 -0400, Seymore4Head wrote:

But finally, with your telephone number decoder, look at:

http://www.codeskulptor.org/#user38_QnR06Upp4AH6h0Q.py
 
 That is much cleaner than mine.  Nice.
 
 I did make one more change to mine that makes it easier to read. I
 changed treating all  -()  With a space.
 I am still thinking about how to treat the large space if it is a digit
 instead:
 1 800 555 

Note that my decoder assumes anything other than a letter can be copied 
straight to the output string.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Denis McMahon
On Fri, 24 Oct 2014 16:58:00 -0400, Seymore4Head wrote:

 I make lots of typing mistakes.  It is not that. Did you see the short
 example I posted?
 
 name=123-xyz-abc
 for x in name:
 if x in range(10):
 print (Range,(x))
 if x in str(range(10)):
 print (String range,(x))
 
 It doesn't throw an error but it doesn't print what you would expect.

It prints exactly what I expect.

Try the following:

print(str(range(10)), type(str(range(10
print(str(list(range(10))), type(str(listr(range(10)

In python 3, str(x) just wraps x up and puts it in a string. range(x) 
generates an iterable range object.

hence str(range(10)) is a string telling you that range(10) is an iterable 
range object with certain boundaries.

However, list(iterable) expands the iterable to the full list of possible 
values, so str(list(range(10))) is a string representation of the list 
containing the values that the iterable range(10) creates.

Note that whether you're looking at a string representation of a value or 
the value itself is a lot clearer in the interpreter console where 
strings are displayed with quotes.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Mark Lawrence

On 24/10/2014 23:58, Seymore4Head wrote:

On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head
Seymore4Head@Hotmail.invalid wrote:

name=123-xyz-abc
a=range(10)
b=list(range(10))
c=str(list(range(10)))
print (a,(a))
print (b,(b))
print (c,(c))

for x in name:
 if x in a:
 print (a,(x))
 if x in b:
 print (b,(x))
 if x in c:
 print (c,(x))

B is type list and C is type str.
I guess I am still a little too thick.  I would expect b and c to
work.
http://i.imgur.com/dT3sEQq.jpg



Why?

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: I am out of trial and error again Lists

2014-10-24 Thread Rustom Mody
On Saturday, October 25, 2014 4:30:47 AM UTC+5:30, Seymore4Head wrote:
 On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head wrote:
 
 name=123-xyz-abc 
 a=range(10)
 b=list(range(10))
 c=str(list(range(10)))
 print (a,(a))
 print (b,(b))
 print (c,(c))
 
 for x in name:
 if x in a:
 print (a,(x))  
 if x in b:
 print (b,(x))  
 if x in c:
 print (c,(x))
 
 B is type list and C is type str.
 I guess I am still a little too thick.  I would expect b and c to
 work. 

Lets simplify the problem a bit.
Do all the following in interpreter window

 name=012
 b=list(range(3))

 for x in name:  print x

 for x in b: print x

Same or different?

Now go back to Denis' nice example and put in type(x)
into each print

Same or different?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Denis McMahon
On Fri, 24 Oct 2014 18:58:04 -0400, Seymore4Head wrote:

 On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head
 Seymore4Head@Hotmail.invalid wrote:

OK, assuming you tried to run this in python3, not python2 or 
codeskulptor.

 name=123-xyz-abc
 a=range(10)

  a is an iterable object giving the numbers 0 through 9

 b=list(range(10))

  b is an list containing the numbers 0 through 9

 c=str(list(range(10)))

  c is an string representation of a list containing the numbers 0 
through 9

 print (a,(a))
 print (b,(b))
 print (c,(c))
 
 for x in name:

 ^ x is a string representing one character in name

 if x in a:
 print (a,(x))

  here you are looking for a string x amongst the numbers yielded by 
an iterable

 if x in b:
 print (b,(x))

  here you are comparing a string x with the elements of a list of 
numbers

 if x in c:
 print (c,(x))

  here you are comparing a string x with the characters in a string 
representation of a list of numbers

 B is type list and C is type str.
 I guess I am still a little too thick.  I would expect b and c to work.
 http://i.imgur.com/dT3sEQq.jpg

a is the range object: range(0, 9)
b is the list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
c is the string: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

When you try and compare a character x eg 8 with the numbers yielded by 
the iterable a, none of them match because character 8 is not the same 
as number 8

When you try and compare a character x eg 8 with the elements of the 
list b, none of them match because character 8 is not the same as 
number 8

When you try and compare a character x eg 8 with the string 
representation of the list b, you get a match of x 8 to the 25th 
character of string c which is also 8.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Fri, 24 Oct 2014 16:27:58 -0700 (PDT), Rustom Mody
rustompm...@gmail.com wrote:

On Saturday, October 25, 2014 4:30:47 AM UTC+5:30, Seymore4Head wrote:
 On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head wrote:
 
 name=123-xyz-abc 
 a=range(10)
 b=list(range(10))
 c=str(list(range(10)))
 print (a,(a))
 print (b,(b))
 print (c,(c))
 
 for x in name:
 if x in a:
 print (a,(x))  
 if x in b:
 print (b,(x))  
 if x in c:
 print (c,(x))
 
 B is type list and C is type str.
 I guess I am still a little too thick.  I would expect b and c to
 work. 

Lets simplify the problem a bit.
Do all the following in interpreter window

 name=012
 b=list(range(3))

 for x in name:  print x

 for x in b: print x

Same or different?

Now go back to Denis' nice example and put in type(x)
into each print

Same or different?

First.  The interpreter is not good for me to use even when I am using
Python 3 because I forget to add :  and I forget to put () around the
print statements.

To keep me from having to correct myself every time I use it, it is
just easier to make a short py file.

Here is mine:

name=012
b=list(range(3))
for x in name:  print (x)
print (type (x))
for x in b: print (x)
print (type (b))

I don't understand what I was supposed to learn from that.  I know
that name will be a string so x will be a string.
I would still think if you compare a 1 from a string to a 1 from a
list, it should be the same.

Obviously I am wrong, but we knew that already.
I get they are not the same, but I still think they should be.

name=012
b=list(range(3))
print (name[1])
print ([1])

1
[1]

OK  I get it.  They are not the same.  I was expecting 1


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


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Fri, 24 Oct 2014 23:21:43 + (UTC), Denis McMahon
denismfmcma...@gmail.com wrote:

On Fri, 24 Oct 2014 16:58:00 -0400, Seymore4Head wrote:

 I make lots of typing mistakes.  It is not that. Did you see the short
 example I posted?
 
 name=123-xyz-abc
 for x in name:
 if x in range(10):
 print (Range,(x))
 if x in str(range(10)):
 print (String range,(x))
 
 It doesn't throw an error but it doesn't print what you would expect.

It prints exactly what I expect.

Try the following:

print(str(range(10)), type(str(range(10
print(str(list(range(10))), type(str(listr(range(10)

In python 3, str(x) just wraps x up and puts it in a string. range(x) 
generates an iterable range object.

hence str(range(10)) is a string telling you that range(10) is an iterable 
range object with certain boundaries.

However, list(iterable) expands the iterable to the full list of possible 
values, so str(list(range(10))) is a string representation of the list 
containing the values that the iterable range(10) creates.

Note that whether you're looking at a string representation of a value or 
the value itself is a lot clearer in the interpreter console where 
strings are displayed with quotes.

I get it now.
Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Fri, 24 Oct 2014 19:48:16 -0400, Seymore4Head
Seymore4Head@Hotmail.invalid wrote:

On Fri, 24 Oct 2014 16:27:58 -0700 (PDT), Rustom Mody
rustompm...@gmail.com wrote:

On Saturday, October 25, 2014 4:30:47 AM UTC+5:30, Seymore4Head wrote:
 On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head wrote:
 
 name=123-xyz-abc 
 a=range(10)
 b=list(range(10))
 c=str(list(range(10)))
 print (a,(a))
 print (b,(b))
 print (c,(c))
 
 for x in name:
 if x in a:
 print (a,(x))  
 if x in b:
 print (b,(x))  
 if x in c:
 print (c,(x))
 
 B is type list and C is type str.
 I guess I am still a little too thick.  I would expect b and c to
 work. 

Lets simplify the problem a bit.
Do all the following in interpreter window

 name=012
 b=list(range(3))

 for x in name:  print x

 for x in b: print x

Same or different?

Now go back to Denis' nice example and put in type(x)
into each print

Same or different?

First.  The interpreter is not good for me to use even when I am using
Python 3 because I forget to add :  and I forget to put () around the
print statements.

To keep me from having to correct myself every time I use it, it is
just easier to make a short py file.

Here is mine:

name=012
b=list(range(3))
for x in name:  print (x)
print (type (x))
for x in b: print (x)
print (type (b))

I don't understand what I was supposed to learn from that.  I know
that name will be a string so x will be a string.
I would still think if you compare a 1 from a string to a 1 from a
list, it should be the same.

Obviously I am wrong, but we knew that already.
I get they are not the same, but I still think they should be.

name=012
b=list(range(3))
print (name[1])
print ([1])

1
[1]

OK  I get it.  They are not the same.  I was expecting 1

Wait!  I don't get it.
name=012
b=list(range(3))
print (name[1])
print (b[1])
1
1

I forgot the b

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


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head
Seymore4Head@Hotmail.invalid wrote:

name=012
b=list(range(3))
print (name[1])
print (b[1])
if name[1] == b[1]:
print (Eureka!)
else:
print (OK, I get it)
 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread MRAB

On 2014-10-25 00:57, Seymore4Head wrote:
[snip]

Wait!  I don't get it.
name=012
b=list(range(3))
print (name[1])
print (b[1])
1
1

I forgot the b


If you print the int 1, you'll see:

1

If you print the string 1, you'll see:

1

Normally you want it to print only the characters of the string. Think
how annoying it would be if every time you printed a string it appeared
in quotes:

 print(Hello world!)
'Hello world!'

How could you print just the text:

Hello world!

No, it's better that it prints the characters of the string.

One function you can use is repr:

x = 1
y = 1
print(repr(x))
print(repr(y))

This will print:

1
'1'

OK, now it's clear that x is an int and y is a string.

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


Re: I am out of trial and error again Lists

2014-10-24 Thread Terry Reedy

On 10/24/2014 6:27 PM, Seymore4Head wrote:


I promise I am not trying to frustrate anyone.  I know I have.


Seymore, if you want to learn real Python, download and install 3.4.2 
and either use the Idle Shell and Editor or the interactive console 
interpreter and a decent programmer editor.


I cannot recommend CodeSkulptor to anyone.  The opening statement
# CodeSkulptor runs Python programs
is deceptive.  CodeSkulptor Python is not Python. It does not correspond 
to any x.y version of Python. It is a somewhat crippled subset of 
ancient Python (2.1) with selected additions of later features.  It does 
not have exceptions, raise, and try: except:.  These are an essential 
part of original Python and Python today  It does not have complex 
(maybe introduced in 1.5) and unicode (introduced in 2.0).  Let that 
pass.  More important, it does not have new-style classes, an essential 
new feature introduced in 2.2.  Python beginners should start with 
unified new-styled classes.  If lucky, they need never learn about the 
original old style, dis-unified type versus class system that started 
going away in 2.2, is mostly gone in 2.7. and completely gone in 3.0.


If you really want to continue with CodeSkulpter Python, you should find 
a CodeSkulpterPython list.  You cannot expect people here to know that 
legal code like

  class I(int): pass
will not run, but will fail with an exceeding cryptic message:
  Line 1: undefined: TypeError: a.$d is undefined
Nor can you expect us to know all the other limitations.

This is a list for Python.  If you want help here, get and use a real 
Python interpreter, with a proper interactive mode, as multiple people 
have suggested.


--
Terry Jan Reedy


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


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Sat, 25 Oct 2014 01:20:53 +0100, MRAB pyt...@mrabarnett.plus.com
wrote:

On 2014-10-25 00:57, Seymore4Head wrote:
[snip]
 Wait!  I don't get it.
 name=012
 b=list(range(3))
 print (name[1])
 print (b[1])
 1
 1

 I forgot the b

If you print the int 1, you'll see:

1

If you print the string 1, you'll see:

1

Normally you want it to print only the characters of the string. Think
how annoying it would be if every time you printed a string it appeared
in quotes:

  print(Hello world!)
'Hello world!'

How could you print just the text:

Hello world!

No, it's better that it prints the characters of the string.

One function you can use is repr:

x = 1
y = 1
print(repr(x))
print(repr(y))

This will print:

1
'1'

OK, now it's clear that x is an int and y is a string.

Yes

x = 123
y = 123
z = [1,2,3]
print(repr(x))
print(repr(y))
print(repr(z))
123
'123'
[1, 2, 3]

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


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Fri, 24 Oct 2014 20:27:03 -0400, Terry Reedy tjre...@udel.edu
wrote:

On 10/24/2014 6:27 PM, Seymore4Head wrote:

 I promise I am not trying to frustrate anyone.  I know I have.

Seymore, if you want to learn real Python, download and install 3.4.2 
and either use the Idle Shell and Editor or the interactive console 
interpreter and a decent programmer editor.

I cannot recommend CodeSkulptor to anyone.  The opening statement
# CodeSkulptor runs Python programs
is deceptive.  CodeSkulptor Python is not Python. It does not correspond 
to any x.y version of Python. It is a somewhat crippled subset of 
ancient Python (2.1) with selected additions of later features.  It does 
not have exceptions, raise, and try: except:.  These are an essential 
part of original Python and Python today  It does not have complex 
(maybe introduced in 1.5) and unicode (introduced in 2.0).  Let that 
pass.  More important, it does not have new-style classes, an essential 
new feature introduced in 2.2.  Python beginners should start with 
unified new-styled classes.  If lucky, they need never learn about the 
original old style, dis-unified type versus class system that started 
going away in 2.2, is mostly gone in 2.7. and completely gone in 3.0.

If you really want to continue with CodeSkulpter Python, you should find 
a CodeSkulpterPython list.  You cannot expect people here to know that 
legal code like
   class I(int): pass
will not run, but will fail with an exceeding cryptic message:
   Line 1: undefined: TypeError: a.$d is undefined
Nor can you expect us to know all the other limitations.

This is a list for Python.  If you want help here, get and use a real 
Python interpreter, with a proper interactive mode, as multiple people 
have suggested.

OK.  I will.
Thanks

But the difference between Python 2 and Codeskulptor was not an issue
with this question.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-24 Thread Cameron Simpson

On 24Oct2014 20:37, Seymore4Head Seymore4Head@Hotmail.invalid wrote:

On Sat, 25 Oct 2014 01:20:53 +0100, MRAB pyt...@mrabarnett.plus.com

One function you can use is repr:

x = 1
y = 1
print(repr(x))
print(repr(y))

This will print:

1
'1'

OK, now it's clear that x is an int and y is a string.


Yes


In particular, Python's interactive mode uses repr to print the result of any 
expression that whose value was not None:


  [/Users/cameron]fleet* python
  Python 2.7.8 (default, Oct  3 2014, 02:34:26)
  [GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
  Type help, copyright, credits or license for more information.
   x=1
   y='1'
   x
  1
   y
  '1'
  

so you get this for free in that mode.

Cheers,
Cameron Simpson c...@zip.com.au

If your new theorem can be stated with great simplicity, then there
will exist a pathological exception.- Adrian Mathesis
--
https://mail.python.org/mailman/listinfo/python-list


Best Jobb Oriented Web Designig Course Institute in Hyderabad

2014-10-24 Thread dreams media Solution
In Web Designing course, students will learn how to develop a rich look web 
site. We will explain design principles in Photoshop. In Photoshop we will 
train you, how to develop logos, icons, banners. We will explain animation 
principles in flash. In Flash we will train you how to develop animated ads, 
logos, banners.

Dreams Media Solutions is One of the Best Web Designing Training Institute in 
Hyderabad  and We aso Provides PHPTraining,Autocad Training Also.
For more details:
http://www.dreamsmediasolutions.com/software-courses/web-designing-course-in-ameerpet/
-- 
https://mail.python.org/mailman/listinfo/python-list


python student at university of jordan.

2014-10-24 Thread heba abukaff
Hi,
my name is heba ibrahim abukaff from jordan ,iam a computer information system 
student at university of jordan . 
i have a trouble using the tokenizer to find the frequency list for URL using 
arabic text.and iam using python 2.7.2 on winXP,I tried this code but every 
time i run the code appears error with first line 
COULD YOU HELP ME.
WITH REGARDS.
::
python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on 
win32
 import re, codecs
import nltk 

from urllib import request
url = http://ar.wikipedia.org/wiki/%D9%85%D9%88%D9%82%D8%B9_%D9%88%D9%8A%D8%A8;
response = request.urlopen(url)
raw = response.read().decode('utf8')
print(raw)

import re, codecs import nltk from nltk.probability
import * def construct_frequency_list(words):

outfile = codecs.open(r'raw.txt' , 'w')
fd = nltk.probability.FreqDist()
for w in words: fd.inc(w)
print Total number of words: %d Vocbulary size : %d % (fd.N(), fd.B())
print word with highest count: %s % (fd.max())
tokenlist = fd.iteritems()
for (key, value) in tokenlist:
printoutfile, %s\t%d % (key, value)
outfile.close() def read_textfile(raw ):
lines = codecs.open(raw ,'r','utf_8').readlines()
outfile = codecs.open(r'raw.txt' ,'w','utf_8')
counter = 0 wordlist = [] for line in lines:
tokens = line.rstrip().lstrip().split()
for t in tokens: wordlist.append(t)
printoutfile, '%s\t%d' % (t, len(t))
counter += len(t) outfile.close()
return wordlist if __name__ == __main__:
 words = read_textfile(r'raw .txt')
construct_frequency_list(words)
print Done!
 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python student at university of jordan.

2014-10-24 Thread Chris Angelico
On Sat, Oct 25, 2014 at 12:47 PM, heba abukaff
habukaf...@yahoo.com.dmarc.invalid wrote:
 i have a trouble using the tokenizer to find the frequency list for URL using 
 arabic text.and iam using python 2.7.2 on winXP,I tried this code but every 
 time i run the code appears error with first line

I'm seeing two problems here. One of them may not actually be a
problem in your code, but just in how you're posting: your text has
all been rewrapped. Post the exact code, as plain text (not HTML); you
should be able to do this, but if you can't with Yahoo, try a
different email provider. Make sure we can see exactly where your code
begins and ends, so we can understand what first line you're looking
at - and if you copy and paste the actual error you get, that would be
extremely helpful, too. (Even if it's in Arabic. There'll be parts we
can understand.)

The second problem is that you're trying to work with non-English text
in Python 2.7. This is harder than it needs to be. Install the latest
Python (3.4) and use that instead of 2.7; the NLTK module is
compatible with 3.2+, so it should work fine. I can't be sure that
you're having trouble with bytes vs strings, because I can't see what
your code's doing (due to the wrap/indent problem), but in any case,
shifting to Python 3 gives you a much better chance of getting things
right. All you'll need to do, I suspect, is change your print
statements into function calls:

# Old style:
print word with highest count: %s % (fd.max())
# New style:
print(word with highest count: %s % (fd.max()))

Easy! And only slightly harder when you send it to a different destination:

# Old style:
printoutfile, '%s\t%d' % (t, len(t))
# New style:
print('%s\t%d' % (t, len(t)), file=outfile)

With those changes, your code will probably (I can't test it) work on
Python 3.4.

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


Re: I am out of trial and error again Lists

2014-10-24 Thread Larry Hudson

On 10/24/2014 07:38 AM, Seymore4Head wrote:
snip

I do get the difference.  I don't actually use Python 2.  I use
CodeSkulptor.  I do have Python 3 installed.  Actually I have Python 2
installed but IDLE defaults to Python 3.  So it is a pain to actually
load Python 2.



Exactly HOW are you trying to run Idle?  A default install of Py2 and Py3 in Windows should have 
also installed Idle for each version.  In my Win7 system, they are BOTH in the standard menu, 
you should be able to call up either one.


OT:  Side comment:  I rarely use Windows these days, maybe once every two or three months -- I 
MUCH prefer Linux.  Among other reasons its a far better environment for programming.  I only 
have one (active) system with Windows installed, and two others with Linux only.  Actually make 
that three, if you count my Raspberry Pi.   :-)


 -=- Larry -=-

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


Re: I am out of trial and error again Lists

2014-10-24 Thread Seymore4Head
On Fri, 24 Oct 2014 19:16:21 -0700, Larry Hudson org...@yahoo.com
wrote:

On 10/24/2014 07:38 AM, Seymore4Head wrote:
snip
 I do get the difference.  I don't actually use Python 2.  I use
 CodeSkulptor.  I do have Python 3 installed.  Actually I have Python 2
 installed but IDLE defaults to Python 3.  So it is a pain to actually
 load Python 2.


Exactly HOW are you trying to run Idle?  A default install of Py2 and Py3 in 
Windows should have 
also installed Idle for each version.  In my Win7 system, they are BOTH in the 
standard menu, 
you should be able to call up either one.

OT:  Side comment:  I rarely use Windows these days, maybe once every two or 
three months -- I 
MUCH prefer Linux.  Among other reasons its a far better environment for 
programming.  I only 
have one (active) system with Windows installed, and two others with Linux 
only.  Actually make 
that three, if you count my Raspberry Pi.   :-)

  -=- Larry -=-
I have a directory of my py files.  I right click on one of the py
files and open with IDLE   Windows XP

If I try to open a py file I have for Python 2 it still opens using
IDLE 3.

I don't have many py 2 files anyway.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python student at university of jordan.

2014-10-24 Thread Cameron Simpson

On 25Oct2014 13:06, Chris Angelico ros...@gmail.com wrote:

On Sat, Oct 25, 2014 at 12:47 PM, heba abukaff
habukaf...@yahoo.com.dmarc.invalid wrote:

i have a trouble using the tokenizer to find the frequency list for URL using 
arabic text.and iam using python 2.7.2 on winXP,I tried this code but every 
time i run the code appears error with first line


I'm seeing two problems here. One of them may not actually be a
problem in your code, but just in how you're posting: your text has
all been rewrapped. Post the exact code, as plain text (not HTML); you
should be able to do this, but if you can't with Yahoo, try a
different email provider.


Looking at his post via python-list, he _did_ post in plain text. There's no 
HTML at all.



Make sure we can see exactly where your code
begins and ends, so we can understand what first line you're looking
at - and if you copy and paste the actual error you get, that would be
extremely helpful, too. (Even if it's in Arabic. There'll be parts we
can understand.)


This, OTOH, yes.

Heba, could you post the error message please? The complete message, including 
the stack trace lines if any.


Cheers,
Cameron Simpson c...@zip.com.au
--
https://mail.python.org/mailman/listinfo/python-list


Re: python student at university of jordan.

2014-10-24 Thread Chris Angelico
On Sat, Oct 25, 2014 at 2:05 PM, Cameron Simpson c...@zip.com.au wrote:
 I'm seeing two problems here. One of them may not actually be a
 problem in your code, but just in how you're posting: your text has
 all been rewrapped. Post the exact code, as plain text (not HTML); you
 should be able to do this, but if you can't with Yahoo, try a
 different email provider.


 Looking at his post via python-list, he _did_ post in plain text. There's no
 HTML at all.

Plain text is all that got through to us, but I suspect that possibly
he had an HTML version that got stripped somewhere along the way.
Either that, or the code that we're looking at really is what's in his
.py file, in which case the first line is the version marker - no
wonder it's failing.

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


Re: I am out of trial and error again Lists

2014-10-24 Thread Rustom Mody
On Saturday, October 25, 2014 5:21:01 AM UTC+5:30, Seymore4Head wrote:
 On Fri, 24 Oct 2014 16:27:58 -0700 (PDT), Rustom Mody wrote:
 
 On Saturday, October 25, 2014 4:30:47 AM UTC+5:30, Seymore4Head wrote:
  On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head wrote:
  
  name=123-xyz-abc 
  a=range(10)
  b=list(range(10))
  c=str(list(range(10)))
  print (a,(a))
  print (b,(b))
  print (c,(c))
  
  for x in name:
  if x in a:
  print (a,(x))  
  if x in b:
  print (b,(x))  
  if x in c:
  print (c,(x))
  
  B is type list and C is type str.
  I guess I am still a little too thick.  I would expect b and c to
  work. 
 
 Lets simplify the problem a bit.
 Do all the following in interpreter window
 
  name=012
  b=list(range(3))
 
  for x in name:  print x
 
  for x in b: print x
 
 Same or different?
 
 Now go back to Denis' nice example and put in type(x)
 into each print
 
 Same or different?
 
 First.  The interpreter is not good for me to use even when I am using
 Python 3 because I forget to add :  and I forget to put () around the
 print statements.
 

What would you say to a person who
- Buys a Lambhorgini
- Hitches a horse (or bullock) to it
- Moans how clumsily slow it is.

   ??

In case you dont get it:

- the interpreter is one of the factors that puts python into the hi-end class.
- the bullock/horse class is the C/Java type language where you always 
need to work through files

Here is my list of points of sliding for bullock category to Lambhorgini:
http://blog.languager.org/2012/10/functional-programming-lost-booty.html
['Interpreter' is called 'REPL' there]

 To keep me from having to correct myself every time I use it, it is
 just easier to make a short py file.

Yes the intention is right, The implementation is wrong.

Programmers consider it a virtue to be lazy.
But you have to put it some work to learn to be lazy in an effective way
And currently you are being lazy on the wrong front.

Hints:
1. A good programmer tries out things at the interpreter ONE LINE AT A TIME
2. What he tries out are usually EXPRESSIONS like eg
   str(list(range(10)))

   And not STATEMENTS like
   if x in name: 
  print x

3. IOW a good programmer rarely needs to type a colon at the interpreter

4. The least useful statement to try at the interpreter is print.

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


Re: I am out of trial and error again Lists

2014-10-24 Thread Rustom Mody
On Saturday, October 25, 2014 9:17:12 AM UTC+5:30, Rustom Mody wrote:
 4. The least useful statement to try at the interpreter is print.

Yeah this is python2 thinking; in python 3, print is technically an expression.


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


Re: I am out of trial and error again Lists

2014-10-24 Thread Ben Finney
Rustom Mody rustompm...@gmail.com writes:

 On Saturday, October 25, 2014 9:17:12 AM UTC+5:30, Rustom Mody wrote:
  4. The least useful statement to try at the interpreter is print.

 Yeah this is python2 thinking; in python 3, print is technically an
 expression.

This is wrong thinking. In Python 3, print is a function.

-- 
 \   “[W]hoever is able to make you absurd is able to make you |
  `\unjust.” —Voltaire |
_o__)  |
Ben Finney

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


Re: python student at university of jordan.

2014-10-24 Thread Steven D'Aprano
heba abukaff wrote:

 Hi,
 my name is heba ibrahim abukaff from jordan ,iam a computer information
 system student at university of jordan . i have a trouble using the
 tokenizer to find the frequency list for URL using arabic text.and iam
 using python 2.7.2 on winXP,I tried this code but every time i run the
 code appears error with first line COULD YOU HELP ME. 

We can only help you if you help us. We cannot guess the error that you get,
you have to show us. Copy and paste the complete error message, starting
from the word Traceback to the end.

Given the code you showed:

[quote]
 import re, codecs
import nltk
[end quote]

Notice the greater-than sign  at the beginning of the import re, codecs
line? If that greater-than sign is actually in your program, you would get
a syntax error:

py  import re, codecs
  File stdin, line 1
 import re, codecs
^
SyntaxError: invalid syntax


If that is not the error message you are getting, you will need to tell us
what error you actually are getting.


Regards,



-- 
Steven

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


Re: (test) ? a:b

2014-10-24 Thread Steven D'Aprano
alister wrote:

 On Fri, 24 Oct 2014 10:20:30 -0700, Dan Stromberg wrote:
 
 On Fri, Oct 24, 2014 at 1:38 AM, Steven D'Aprano
 steve+comp.lang.pyt...@pearwood.info wrote:
 I don't get why that's considered hard to read.
 
 So why is it hard to read when the index is a flag?

 value = [f, g][cond]()
 
[Dan]
 It's clear to you, it's clear to me, but is it clear to everyone?  I
 very much doubt it.

Of course it won't be clear to *everyone* but it should be clear enough to
people who are familiar with standard Python idioms. A concrete example
should be more obvious than the fake example:

title = ('Mr', 'Ms')[person.sex == 'F']

which should be clear to anyone who understands indexing in Python and that
True == 1 and False == 0.

Although that's probably better written as a dict lookup:

title = {'M': 'Mr', 'F': 'Ms'}[person.sex]

which is then more easily extended to support intersex and
non-traditional[1] gender identities. Better still is to allow the
individual to choose their own title (Dr, Prof, Mrs, Miss, Mx, Sir, Dame,
etc.) rather than calculate it from their sex, but that's moving away from
the point I am making that this idiom isn't some weird and hackish
bizarrity. We use list indexing and key lookup all the time, this is just a
special case of the same. It's no more hackish than:

mapping = {True: something which is factual,
   False: something which people prefer to believe}
value = mapping[flag]


[Alister]
 I had to mentally step through this before it became apparent what it was
 doing,  can see places where it could be usefull (a switch replacement)
 but it is not instantly obvious

Very little code is instantly obvious. Even when you know what the syntax
means, you still have to understand the semantics, and sometimes that's far
from obvious.


 a = value if condition else another Value
 
 is instantly obvious (at least to a native English speaker anyway)

Ha! And yet people have, and continue to, complain *bitterly* about the
non-standard ordering of Python's ternary if, compared to C, standard
if...else syntax, and English.

If the syntax is like C, then people will use it, or else they will
complain that the syntax is incomprehensible.

Personally, I don't accept or agree with such complaints. Python's ternary
if follows the same syntax as this English variant:

People will use it if the syntax is like C, or else they will complain that
the syntax is incomprehensible.

Still, English-like though it is, Python's ternary if does violate the
expectations of those who expect the condition to come first, as the
standard if...else block does.


[Dan]
 Also, you've gone to the trouble of def'ing two functions here - you may
 as well do a function for the if/else.

Not every one-liner expression needs to go into a function.




[1] For Western Christian definitions of traditional. Other cultures have
traditionally recognised more than just a binary state of gender and
sexuality, e.g. https://en.wikipedia.org/wiki/Hijra_%28South_Asia%29

-- 
Steven

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


  1   2   >