Re: [OT] is JSON all that great? - was Re: API Help

2017-06-14 Thread Gregory Ewing

Michael Torrie wrote:

I don't find JSON any more human readable than XML
to be honest, perhaps less so because there's no way to define a formal
schema to follow, at least that I'm aware of.


You mean like this?

http://json-schema.org/

One thing I like better about JSON than XML as a serialisation
format is that JSON constructs map one-to-one with data structures
typically found in programming languages, whereas XML constructs
don't. With JSON there's usually One Obvious Way to do the mapping,
but with XML you get spurious choices and inconvenient restrictions.

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


Re: data structure

2017-06-14 Thread Frank Millman
"Andrew Zyman"  wrote in message 
news:caprckxktozonlak8asizonkypd9y_p25fr2rkfkozxoa4bc...@mail.gmail.com...


Hello,
 i wonder what would be a proper data structure for something with the
following characteristics:

id - number,
obj[a..c] - objects of various classes

the idea is to be able to update certain fields of these objects initially
getting access to the record by ID

something like this ( not working )

### code start

class ClassA(object):
a = ''
b = ''
def __init__(self):
a= 'aa'
b= 'ab'

class ClassB(object):
def __init__(self):
self.c = 'ba'
self.d = 'bb'

def main():
obja = ClassA
objb = ClassB

sets = set(obja, objb)
   contracts[1] = sets

print('Sets ', contracts)

# with the logic like ( not working too)
if obja.a = 'aa':
contracts[1].obja.a = 'ABC'


 if __name__ == '__main__':
main()


### code end


I don't really understand the question, but I would like to point out the 
following -


 class ClassA(object):
a = ''
b = ''
def __init__(self):
a= 'aa'
b= 'ab'

In your __init__() function, 'a' and 'b' are not bound to anything, so they 
are simply local variables and will be garbage-collected when the function 
has completed.


Therefore any instance of ClassA() will get its values of 'a' and 'b' from 
the class definition - an empty string.


Frank Millman


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


Re: [OT] is JSON all that great? - was Re: API Help

2017-06-14 Thread Marko Rauhamaa
Chris Angelico :

> XML is thus poorly suited to *most* forms of data,

Correct.

> 
> 
>   aa
>   qq
>   qw
>   qe
>   as
> 
>
> What does this represent? A generic XML parser has to cope with it. I
> gave this to a few XML-to-JSON converters, and they all interpreted it
> as some variant of {"asdf":["aa","as"],"qwer":["qq","qw","qe"]}

It's worse than that. For a *generic* parser, it should be something
like:

   {
   "spam" : [
   "  \n",
   { "asdf" : [ "aa" ] },
   "  \n",
   { "qwer" : [ "qq" ] },
   "  \n",
   { "qwer" : [ "qw" ] },
   "  \n",
   { "qwer" : [ "qe" ] },
   "  \n",
   { "asdf" : [ "as" ] },
   "\n"
   ]
   }

> XML just needs to die.

Thankfully, that seems to be happening.


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


Re: Standard lib version of something like enumerate() that takes a max count iteration parameter?

2017-06-14 Thread Jussi Piitulainen
Andre Müller writes:

> I'm a fan of infinite sequences. Try out itertools.islice.
> You should not underestimate this very important module.
>
> Please read also the documentation:
> https://docs.python.org/3.6/library/itertools.html
>
> from itertools import islice
>
> iterable = range(100)
> # since Python 3 range is a lazy evaluated object
> # using this just as a dummy
> # if you're using legacy Python (2.x), then use the xrange function for it
> # or you'll get a memory error
>
> max_count = 10
> step = 1
>
> for i, element in enumerate(islice(iterable, 0, max_count, step), start=1):
> print(i, element)

I like to test this kind of thing with iter("abracadabra") and look at
the remaining elements, just to be sure that they are still there.

from itertools import islice

s = iter("abracadabra")
for i, element in enumerate(islice(s, 3)):
print(i, element)

print(''.join(s))

Prints this:

0 a
1 b
2 r
acadabra

One can do a similar check with iter(range(1000)). The range object
itself does not change when its elements are accessed.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ensurepip

2017-06-14 Thread Steven D'Aprano
On Wed, 14 Jun 2017 07:00:13 +0200, Pavol Lisy wrote:

> $ python3 -m ensurepip /usr/bin/python3: No module named ensurepip
> 
> But maybe this help to understand:
> 
> $ python -m ensurepip 
> ensurepip is disabled in Debian/Ubuntu for the system python.


Ah, thanks!

I don't get that error message, possibly because I'm running Python 3 
which isn't the system python but was installed by apt-get.




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


Re: [OT] is JSON all that great? - was Re: API Help

2017-06-14 Thread Chris Angelico
On Thu, Jun 15, 2017 at 12:33 PM, Michael Torrie  wrote:
> To me JSON seems to hold no real benefits over other serialization
> techniques, including the XML beast. XML may be verbose, but at least
> XML data can be formally validated and formally transformed and queried,
> which is certainly not the case with JSON as we can see from this long
> thread.  JSON's mantra seems to be try parsing it and see what happens.
> Whether it works depends on the parser and any quirks it has (quotes vs
> single quotes, etc).  I don't find JSON any more human readable than XML
> to be honest, perhaps less so because there's no way to define a formal
> schema to follow, at least that I'm aware of.

There are JSON schema validators. And I'd trust them every bit as much
as I'd trust an XML schema validator - probably more, because I can
actually understand them (due largely to the simplicity of JSON).

XML is a document format, like HTML and friends. It has certain
features that JSON doesn't have, and JSON has features that XML
doesn't. Thing is, most people's data is either strictly tabular, or
is structured in something like a Python object hierarchy - not a
document. XML is thus poorly suited to *most* forms of data, and
you'll end up shoehorning data into format and vice versa, which leads
to stupidities like being unable to adequately represent a one-item
list/array, or having to try to maintain element order. Consider:



  aa
  qq
  qw
  qe
  as


What does this represent? A generic XML parser has to cope with it. I
gave this to a few XML-to-JSON converters, and they all interpreted it
as some variant of {"asdf":["aa","as"],"qwer":["qq","qw","qe"]} - but
if you remove the last  element, they all saw it as
{"asdf":"aa","qwer":["qq","qw","qe"]}. So we lose element order (which
is a feature of XML but not JSON), and we lose single-element arrays
(which are a feature of JSON but not XML), and we make a total hash of
the notion of a tree (since both formats are trees but in slightly
different ways).

Pick a transport format that matches your data structure, or at very
least, a strict superset thereof (eg tabular data is probably best
expressed as CSV, but JSON is perfectly capable of representing it).

XML just needs to die.

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


Re: Converting epoch to string in format yyyy-mm-dd, or maybe it is not necessary

2017-06-14 Thread Pavol Lisy
(I am not very familiar with panda too!)

In case of his data he needs to set unit to 's'

df['dt'] = pd.to_datetime(df.epoch,unit='s')

It return utc time from epoch, so maybe this is what he could use ->

df['dt'] = df.epoch.apply(time.ctime)

or something like (if he needs strings) ->

df['dt'] = df.epoch.apply(lambda a:time.strftime('%Y-%m-%d %H:%M:%S',
time.localtime(a))
df['dt'] = df.epoch.apply(lambda a:time.strftime('%Y-%m-%d %H:%M:%S',
time.gmtime(a))  # if utc is desired

On 6/15/17, Andre Müller  wrote:
> I'm not familar with pandas.
>
> If you look on stackoverfolow you'll find this solution:
>
> df.epoch = pd.to_datetime(df.epoch)
> https://stackoverflow.com/questions/17134716/convert-dataframe-column-type-from-string-to-datetime
>
> But in this case, it's not a plain string, then it's a datetime object.
>
> Greetings
> Andre
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT] is JSON all that great? - was Re: API Help

2017-06-14 Thread justin walters
On Wed, Jun 14, 2017 at 7:33 PM, Michael Torrie  wrote:

> On 06/14/2017 05:06 PM, justin walters wrote:
> > JSON in Python is such a joy! :)
>
> I understand that in this case the data is coming from a server in a
> form intended for easy use with Javascript.  But other than this type of
> communication, I don't see any good reason to choose JSON as a data
> interchange format.
>
> To me JSON seems to hold no real benefits over other serialization
> techniques, including the XML beast. XML may be verbose, but at least
> XML data can be formally validated and formally transformed and queried,
> which is certainly not the case with JSON as we can see from this long
> thread.  JSON's mantra seems to be try parsing it and see what happens.
> Whether it works depends on the parser and any quirks it has (quotes vs
> single quotes, etc).  I don't find JSON any more human readable than XML
> to be honest, perhaps less so because there's no way to define a formal
> schema to follow, at least that I'm aware of.
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

There are 2 main issues with XML:

1) It is not secure. Check this out:
https://stackoverflow.com/questions/1906927/xml-vulnerabilities#1907500

2) It is large. JSON can express the same amount of information while
using much less memory. There are many reasons for this, but the simplest
is that JSON formatting requires less characters.

Also, there are several formal schemas to follow. The most popular is
JSONAPI.

JSON is also fundamentally much simpler than XML. There are strings,
numbers,
arrays, and objects. That's it. It is basically a dumbed down Python
dictionary.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT] is JSON all that great? - was Re: API Help

2017-06-14 Thread Grant Edwards
On 2017-06-15, Michael Torrie  wrote:
> On 06/14/2017 05:06 PM, justin walters wrote:
>> JSON in Python is such a joy! :)

100% agreement here.

> I understand that in this case the data is coming from a server in a
> form intended for easy use with Javascript.  But other than this
> type of communication, I don't see any good reason to choose JSON as
> a data interchange format.
>
> To me JSON seems to hold no real benefits over other serialization
> techniques,

A JSON library is usually several orders of magnitude smaller, faster,
and easier to use than an XML library.  To some of us, that matters a
lot.

> including the XML beast. XML may be verbose, but at least XML data
> can be formally validated

To paraphrase Knuth: You can prove an XML file is correct -- but it
still won't work. ;)

Every time I've used anything involving XML, it was a complete and
utter nightmare with no two toolsets/libraries able to agree on
anything.  OTOH, I've been using JSON for years, and never run into
problems like that.  Verifying files from schemas never worked,
transforming files never worked.

I hate XML with a passion...

JSON does have it's warts: it should allow trailing commas in
sequences of object or array entries.  Most parsers don't try to do
any sort of error recovery: either the file parses, and you get all
the data, or it fails and you get nothing.

--
Grant



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


Re: API Help

2017-06-14 Thread justin walters
On Wed, Jun 14, 2017 at 6:00 PM, Ned Batchelder 
wrote:

> On Wednesday, June 14, 2017 at 7:06:39 PM UTC-4, justin walters wrote:
> > JSON and Python dictionaries have nearly the exact same syntax. That's
> why
> > working with
> > JSON in Python is such a joy! :)
> >
> > You can paste any valid JSON into a Python REPL and it will be
> interpreted
> > as a Python dictionary.
>
> Careful: JSON booleans are true and false, not True and False, and the
> missing
> value is null, not None.  So valid JSON might not be readable as Python.
>
> --Ned.
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Oh! Yep!

I haven't run into this issue because I generally don't run ``eval()`` on
random data from the internet. I usually use either the built in ``json``
module
or ``marshmallow`` if I have a strict schema to conform to.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT] is JSON all that great? - was Re: API Help

2017-06-14 Thread Skip Montanaro
On Wed, Jun 14, 2017 at 9:33 PM, Michael Torrie  wrote:
> To me JSON seems to hold no real benefits over other serialization
> techniques, including the XML beast.

I guess we'll have to agree to disagree. XML is the Devil's spawn,
hiding its real intent inside layer after layer of tags. In contrast,
JSON is Hello Kitty, all cute and pink, just dictionaries, lists, and
scalars. 

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


Re: API Help

2017-06-14 Thread justin walters
On Wed, Jun 14, 2017 at 4:40 PM, Grant Edwards 
wrote:

> On 2017-06-14, justin walters  wrote:
>
> > I should also specify that the data you have received is malformed.
> >
> > JSON should always have an object as the top level structure, not an
> > array as in your data.
>
> Where is that requirement stated?
>
> RFC7159 explicitly states that a "conforming JSON text" can be either
> an array or an object:
>
>
>2.  JSON Grammar
>
>A JSON text is a sequence of tokens.  The set of tokens includes
>six structural characters, strings, numbers, and three literal
>names.
>
>A JSON text is a serialized value.  Note that certain previous
>specifications of JSON constrained a JSON text to be an object or
>an array.  Implementations that generate only objects or arrays
>where a JSON text is called for will be interoperable in the sense
>that all implementations will accept these as conforming JSON
>texts.
>
> The grammar specified by later in that section also allow a JSON text
> to contain nothing but a single simple value: string, number 'null'
> 'true' or 'false'.  IOW, a file containing a single digit (0-9) is
> valid JSON.
>
> --
> Grant
>
>
>
>
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

That's why I said "should", not "required".

Generally, it's considered best practice for web APIs.

I also did not say that the data is "invalid", I said it is "malformed".
-- 
https://mail.python.org/mailman/listinfo/python-list


data structure

2017-06-14 Thread Andrew Zyman
Hello,
 i wonder what would be a proper data structure for something with the
following characteristics:

id - number,
obj[a..c] - objects of various classes

the idea is to be able to update certain fields of these objects initially
getting access to the record by ID

something like this ( not working )

### code start

class ClassA(object):
a = ''
b = ''
def __init__(self):
a= 'aa'
b= 'ab'

class ClassB(object):
def __init__(self):
self.c = 'ba'
self.d = 'bb'

def main():
obja = ClassA
objb = ClassB

sets = set(obja, objb)
contracts[1] = sets

print('Sets ', contracts)

# with the logic like ( not working too)
if obja.a = 'aa':
contracts[1].obja.a = 'ABC'


 if __name__ == '__main__':
main()


### code end

appreciate your guidance
-- 
https://mail.python.org/mailman/listinfo/python-list


[OT] is JSON all that great? - was Re: API Help

2017-06-14 Thread Michael Torrie
On 06/14/2017 05:06 PM, justin walters wrote:
> JSON in Python is such a joy! :)

I understand that in this case the data is coming from a server in a
form intended for easy use with Javascript.  But other than this type of
communication, I don't see any good reason to choose JSON as a data
interchange format.

To me JSON seems to hold no real benefits over other serialization
techniques, including the XML beast. XML may be verbose, but at least
XML data can be formally validated and formally transformed and queried,
which is certainly not the case with JSON as we can see from this long
thread.  JSON's mantra seems to be try parsing it and see what happens.
Whether it works depends on the parser and any quirks it has (quotes vs
single quotes, etc).  I don't find JSON any more human readable than XML
to be honest, perhaps less so because there's no way to define a formal
schema to follow, at least that I'm aware of.


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


Re: How do you use Python 3.5 and Python 3.6 in production

2017-06-14 Thread Chris Angelico
On Thu, Jun 15, 2017 at 9:46 AM, Amirouche Boubekki
 wrote:
> I'd like to use Python 3.5 or Python 3.6 in production but avoid the use of
> pip and virtualenv.
>
> Is there a solution based on a popular GNU/Linux distribution that allows
> to keep up with the release of Python 3.x and various other highly prolific
> project but still young like aiohttp?
>
> What I am looking for is the ability to have reproducible builds in the
> form of lxc templates (or maybe somekind of docker magic) but without the
> need to maintain another package repository.
>
> I hope my question is clear.

I generally build the very latest from source control. (Presumably
it'll be the same if you get a .tar.gz archive, but I haven't tested
it.) Either way, you'll generally do something like this:

$ sudo apt build-dep python3
$ ./configure
$ make
$ sudo make install

and that should give you a fully working Python. And here's the thing:
for a modern Python, "fully working" includes having pip available.
I'm not sure what the advantage is of avoiding pip, but if your idea
is to avoid trampling on the system Python, the easiest way is to use
the inbuilt venv (rather than the third-party virtualenv) and use
that.

To keep up with projects like aiohttp, you're either going to need to
use pip, or you're going to install them manually. I strongly
recommend the former.

$ python3 -m venv env
$ source env/bin/activate
$ pip install aiohttp

That's usually the safest way to do things IMO.

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


Re: API Help

2017-06-14 Thread Ned Batchelder
On Wednesday, June 14, 2017 at 7:06:39 PM UTC-4, justin walters wrote:
> JSON and Python dictionaries have nearly the exact same syntax. That's why
> working with
> JSON in Python is such a joy! :)
> 
> You can paste any valid JSON into a Python REPL and it will be interpreted
> as a Python dictionary.

Careful: JSON booleans are true and false, not True and False, and the missing
value is null, not None.  So valid JSON might not be readable as Python.

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


Re: API Help

2017-06-14 Thread Ray Cote
On Wed, Jun 14, 2017 at 6:14 PM, Erik  wrote:

> On 14/06/17 22:54, Ray Cote wrote:
>
>> Definitely JSON:
>>
>>>
> json.loads(“""[{"itemNumber":"75-5044","inventory":[{"wareho
>> useCode":"UT-1-US","quantityAvailable":0.0},{"wa
>> rehouseCode":"KY-1-US","quantityAvailable":0.0},
>> {"warehouseCode":"TX-1-US","quantityAvailable":14.00
>> 000},{"warehouseCode":"CA-1-US","quantityAvailable":4.
>> 0},{"warehouseCode":"AB-1-CA","quantityAvailable":
>> 1.0},{"warehouseCode":"WA-1-US","quantityAvailab
>> le":0.0},{"warehouseCode":"PO-1-CA","quantityAva
>> ilable":0.0}]}]""")
>>
>> [{u’itemNumber': u'75-5044', u'inventory': [{u'quantityAvailable': 0.0,
>> u'warehouseCode': u'UT-1-US'}, {u'quantityAvailable': 0.0,
>> u'warehouseCode': u'KY-1-US'}, {u'quantityAvailable': 14.0,
>> u'warehouseCode': u'TX-1-US'}, {u'quantityAvailable': 4.0,
>> u'warehouseCode': u'CA-1-US'}, {u'quantityAvailable': 1.0,
>> u'warehouseCode': u'AB-1-CA'}, {u'quantityAvailable': 0.0,
>> u'warehouseCode': u'WA-1-US'}, {u'quantityAvailable': 0.0,
>> u'warehouseCode': u'PO-1-CA'}]}]
>>
>>>
>
> If that makes it definitely JSON, then this makes it definitely Python ;) :
>
> >>> [{"itemNumber":"75-5044","inventory":[{"warehouseCode":"UT-
> 1-US","quantityAvailable":0.0},{"warehouseCode
> ":"KY-1-US","quantityAvailable":0.0},{"warehouse
> Code":"TX-1-US","quantityAvailable":14.0},{"ware
> houseCode":"CA-1-US","quantityAvailable":4.0},{"
> warehouseCode":"AB-1-CA","quantityAvailable":1.0
> },{"warehouseCode":"WA-1-US","quantityAvailable":0.0
> },{"warehouseCode":"PO-1-CA","quantityAvailable":0.0}]}]
> [{'itemNumber': '75-5044', 'inventory': [{'quantityAvailable': 0.0,
> 'warehouseCode': 'UT-1-US'}, {'quantityAvailable': 0.0, 'warehouseCode':
> 'KY-1-US'}, {'quantityAvailable': 14.0, 'warehouseCode': 'TX-1-US'},
> {'quantityAvailable': 4.0, 'warehouseCode': 'CA-1-US'},
> {'quantityAvailable': 1.0, 'warehouseCode': 'AB-1-CA'},
> {'quantityAvailable': 0.0, 'warehouseCode': 'WA-1-US'},
> {'quantityAvailable': 0.0, 'warehouseCode': 'PO-1-CA'}]}]
>
>
>
> So, I think we're agreed that it's definitely one or the other.
>

Well, that is the Python output from the json.loads() call; so yes…


-- 
Raymond Cote, President
voice: +1.603.924.6079 email: rgac...@appropriatesolutions.com skype:
ray.cote
Schedule a meeting: https://calendly.com/ray_cote/60min/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you use Python 3.5 and Python 3.6 in production

2017-06-14 Thread Andre Müller
Hi,
I'm using Arch Linux. There is currently Python 3.6 the standard
interpreter.
But I think it's not good to use this in production.

Hm, maybe pyenv can be an distribution independent solution:
https://github.com/pyenv/pyenv
If you're using pyenv, then you'll have some build dependencies.

One time I've used a Debian repository to install Python 3.6 somewhere (can
not remind where).
But then you rely on the user, who is managing the repository.

I often build my own Python version. If you're willing to do this, you can
build your own packages
on your own repository. Then you can install this version on your
production without having there the
whole build dependencies. But this is additional work.

Amirouche Boubekki  schrieb am Do., 15. Juni
2017 um 01:47 Uhr:

> Héllo,
>
>
> I'd like to use Python 3.5 or Python 3.6 in production but avoid the use of
> pip and virtualenv.
>
> Is there a solution based on a popular GNU/Linux distribution that allows
> to keep up with the release of Python 3.x and various other highly prolific
> project but still young like aiohttp?
>
> What I am looking for is the ability to have reproducible builds in the
> form of lxc templates (or maybe somekind of docker magic) but without the
> need to maintain another package repository.
>
> I hope my question is clear.
>
> Thanks in advance!
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Converting epoch to string in format yyyy-mm-dd, or maybe it is not necessary

2017-06-14 Thread Andre Müller
I'm not familar with pandas.

If you look on stackoverfolow you'll find this solution:

df.epoch = pd.to_datetime(df.epoch)
https://stackoverflow.com/questions/17134716/convert-dataframe-column-type-from-string-to-datetime

But in this case, it's not a plain string, then it's a datetime object.

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


Re: API Help

2017-06-14 Thread Erik

On 15/06/17 00:45, Chris Angelico wrote:

Add all that
kind of thing together, and you get my original conclusion that this
is JSON. It's also perfectly parseable as various other things, but
it's still most likely to be JSON.


It "is JSON" but is also "parsable as various other things" yet is "most 
likely to be JSON".


I think it is reasonable to interpret that as "Might not be JSON", which 
was my original point (ignoring my fubar with the quoted keys thing).


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


How do you use Python 3.5 and Python 3.6 in production

2017-06-14 Thread Amirouche Boubekki
Héllo,


I'd like to use Python 3.5 or Python 3.6 in production but avoid the use of
pip and virtualenv.

Is there a solution based on a popular GNU/Linux distribution that allows
to keep up with the release of Python 3.x and various other highly prolific
project but still young like aiohttp?

What I am looking for is the ability to have reproducible builds in the
form of lxc templates (or maybe somekind of docker magic) but without the
need to maintain another package repository.

I hope my question is clear.

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


Re: API Help

2017-06-14 Thread Chris Angelico
On Thu, Jun 15, 2017 at 8:34 AM, Erik  wrote:
> On 14/06/17 22:30, Chris Angelico wrote:
>>
>> It wouldn't be the repr() of a Python structure, as that wouldn't have
>> all those trailing zeroes.
>
>
> That depends on what class represents those float values. It doesn't have to
> be the built-in float. Same with the double-quotes instead of single-quotes
> on the strings.
>
> I still think it _could_ be the output of a Python repr() or similar
> (something that is expected to be evaluated as a Python expression). I'm not
> saying it *is*, and secretly I agree that it's probably not, but it _could_
> be.

JSON mandates double quotes, even though JS and Python both support
single. Python's built-in float won't repr like that. Add all that
kind of thing together, and you get my original conclusion that this
is JSON. It's also perfectly parseable as various other things, but
it's still most likely to be JSON.

But...

On Thu, Jun 15, 2017 at 9:08 AM, justin walters
 wrote:
> I should also specify that the data you have received is malformed.
>
> JSON should always have an object as the top level structure, not an
> array as in your data.

... JSON doesn't actually mandate that. You can use any top-level
type. The string '"hello"' is a valid JSON-decodable value.

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


Re: API Help

2017-06-14 Thread Grant Edwards
On 2017-06-14, justin walters  wrote:

> I should also specify that the data you have received is malformed.
>
> JSON should always have an object as the top level structure, not an
> array as in your data.

Where is that requirement stated?  

RFC7159 explicitly states that a "conforming JSON text" can be either
an array or an object:


   2.  JSON Grammar

   A JSON text is a sequence of tokens.  The set of tokens includes
   six structural characters, strings, numbers, and three literal
   names.

   A JSON text is a serialized value.  Note that certain previous
   specifications of JSON constrained a JSON text to be an object or
   an array.  Implementations that generate only objects or arrays
   where a JSON text is called for will be interoperable in the sense
   that all implementations will accept these as conforming JSON
   texts.

The grammar specified by later in that section also allow a JSON text
to contain nothing but a single simple value: string, number 'null'
'true' or 'false'.  IOW, a file containing a single digit (0-9) is
valid JSON.

-- 
Grant







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


Re: API Help

2017-06-14 Thread Erik

On 15/06/17 00:08, justin walters wrote:

I should also specify that the data you have received is malformed.

JSON should always have an object as the top level structure, not an
array as in your data.


So it's not JSON then? :D

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


Re: API Help

2017-06-14 Thread justin walters
On Wed, Jun 14, 2017 at 4:06 PM, justin walters 
wrote:

>
>
> On Wed, Jun 14, 2017 at 3:49 PM, Grant Edwards 
> wrote:
>
>> On 2017-06-14, Erik  wrote:
>> > On 14/06/17 22:54, Ray Cote wrote:
>> >> Definitely JSON:
>> >
>> >> json.loads(“""[{"itemNumber":"75-5044","inventory":[{"wareho
>> useCode":"UT-1-US","quantityAvailable":0.0},{"wa
>> rehouseCode":"KY-1-US","quantityAvailable":0.0},
>> {"warehouseCode":"TX-1-US","quantityAvailable":14.00
>> 000},{"warehouseCode":"CA-1-US","quantityAvailable":4.
>> 0},{"warehouseCode":"AB-1-CA","quantityAvailable":
>> 1.0},{"warehouseCode":"WA-1-US","quantityAvailab
>> le":0.0},{"warehouseCode":"PO-1-CA","quantityAva
>> ilable":0.0}]}]""")
>> [...]
>> >
>> > If that makes it definitely JSON, then this makes it definitely Python
>> ;) :
>> > >>>
>> > [{"itemNumber":"75-5044","inventory":[{"warehouseCode":"UT-
>> 1-US","quantityAvailable":0.0},{"warehouseCode
>> ":"KY-1-US","quantityAvailable":0.0},{"warehouse
>> Code":"TX-1-US","quantityAvailable":14.0},{"ware
>> houseCode":"CA-1-US","quantityAvailable":4.0},{"
>> warehouseCode":"AB-1-CA","quantityAvailable":1.0
>> },{"warehouseCode":"WA-1-US","quantityAvailable":0.0
>> },{"warehouseCode":"PO-1-CA","quantityAvailable":0.0}]}]
>>
>> Indeed.
>>
>> > So, I think we're agreed that it's definitely one or the other.
>>
>> It's both a floor wax _and_ a dessert topping!
>>
>> --
>> Grant
>>
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>
> JSON and Python dictionaries have nearly the exact same syntax. That's why
> working with
> JSON in Python is such a joy! :)
>
> You can paste any valid JSON into a Python REPL and it will be interpreted
> as a Python
> dictionary.
>
> I can assure you with 99.~% confidence that the data you are receiving
> from the API
> is JSON data. You will find very few web APIs around nowadays that aren't
> using JSON or
> JSONB(binary representation of JSON).
>
> All that said, you can use the built in ``json`` module to convert the raw
> data into a Python
> dictionary in the following manner(assuming you are using Python 3.2+).
>
> ```
> import json
>
> response_data = "..." # This is the received JSON data as a binary string.
>
> data = json.loads(
> str(response_data, encoding="utf8")
> )
>
> data["itemNumber"]
>
> >>> "75-5044"
> ```
>
> Hope that helps.
>

I should also specify that the data you have received is malformed.

JSON should always have an object as the top level structure, not an
array as in your data.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: API Help

2017-06-14 Thread Rob Gaddi

On 06/14/2017 03:49 PM, Grant Edwards wrote:

On 2017-06-14, Erik  wrote:

On 14/06/17 22:54, Ray Cote wrote:

Definitely JSON:



json.loads(“""[{"itemNumber":"75-5044","inventory":[{"warehouseCode":"UT-1-US","quantityAvailable":0.0},{"warehouseCode":"KY-1-US","quantityAvailable":0.0},{"warehouseCode":"TX-1-US","quantityAvailable":14.0},{"warehouseCode":"CA-1-US","quantityAvailable":4.0},{"warehouseCode":"AB-1-CA","quantityAvailable":1.0},{"warehouseCode":"WA-1-US","quantityAvailable":0.0},{"warehouseCode":"PO-1-CA","quantityAvailable":0.0}]}]""")

[...]


If that makes it definitely JSON, then this makes it definitely Python ;) :



[{"itemNumber":"75-5044","inventory":[{"warehouseCode":"UT-1-US","quantityAvailable":0.0},{"warehouseCode":"KY-1-US","quantityAvailable":0.0},{"warehouseCode":"TX-1-US","quantityAvailable":14.0},{"warehouseCode":"CA-1-US","quantityAvailable":4.0},{"warehouseCode":"AB-1-CA","quantityAvailable":1.0},{"warehouseCode":"WA-1-US","quantityAvailable":0.0},{"warehouseCode":"PO-1-CA","quantityAvailable":0.0}]}]


Indeed.


So, I think we're agreed that it's definitely one or the other.


It's both a floor wax _and_ a dessert topping!



Since it's viable directly as Python code, you should just eval() the 
random thing you got from the Internet and use the result.[*]_


.. [*] Don't do that.  Don't ever, EVER do that.

--
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
--
https://mail.python.org/mailman/listinfo/python-list


Re: API Help

2017-06-14 Thread justin walters
On Wed, Jun 14, 2017 at 3:49 PM, Grant Edwards 
wrote:

> On 2017-06-14, Erik  wrote:
> > On 14/06/17 22:54, Ray Cote wrote:
> >> Definitely JSON:
> >
> >> json.loads(“""[{"itemNumber":"75-5044","inventory":[{"
> warehouseCode":"UT-1-US","quantityAvailable":0.0},{"
> warehouseCode":"KY-1-US","quantityAvailable":0.0},{"
> warehouseCode":"TX-1-US","quantityAvailable":14.0},{"
> warehouseCode":"CA-1-US","quantityAvailable":4.0},{"
> warehouseCode":"AB-1-CA","quantityAvailable":1.0},{"
> warehouseCode":"WA-1-US","quantityAvailable":0.0},{"
> warehouseCode":"PO-1-CA","quantityAvailable":0.0}]}]""")
> [...]
> >
> > If that makes it definitely JSON, then this makes it definitely Python
> ;) :
> > >>>
> > [{"itemNumber":"75-5044","inventory":[{"warehouseCode":"
> UT-1-US","quantityAvailable":0.0},{"warehouseCode":"KY-1-US","
> quantityAvailable":0.0},{"warehouseCode":"TX-1-US","
> quantityAvailable":14.0},{"warehouseCode":"CA-1-US","
> quantityAvailable":4.0},{"warehouseCode":"AB-1-CA","
> quantityAvailable":1.0},{"warehouseCode":"WA-1-US","
> quantityAvailable":0.0},{"warehouseCode":"PO-1-CA","
> quantityAvailable":0.0}]}]
>
> Indeed.
>
> > So, I think we're agreed that it's definitely one or the other.
>
> It's both a floor wax _and_ a dessert topping!
>
> --
> Grant
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

JSON and Python dictionaries have nearly the exact same syntax. That's why
working with
JSON in Python is such a joy! :)

You can paste any valid JSON into a Python REPL and it will be interpreted
as a Python
dictionary.

I can assure you with 99.~% confidence that the data you are receiving
from the API
is JSON data. You will find very few web APIs around nowadays that aren't
using JSON or
JSONB(binary representation of JSON).

All that said, you can use the built in ``json`` module to convert the raw
data into a Python
dictionary in the following manner(assuming you are using Python 3.2+).

```
import json

response_data = "..." # This is the received JSON data as a binary string.

data = json.loads(
str(response_data, encoding="utf8")
)

data["itemNumber"]

>>> "75-5044"
```

Hope that helps.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: API Help

2017-06-14 Thread Grant Edwards
On 2017-06-14, Erik  wrote:
> On 14/06/17 22:54, Ray Cote wrote:
>> Definitely JSON:
>
>> json.loads(“""[{"itemNumber":"75-5044","inventory":[{"warehouseCode":"UT-1-US","quantityAvailable":0.0},{"warehouseCode":"KY-1-US","quantityAvailable":0.0},{"warehouseCode":"TX-1-US","quantityAvailable":14.0},{"warehouseCode":"CA-1-US","quantityAvailable":4.0},{"warehouseCode":"AB-1-CA","quantityAvailable":1.0},{"warehouseCode":"WA-1-US","quantityAvailable":0.0},{"warehouseCode":"PO-1-CA","quantityAvailable":0.0}]}]""")
[...]
>
> If that makes it definitely JSON, then this makes it definitely Python ;) :
> >>> 
> [{"itemNumber":"75-5044","inventory":[{"warehouseCode":"UT-1-US","quantityAvailable":0.0},{"warehouseCode":"KY-1-US","quantityAvailable":0.0},{"warehouseCode":"TX-1-US","quantityAvailable":14.0},{"warehouseCode":"CA-1-US","quantityAvailable":4.0},{"warehouseCode":"AB-1-CA","quantityAvailable":1.0},{"warehouseCode":"WA-1-US","quantityAvailable":0.0},{"warehouseCode":"PO-1-CA","quantityAvailable":0.0}]}]

Indeed.

> So, I think we're agreed that it's definitely one or the other.

It's both a floor wax _and_ a dessert topping!

-- 
Grant

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


Re: API Help

2017-06-14 Thread Erik

On 14/06/17 22:30, Chris Angelico wrote:

It wouldn't be the repr() of a Python structure, as that wouldn't have
all those trailing zeroes.


That depends on what class represents those float values. It doesn't 
have to be the built-in float. Same with the double-quotes instead of 
single-quotes on the strings.


I still think it _could_ be the output of a Python repr() or similar 
(something that is expected to be evaluated as a Python expression). I'm 
not saying it *is*, and secretly I agree that it's probably not, but it 
_could_ be.


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


Re: API Help

2017-06-14 Thread Erik

On 14/06/17 22:54, Ray Cote wrote:

Definitely JSON:



json.loads(“""[{"itemNumber":"75-5044","inventory":[{"warehouseCode":"UT-1-US","quantityAvailable":0.0},{"warehouseCode":"KY-1-US","quantityAvailable":0.0},{"warehouseCode":"TX-1-US","quantityAvailable":14.0},{"warehouseCode":"CA-1-US","quantityAvailable":4.0},{"warehouseCode":"AB-1-CA","quantityAvailable":1.0},{"warehouseCode":"WA-1-US","quantityAvailable":0.0},{"warehouseCode":"PO-1-CA","quantityAvailable":0.0}]}]""")

[{u’itemNumber': u'75-5044', u'inventory': [{u'quantityAvailable': 0.0,
u'warehouseCode': u'UT-1-US'}, {u'quantityAvailable': 0.0,
u'warehouseCode': u'KY-1-US'}, {u'quantityAvailable': 14.0,
u'warehouseCode': u'TX-1-US'}, {u'quantityAvailable': 4.0,
u'warehouseCode': u'CA-1-US'}, {u'quantityAvailable': 1.0,
u'warehouseCode': u'AB-1-CA'}, {u'quantityAvailable': 0.0,
u'warehouseCode': u'WA-1-US'}, {u'quantityAvailable': 0.0,
u'warehouseCode': u'PO-1-CA'}]}]




If that makes it definitely JSON, then this makes it definitely Python ;) :

>>> 
[{"itemNumber":"75-5044","inventory":[{"warehouseCode":"UT-1-US","quantityAvailable":0.0},{"warehouseCode":"KY-1-US","quantityAvailable":0.0},{"warehouseCode":"TX-1-US","quantityAvailable":14.0},{"warehouseCode":"CA-1-US","quantityAvailable":4.0},{"warehouseCode":"AB-1-CA","quantityAvailable":1.0},{"warehouseCode":"WA-1-US","quantityAvailable":0.0},{"warehouseCode":"PO-1-CA","quantityAvailable":0.0}]}]
[{'itemNumber': '75-5044', 'inventory': [{'quantityAvailable': 0.0, 
'warehouseCode': 'UT-1-US'}, {'quantityAvailable': 0.0, 'warehouseCode': 
'KY-1-US'}, {'quantityAvailable': 14.0, 'warehouseCode': 'TX-1-US'}, 
{'quantityAvailable': 4.0, 'warehouseCode': 'CA-1-US'}, 
{'quantityAvailable': 1.0, 'warehouseCode': 'AB-1-CA'}, 
{'quantityAvailable': 0.0, 'warehouseCode': 'WA-1-US'}, 
{'quantityAvailable': 0.0, 'warehouseCode': 'PO-1-CA'}]}]




So, I think we're agreed that it's definitely one or the other.

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


Re: API Help

2017-06-14 Thread Andre Müller
Am 14.06.2017 um 22:33 schrieb Bradley Cooper:
> I am working with an API and I get a return response in this format.
>
>  
> [{"itemNumber":"75-5044","inventory":[{"warehouseCode":"UT-1-US","quantityAvailable":0.0},{"warehouseCode":"KY-1-US","quantityAvailable":0.0},{"warehouseCode":"TX-1-US","quantityAvailable":14.0},{"warehouseCode":"CA-1-US","quantityAvailable":4.0},{"warehouseCode":"AB-1-CA","quantityAvailable":1.0},{"warehouseCode":"WA-1-US","quantityAvailable":0.0},{"warehouseCode":"PO-1-CA","quantityAvailable":0.0}]}]
>
> What is the best way to read through the data?
>

Your data looks like Json.
First use the _json_ module to convert the _string_ into a _Python data
structure_.
Then you can iterate over it. My example is a nested loop. Maybe
you've more than one element inside the list.


import json

# the string looks like json
JSON_DATA = """[
{"itemNumber":"75-5044","inventory": [
{"warehouseCode":"UT-1-US","quantityAvailable":0.0},
{"warehouseCode":"KY-1-US","quantityAvailable":0.0},
{"warehouseCode":"TX-1-US","quantityAvailable":14.0},
{"warehouseCode":"CA-1-US","quantityAvailable":4.0},
{"warehouseCode":"AB-1-CA","quantityAvailable":1.0},
{"warehouseCode":"WA-1-US","quantityAvailable":0.0},
{"warehouseCode":"PO-1-CA","quantityAvailable":0.0}
]
}
]"""


# converting the json string to a Python data structure
inventory = json.loads(JSON_DATA)

# representation in Python
#[{'inventory': [{'quantityAvailable': 0.0, 'warehouseCode': 'UT-1-US'},
   #{'quantityAvailable': 0.0, 'warehouseCode': 'KY-1-US'},
   #{'quantityAvailable': 14.0, 'warehouseCode': 'TX-1-US'},
   #{'quantityAvailable': 4.0, 'warehouseCode': 'CA-1-US'},
   #{'quantityAvailable': 1.0, 'warehouseCode': 'AB-1-CA'},
   #{'quantityAvailable': 0.0, 'warehouseCode': 'WA-1-US'},
   #{'quantityAvailable': 0.0, 'warehouseCode': 'PO-1-CA'}],
  #'itemNumber': '75-5044'}]


# the interesting part
for items in inventory:
# get the elements in from the list
# the elements are dicts, in this case exactly one dict
print('itemNumber:', i['itemNumber'])
# nested loop iterating over the values of the key 'inventory'
for item in items['inventory']:
# the value is dict
code, qty = item['warehouseCode'],item['quantityAvailable']
print('warehouseCode:', code, 'quantityAvailable', qty)


# Output
#itemNumber: 75-5044
#warehouseCode: UT-1-US quantityAvailable 0.0
#warehouseCode: KY-1-US quantityAvailable 0.0
#warehouseCode: TX-1-US quantityAvailable 14.0
#warehouseCode: CA-1-US quantityAvailable 4.0
#warehouseCode: AB-1-CA quantityAvailable 1.0
#warehouseCode: WA-1-US quantityAvailable 0.0
#warehouseCode: PO-1-CA quantityAvailable 0.0


Greetings
Andre


signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: API Help

2017-06-14 Thread Ray Cote
On Wed, Jun 14, 2017 at 4:33 PM, Bradley Cooper  wrote:

> I am working with an API and I get a return response in this format.
>
>
> [{"itemNumber":"75-5044","inventory":[{"warehouseCode":"
> UT-1-US","quantityAvailable":0.0},{"warehouseCode":"KY-1-US","
> quantityAvailable":0.0},{"warehouseCode":"TX-1-US","
> quantityAvailable":14.0},{"warehouseCode":"CA-1-US","
> quantityAvailable":4.0},{"warehouseCode":"AB-1-CA","
> quantityAvailable":1.0},{"warehouseCode":"WA-1-US","
> quantityAvailable":0.0},{"warehouseCode":"PO-1-CA","
> quantityAvailable":0.0}]}]
>
> What is the best way to read through the data?
>

Definitely JSON:
>>>
json.loads(“""[{"itemNumber":"75-5044","inventory":[{"warehouseCode":"UT-1-US","quantityAvailable":0.0},{"warehouseCode":"KY-1-US","quantityAvailable":0.0},{"warehouseCode":"TX-1-US","quantityAvailable":14.0},{"warehouseCode":"CA-1-US","quantityAvailable":4.0},{"warehouseCode":"AB-1-CA","quantityAvailable":1.0},{"warehouseCode":"WA-1-US","quantityAvailable":0.0},{"warehouseCode":"PO-1-CA","quantityAvailable":0.0}]}]""")

[{u’itemNumber': u'75-5044', u'inventory': [{u'quantityAvailable': 0.0,
u'warehouseCode': u'UT-1-US'}, {u'quantityAvailable': 0.0,
u'warehouseCode': u'KY-1-US'}, {u'quantityAvailable': 14.0,
u'warehouseCode': u'TX-1-US'}, {u'quantityAvailable': 4.0,
u'warehouseCode': u'CA-1-US'}, {u'quantityAvailable': 1.0,
u'warehouseCode': u'AB-1-CA'}, {u'quantityAvailable': 0.0,
u'warehouseCode': u'WA-1-US'}, {u'quantityAvailable': 0.0,
u'warehouseCode': u'PO-1-CA'}]}]
>>>

-- 
Raymond Cote, President
voice: +1.603.924.6079 email: rgac...@appropriatesolutions.com skype:
ray.cote
Schedule a meeting: https://calendly.com/ray_cote/60min/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Ciphers in SSL library python.

2017-06-14 Thread Ray Cote
On Wed, Jun 14, 2017 at 4:40 PM,  wrote:

> Hey, I'm "the server(I've written using ssl/socket)" and my client is
> using RC4-SHA, but I can't make the server to use it. I make "
> ciphers='RC4-SHA' " in the ssl.wrap_socket. Do I need to modify SSL file or
> something to make it work?


Had not realized you were the server.

Been a long time since I used SSL, but here’s a few thoughts.
1: What version of Python are you using?
2: What version of OpenSSL are you using? RC4-SHA is considered insecure
and might be disabled at the OpenSSL/OS level.
3: You say you set ciphers=. I found some old code that used the
set_ciphers context call. That might be the approach.
—R


-- 
Raymond Cote, President
voice: +1.603.924.6079 email: rgac...@appropriatesolutions.com skype:
ray.cote
Schedule a meeting: https://calendly.com/ray_cote/60min/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: API Help

2017-06-14 Thread Peter Otten
Bradley Cooper wrote:

> Yes it is not json, I did try that with no luck.

What exactly did you try and how did it fail?

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


Re: API Help

2017-06-14 Thread Erik

On 14/06/17 22:16, Matt Wheeler wrote:

? JSON keys are quoted


Thanks Matt,

I was confusing myself between JS source and JSON. Good to have this 
reminder (I always use libraries for reading and writing JSON in 
whatever language, so while I view it often I very rarely have to type 
it in directly).


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


Re: API Help

2017-06-14 Thread Erik

On 14/06/17 22:18, Grant Edwards wrote:

What makes it look like JSON to you?


The fact that it _is_ valid JSON (at least according to the parsers
I've tried on it, both locally and using things like jsonlint.com).


And I tried it on the Python REPL. It's Python too.

If someone wrote the following on this list:

  foo = bar(1, x, 3 * (x - 1), frob("hello world"))

.. and I said "That looks like C to me", I suspect you and a lot of 
other people would ask me what makes me think that is C and not 
something else. Like Python, for example.



(I'm not arguing, I'm asking what I've missed).


My point was (I thought clearly) "What makes this exclusively JSON and 
not something else"? I even suggested that I was possibly missing 
something so as to come across as questioning and not argumentative. I 
guess that didn't work either.


E.

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


Re: API Help

2017-06-14 Thread Chris Angelico
On Thu, Jun 15, 2017 at 6:47 AM, Erik  wrote:
> On 14/06/17 21:38, Chris Angelico wrote:
>>
>> On Thu, Jun 15, 2017 at 6:33 AM, Bradley Cooper
>>  wrote:
>>>
>>> I am working with an API and I get a return response in this format.
>>>
>>>
>>>
>>> [{"itemNumber":"75-5044","inventory":[{"warehouseCode":"UT-1-US","quantityAvailable":0.0},{"warehouseCode":"KY-1-US","quantityAvailable":0.0},{"warehouseCode":"TX-1-US","quantityAvailable":14.0},{"warehouseCode":"CA-1-US","quantityAvailable":4.0},{"warehouseCode":"AB-1-CA","quantityAvailable":1.0},{"warehouseCode":"WA-1-US","quantityAvailable":0.0},{"warehouseCode":"PO-1-CA","quantityAvailable":0.0}]}]
>>>
>>> What is the best way to read through the data?
>>
>>
>> That looks like JSON.
>
>
> If the keys weren't quoted, I'd agree with you.
>
> It looks like a REPL representation of a Python structure to me (list of
> dicts where the values could also be lists of dicts ...
>
> What makes it look like JSON to you? (I'm not arguing, I'm asking what I've
> missed).

JSON, unlike JavaScript/ECMAScript itself, requires the keys to be
quoted. (It's legal to quote them in JS, but conventionally, people
omit the quotes where possible.)

It wouldn't be the repr() of a Python structure, as that wouldn't have
all those trailing zeroes. But you probably could parse it with
literal_eval all the same. Still, I'd go with JSON if at all possible.

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


Re: API Help

2017-06-14 Thread Matt Wheeler
On Wed, 14 Jun 2017 at 21:47 Erik  wrote:

> On 14/06/17 21:38, Chris Angelico wrote:
> > On Thu, Jun 15, 2017 at 6:33 AM, Bradley Cooper
> >  wrote:
> >> I am working with an API and I get a return response in this format.
> >>
> >>
> >>
> [{"itemNumber":"75-5044","inventory":[{"warehouseCode":"UT-1-US","quantityAvailable":0.0},{"warehouseCode":"KY-1-US","quantityAvailable":0.0},{"warehouseCode":"TX-1-US","quantityAvailable":14.0},{"warehouseCode":"CA-1-US","quantityAvailable":4.0},{"warehouseCode":"AB-1-CA","quantityAvailable":1.0},{"warehouseCode":"WA-1-US","quantityAvailable":0.0},{"warehouseCode":"PO-1-CA","quantityAvailable":0.0}]}]
> >>
> >> What is the best way to read through the data?
> >
> > That looks like JSON.
>

Yes


> If the keys weren't quoted, I'd agree with you.
>

? JSON keys are quoted


> It looks like a REPL representation of a Python structure to me (list of
> dicts where the values could also be lists of dicts ...
>
> What makes it look like JSON to you? (I'm not arguing, I'm asking what
> I've missed).
>

On Wed, 14 Jun 2017 at 21:54 Bradley Cooper 
wrote:

> Yes it is not json, I did try that with no luck.


What did you try?

% python
Python 2.7.13 (default, Feb 17 2017, 23:41:27)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> s = raw_input()
[{"itemNumber":"75-5044","inventory":[{"warehouseCode":"UT1-US","quantityAvailable":0.0},{"warehouseCode":"KY1US","quantityAvailable":0.0},{"warehouseCode":"TX-1-US","quantityAvailable":14.0},{"warehouseCode":"CA-1-US","quantityAvailable":4.0},{"warehouseCode":"AB-1-CA","quantityAvailable":1.0},{"warehouseCode":"WA-1-US","quantityAvailable":0.0},{"warehouseCode":"PO-1-CA","quantityAvailable":0.0}]}]
>>> json.loads(s)
[{u'inventory': [{u'quantityAvailable': 0.0, u'warehouseCode': u'UT1-US'},
 {u'quantityAvailable': 0.0, u'warehouseCode': u'KY1US'},
 {u'quantityAvailable': 14.0, u'warehouseCode': u'TX-1-US'},
 {u'quantityAvailable': 4.0, u'warehouseCode': u'CA-1-US'},
 {u'quantityAvailable': 1.0, u'warehouseCode': u'AB-1-CA'},
 {u'quantityAvailable': 0.0, u'warehouseCode': u'WA-1-US'},
 {u'quantityAvailable': 0.0, u'warehouseCode': u'PO-1-CA'}],
  u'itemNumber': u'75-5044'}]

Looks like json to me, and to json.loads, which is probably more
authoritative :)
-- 

--
Matt Wheeler
http://funkyh.at
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: API Help

2017-06-14 Thread Grant Edwards
On 2017-06-14, Erik  wrote:
> On 14/06/17 21:38, Chris Angelico wrote:
>> On Thu, Jun 15, 2017 at 6:33 AM, Bradley Cooper
>>  wrote:
>>> I am working with an API and I get a return response in this format.
>>>
>>>
>>> {"itemNumber":"75-5044","inventory":[{"warehouseCode":"UT-1-US","quantityAvailable":0.0},{"warehouseCode":"KY-1-US","quantityAvailable":0.0},{"warehouseCode":"TX-1-US","quantityAvailable":14.0},{"warehouseCode":"CA-1-US","quantityAvailable":4.0},{"warehouseCode":"AB-1-CA","quantityAvailable":1.0},{"warehouseCode":"WA-1-US","quantityAvailable":0.0},{"warehouseCode":"PO-1-CA","quantityAvailable":0.0}]}]
>>>
>>> What is the best way to read through the data?
>> 
>> That looks like JSON.

Yep.

> If the keys weren't quoted, I'd agree with you.

JSON keys _are_ quoted.

> It looks like a REPL representation of a Python structure to me (list of 
> dicts where the values could also be lists of dicts ...
>
> What makes it look like JSON to you?

The fact that it _is_ valid JSON (at least according to the parsers
I've tried on it, both locally and using things like jsonlint.com).

> (I'm not arguing, I'm asking what I've missed).


-- 
Grant Edwards   grant.b.edwardsYow! I request a weekend in
  at   Havana with Phil Silvers!
  gmail.com

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


Re: API Help

2017-06-14 Thread Erik

On 14/06/17 21:47, Erik wrote:
What makes it look like JSON to you? (I'm not arguing, I'm asking what 
I've missed).


If I cut-and-paste the OP's structure into the REPL, it replies with a 
valid Python structure that's equivalent (albeit with single-quotes 
instead of double-quotes).


So I guess I'm only partially arguing. I agree that it therefore looks 
like it's not REPL output, but perhaps the actual input that the OP 
needs to deal with (from whatever). Still not exclusively JSON though ;)






To the OP: start a Python shell and paste your structure as follows:

foo = 
[{"itemNumber":"75-5044","inventory":[{"warehouseCode":"UT1-US","quantityAvailable":0.0},{"warehouseCode":"KY1US","quantityAvailable":0.0},{"warehouseCode":"TX-1-US","quantityAvailable":14.0},{"warehouseCode":"CA-1-US","quantityAvailable":4.0},{"warehouseCode":"AB-1-CA","quantityAvailable":1.0},{"warehouseCode":"WA-1-US","quantityAvailable":0.0},{"warehouseCode":"PO-1-CA","quantityAvailable":0.0}]}]


Now you can interrogate your structure interactively to see what might 
be a good way of "reading through it" (you don't say what you actually 
want to do).


What does "foo[0]" show.
What does "foo[0]['inventory'] show?
What does "foo[0]['inventory'][1] show?
What does "foo[0]['inventory'][1]['warehouseCode'] show?

It's just lists (arrays) and dicts (key/value pairs).

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


Re: API Help

2017-06-14 Thread Bradley Cooper
Yes it is not json, I did try that with no luck.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: API Help

2017-06-14 Thread Erik

On 14/06/17 21:38, Chris Angelico wrote:

On Thu, Jun 15, 2017 at 6:33 AM, Bradley Cooper
 wrote:

I am working with an API and I get a return response in this format.


[{"itemNumber":"75-5044","inventory":[{"warehouseCode":"UT-1-US","quantityAvailable":0.0},{"warehouseCode":"KY-1-US","quantityAvailable":0.0},{"warehouseCode":"TX-1-US","quantityAvailable":14.0},{"warehouseCode":"CA-1-US","quantityAvailable":4.0},{"warehouseCode":"AB-1-CA","quantityAvailable":1.0},{"warehouseCode":"WA-1-US","quantityAvailable":0.0},{"warehouseCode":"PO-1-CA","quantityAvailable":0.0}]}]

What is the best way to read through the data?


That looks like JSON.


If the keys weren't quoted, I'd agree with you.

It looks like a REPL representation of a Python structure to me (list of 
dicts where the values could also be lists of dicts ...


What makes it look like JSON to you? (I'm not arguing, I'm asking what 
I've missed).


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


Re: Ciphers in SSL library python.

2017-06-14 Thread djnight538
To Ray Cote:

Hey, I'm "the server(I've written using ssl/socket)" and my client is using 
RC4-SHA, but I can't make the server to use it. I make " ciphers='RC4-SHA' " in 
the ssl.wrap_socket. Do I need to modify SSL file or something to make it work?


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


Re: API Help

2017-06-14 Thread Chris Angelico
On Thu, Jun 15, 2017 at 6:33 AM, Bradley Cooper
 wrote:
> I am working with an API and I get a return response in this format.
>
>
> [{"itemNumber":"75-5044","inventory":[{"warehouseCode":"UT-1-US","quantityAvailable":0.0},{"warehouseCode":"KY-1-US","quantityAvailable":0.0},{"warehouseCode":"TX-1-US","quantityAvailable":14.0},{"warehouseCode":"CA-1-US","quantityAvailable":4.0},{"warehouseCode":"AB-1-CA","quantityAvailable":1.0},{"warehouseCode":"WA-1-US","quantityAvailable":0.0},{"warehouseCode":"PO-1-CA","quantityAvailable":0.0}]}]
>
> What is the best way to read through the data?

That looks like JSON. Check out Python's json module:

https://docs.python.org/3/library/json.html

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


API Help

2017-06-14 Thread Bradley Cooper
I am working with an API and I get a return response in this format.

 
[{"itemNumber":"75-5044","inventory":[{"warehouseCode":"UT-1-US","quantityAvailable":0.0},{"warehouseCode":"KY-1-US","quantityAvailable":0.0},{"warehouseCode":"TX-1-US","quantityAvailable":14.0},{"warehouseCode":"CA-1-US","quantityAvailable":4.0},{"warehouseCode":"AB-1-CA","quantityAvailable":1.0},{"warehouseCode":"WA-1-US","quantityAvailable":0.0},{"warehouseCode":"PO-1-CA","quantityAvailable":0.0}]}]

What is the best way to read through the data?

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


Error while Importing Teradata in Python

2017-06-14 Thread mradul dhakad
Hi All ,

I am new to python .I have installed 3.6.1 python on my computer.
when i am trying to import teradata i am getting below error message:
Traceback (most recent call last)
File "C:\Users\mradul_dhakad\AppData\Local\Programs\Python\
Python36\Hello.py",
line 1, in 
import teradata
ModuleNot FoundError: No Module named 'teradata'

Could any one please let me know how to resolve this error.

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


Re: Ciphers in SSL library python.

2017-06-14 Thread Ray Cote
1: Are you 100% sure the server to which you are trying to connect supports
RC4-SHA?

2: If you have access to the server, turn on SSH debug mode to watch your
client try and connect.
I find that to be helpful in debugging many connection issues.


On Wed, Jun 14, 2017 at 4:16 PM,  wrote:

> Hey, I want to use RC4-SHA in python, but when I try to use it, it doesn't
> get used (If I do cipher() it says none(and handshake fails too)), I've
> tried to modify the SSL library, but it didn't help at all(Maybe I did
> something wrong, any help will be appreciated). Is there a way to use the
> RC4-SHA cipher(0x05). Please, I need help, I've been looking for an answer
> for days.
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Raymond Cote, President
voice: +1.603.924.6079 email: rgac...@appropriatesolutions.com skype:
ray.cote
Schedule a meeting: https://calendly.com/ray_cote/60min/
-- 
https://mail.python.org/mailman/listinfo/python-list


Ciphers in SSL library python.

2017-06-14 Thread djnight538
Hey, I want to use RC4-SHA in python, but when I try to use it, it doesn't get 
used (If I do cipher() it says none(and handshake fails too)), I've tried to 
modify the SSL library, but it didn't help at all(Maybe I did something wrong, 
any help will be appreciated). Is there a way to use the RC4-SHA cipher(0x05). 
Please, I need help, I've been looking for an answer for days.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Standard lib version of something like enumerate() that takes a max count iteration parameter?

2017-06-14 Thread Andre Müller
I'm a fan of infinite sequences. Try out itertools.islice.
You should not underestimate this very important module.

Please read also the documentation:
https://docs.python.org/3.6/library/itertools.html

from itertools import islice

iterable = range(100)
# since Python 3 range is a lazy evaluated object
# using this just as a dummy
# if you're using legacy Python (2.x), then use the xrange function for it
# or you'll get a memory error

max_count = 10
step = 1

for i, element in enumerate(islice(iterable, 0, max_count, step), start=1):
print(i, element)


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


Re: Standard lib version of something like enumerate() that takes a max count iteration parameter?

2017-06-14 Thread Malcolm Greene
Thank you Peter and Jussi - both your solutions were very helpful!

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


Re: Standard lib version of something like enumerate() that takes a max count iteration parameter?

2017-06-14 Thread Jussi Piitulainen
Malcolm Greene writes:

> Wondering if there's a standard lib version of something like
> enumerate() that takes a max count value?
> Use case: When you want to enumerate through an iterable, but want to
> limit the number of iterations without introducing if-condition-break
> blocks in code.
> Something like:
>
> for counter, key in enumerate( some_iterable, max_count=10 ):
> 
>
> Thank you,
> Malcolm

for counter, key in zip(range(10), some_iterable):

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


Re: Standard lib version of something like enumerate() that takes a max count iteration parameter?

2017-06-14 Thread Peter Otten
Malcolm Greene wrote:

> Wondering if there's a standard lib version of something like
> enumerate() that takes a max count value?
> Use case: When you want to enumerate through an iterable, but want to
> limit the number of iterations without introducing if-condition-break
> blocks in code.
> Something like:
> 
> for counter, key in enumerate( some_iterable, max_count=10 ):
> 

Usually you limit the iterable before passing it to enumerate():

for index, value in enumerate(some_seq[:max_count]):
...

When you have to deal with arbitrary iterables there's itertools.islice():

from itertools import islice

for index, value in enumerate(islice(some_iterable, max_count)):
   ...

Of course

for index, value in islice(enumerate(some_iterable), max_count):
   ...

is also possible.


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


Standard lib version of something like enumerate() that takes a max count iteration parameter?

2017-06-14 Thread Malcolm Greene
Wondering if there's a standard lib version of something like
enumerate() that takes a max count value?
Use case: When you want to enumerate through an iterable, but want to
limit the number of iterations without introducing if-condition-break
blocks in code.
Something like:

for counter, key in enumerate( some_iterable, max_count=10 ):


Thank you,
Malcolm
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python nmap for loop

2017-06-14 Thread Skip Montanaro
> I'm trying to make the following code work:
> ...

It seems fairly clear that you've posted code which couldn't possibly
run (missing a closing quote and right paren). Let me suggest:

1. You copy and paste directly from a Python (or IPython/Jupyter/IDLE)
session, including prompts and output.

2. You tell us what you expected to happen, and what actually happened.

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


dont exetute my exe after decompile and change code

2017-06-14 Thread Xristos Xristoou


i have an .exe file where file compiled by py2exe in my .exe folder i have some 
.dll files one .exe file and library.zip file and inside this zip i have to 
many .pyccombile files.

i have decompile this files from library.zip using this program and that 
program create me new file where i can see and change my code.

i have open this file where i need and i change my code using python editor and 
finaly i save as new script code with the some name and extension .pyc with 
purpose to replace first .pyc.

zip again library folder and i try to run .exe prgram but after the changes the 
program dont exetute.

where step i have wrong in my task ?i need with the some way to re-compile 
again ?
-- 
https://mail.python.org/mailman/listinfo/python-list


python nmap for loop

2017-06-14 Thread SS
I'm trying to make the following code work:

import os, sys

app=['host1', 'host2', 'host3']

for i in app:
os.system('nmap -p 22 -P0 %s | grep open 2>&1 > /dev/null && echo "%s up"


I've tried many different iterations of the os.system call, how to make this 
work?

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


Re: New to Python - Career question

2017-06-14 Thread Larry Martell
On Sat, Jun 10, 2017 at 3:51 AM, Paul Rubin  wrote:
> Larry Martell  writes:
>> I can tell they think I am old and they dismiss me right away.
>
> http://oldgeekjobs.com ?

Cool! Thanks! Sharing with all my old nerdy friends.
-- 
https://mail.python.org/mailman/listinfo/python-list