Breaking down network range to individual networks

2016-06-01 Thread Aaron Christensen
Hello,

Does anyone know about a feature of ipaddress that will take the following
network range:

"10.224.16.0-10.224.23.0"

and convert it to individual networks?

I am trying to figure out the best way to take a network range and break it
up into the largest possible networks.

I started working out some things on paper but I don't want to get too far
ahead of myself in case there is a function or easy way that already does
this.

Thank you for your help!
Aaron




-
Pasted some brainstorming below to show that I am actively working this and
not just asking before trying.


ipaddress.ip_network('10.224.16.0/24') - (ipaddress.ip_network('
10.224.23.0/24'))
IPv4Network

IPv4Network('10.224.16.0/24').compare_networks(IPv4Network('10.224.23.0/24')
)



str(ipaddress.IPv4Address('192.168.0.1'))

IPv4Address('10.224.16.0') + 3

ipaddress.ip_address('10.224.16.0') + 256


0.0.x=0.0
/24 x + 0
/23 x + 1 = 0.0.0.0
/22 x + 3 = 0.0.0.0

1  can be /18 if x = 0
2  can be /19 if x = 0, 32
4  can be /20 if x = 0, 16, 32, 48
8  can be /21 if x = 0, 8, 16, 24, 32, 40, 48, 56
16 can be /22 if x = 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52,
56, 60
32 can be /23 if x = 0 through 62


64 can be /24 if x = 0 though 255

10.224.255.0

start > can be
odd  > /24
even > /24/23
0  >  /22/21/20/19/18...
4  >  /22
8  >  /22/21
12 >  /22
16 >  /22/21/20
20 >  /22
24 >  /22/21
28 >  /22
32 >  /22/21/20/19
36 >  /22
40 >  /22/21
44 >  /22
48 >  /22/21/20
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Psycopg2 to create a record using a FK

2016-03-12 Thread Aaron Christensen
On Sat, Mar 12, 2016 at 9:57 PM, Aaron Christensen <
aaron.christen...@gmail.com> wrote:

>
>
> On Sat, Mar 12, 2016 at 5:03 AM, dieter <die...@handshake.de> wrote:
>
>> Aaron Christensen <aaron.christen...@gmail.com> writes:
>> > I am running the following versions of software:
>> >
>> > Python 3.5
>> > psycopg2==2.6.1
>> > Postgres 9.4.5
>> >
>> > I have 2 tables.  Table User has UserId (serial PK), LastName,
>> FirstName,
>> > Gender, DateOfBirth, and DateEnrolled.  Table UserProfile has
>> UserProfileId
>> > (serial, PK), UserId (FK), DateEntered, FaveNumber, and Activity.
>> There is
>> > a one-to-many relationship.
>> >
>> > The following PostgreSQL works and ultimately creates a record in
>> > UserProfile with an associated UserId (FK).
>> >
>> > \set last_name '''Sara'''
>> > \set first_name '''Jackson'''
>> > \set gender '''F'''
>> > \set dob '''1941-1-12'''
>> > \set fave_number '''3'''
>> > \set activity '''volleyball'''
>> >
>> >
>> > WITH ins_user AS (
>> > INSERT INTO User
>> > (LastName, FirstName, Gender, DateOfBirth, DateEnrolled)
>> > VALUES (:last_name, :first_name, :gender, :dob, now())
>> > RETURNING UserId)
>> > INSERT INTO UserProfile
>> > (UserId, DateEntered, FaveNumber, Activity)
>> > VALUES ( (SELECT UserId FROM ins_user), now(), :fave_number :activity);
>> >
>> > How can I build a psycopg2 cur.execute query that will accomplish the
>> above
>> > PostgreSQL?  I've read documentation but can't seem to get a handle on
>> how
>> > I should structure this command.
>> >
>> > My starting point is:
>> >
>> > cur.execute( \
>> > """INSERT INTO User \
>> > (LastName, FirstName, Gender, DateOfBirth, DateEnrolled) \
>> > VALUES (%s, %s, %s, %s, %s) RETURNING UserId;""", \
>> > (last_name, first_name, gender, date_of_birth, now(), ??...??)
>>
>> You can add "returning UserId" to this SQL command to get back
>> the id of the created user in your Python program. You can
>> then use this "UserId" to create the row in your dependent table.
>>
>> I use it like this in one of my programs:
>>
>>   cursor.execute("insert into service(...) "
>>  "values (...) returning id",
>>  (...)
>>  )
>>   id = cursor.fetchone()[0]
>>   cursor.execute(
>> "insert into product(..., f_service_id) "
>> "values (..., %s) returning id",
>> (..., id)
>> )
>>   id = cursor.fetchone()[0]
>>
>>
>>
>> Likely, there is also a way to bind the "UserId" inside SQL (maybe
>> via "SET") and use it in a second "INSERT" in the same call
>> to "cur.execute". Check the Postgres documentation for this.
>>
>>
>> > Also, I have a second question.  Is it possible to extract that value
>> > derived from "RETURNING UserId" so that it can be used in a later query?
>>
>> Sure -- see above.
>>
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>
>
> Hi Dieter,
>
> Thanks for the response.  I managed to get it working and also combined it
> with Peter's suggestion of passing a dictionary as an argument.  However, I
> am trying to figure out how I can get the RETURNING ID to be used in the
> next cur.execute().  Here is what I have been working on but have found
> many ways for it not to work.  My latest response is that the tuple indices
> must be integers or slices.
>
> # Here I initialize the dictionaries.  I will use each dictionary as an
> input into each cur.execute()
> user_input = dict(
> last_name = 'Jackson',
> first_name = 'Sara',
> gender = 'F',
> date_of_birth = '1941-1-12'
> )
>
> user_profile_input = dict(
> fave_number = 3,
> activity = 'volleyball'
> )
>
>
>
> # Create record in User // cur.execute(query, user_input)
> cur.execute("""
> INSERT INTO User
> (LastName, FirstName, Gender, DateOfBirth)
> VALUES (%(last_name)s, %(first_name)s, %(gender)s, %(date_of_birth))
> RETURNING UserId""",
> user_input)
> conn.commit()
> UserId = cur.fetchone()[0]#< --   HERE is the UserId
> print("UserId = %s" % UserId)
>
> # Create record in UserProfile // cur.execute(query, user_profile_input)
> cur.execute("

Re: Psycopg2 to create a record using a FK

2016-03-12 Thread Aaron Christensen
On Sat, Mar 12, 2016 at 5:03 AM, dieter <die...@handshake.de> wrote:

> Aaron Christensen <aaron.christen...@gmail.com> writes:
> > I am running the following versions of software:
> >
> > Python 3.5
> > psycopg2==2.6.1
> > Postgres 9.4.5
> >
> > I have 2 tables.  Table User has UserId (serial PK), LastName, FirstName,
> > Gender, DateOfBirth, and DateEnrolled.  Table UserProfile has
> UserProfileId
> > (serial, PK), UserId (FK), DateEntered, FaveNumber, and Activity.  There
> is
> > a one-to-many relationship.
> >
> > The following PostgreSQL works and ultimately creates a record in
> > UserProfile with an associated UserId (FK).
> >
> > \set last_name '''Sara'''
> > \set first_name '''Jackson'''
> > \set gender '''F'''
> > \set dob '''1941-1-12'''
> > \set fave_number '''3'''
> > \set activity '''volleyball'''
> >
> >
> > WITH ins_user AS (
> > INSERT INTO User
> > (LastName, FirstName, Gender, DateOfBirth, DateEnrolled)
> > VALUES (:last_name, :first_name, :gender, :dob, now())
> > RETURNING UserId)
> > INSERT INTO UserProfile
> > (UserId, DateEntered, FaveNumber, Activity)
> > VALUES ( (SELECT UserId FROM ins_user), now(), :fave_number :activity);
> >
> > How can I build a psycopg2 cur.execute query that will accomplish the
> above
> > PostgreSQL?  I've read documentation but can't seem to get a handle on
> how
> > I should structure this command.
> >
> > My starting point is:
> >
> > cur.execute( \
> > """INSERT INTO User \
> > (LastName, FirstName, Gender, DateOfBirth, DateEnrolled) \
> > VALUES (%s, %s, %s, %s, %s) RETURNING UserId;""", \
> > (last_name, first_name, gender, date_of_birth, now(), ??...??)
>
> You can add "returning UserId" to this SQL command to get back
> the id of the created user in your Python program. You can
> then use this "UserId" to create the row in your dependent table.
>
> I use it like this in one of my programs:
>
>   cursor.execute("insert into service(...) "
>  "values (...) returning id",
>  (...)
>  )
>   id = cursor.fetchone()[0]
>   cursor.execute(
> "insert into product(..., f_service_id) "
> "values (..., %s) returning id",
> (..., id)
> )
>   id = cursor.fetchone()[0]
>
>
>
> Likely, there is also a way to bind the "UserId" inside SQL (maybe
> via "SET") and use it in a second "INSERT" in the same call
> to "cur.execute". Check the Postgres documentation for this.
>
>
> > Also, I have a second question.  Is it possible to extract that value
> > derived from "RETURNING UserId" so that it can be used in a later query?
>
> Sure -- see above.
>
> --
> https://mail.python.org/mailman/listinfo/python-list


Hi Dieter,

Thanks for the response.  I managed to get it working and also combined it
with Peter's suggestion of passing a dictionary as an argument.  However, I
am trying to figure out how I can get the RETURNING ID to be used in the
next cur.execute().  Here is what I have been working on but have found
many ways for it not to work.  My latest response is that the tuple indices
must be integers or slices.

# Here I initialize the dictionaries.  I will use each dictionary as an
input into each cur.execute()
user_input = dict(
last_name = 'Jackson',
first_name = 'Sara',
gender = 'F',
date_of_birth = '1941-1-12'
)

user_profile_input = dict(
fave_number = 3,
activity = 'volleyball'
)



# Create record in User // cur.execute(query, user_input)
cur.execute("""
INSERT INTO User
(LastName, FirstName, Gender, DateOfBirth)
VALUES (%(last_name)s, %(first_name)s, %(gender)s, %(date_of_birth))
RETURNING UserId""",
user_input)
conn.commit()
UserId = cur.fetchone()[0]#< --   HERE is the UserId
print("UserId = %s" % UserId)

# Create record in UserProfile // cur.execute(query, user_profile_input)
cur.execute("""
INSERT INTO UserProfile
(FaveNumber, Activity, UserId)
VALUES (%(fave_number)s, %(activity)s, %s)< I tried
following your format
RETURNING UserProfileId""",
(user_profile_input, UserId)  # < This is what I'm trying
to figure out..  How to pass the UserId.
)
conn.commit()
UserProfileId = cur.fetchone()[0]
print("UserProfileId = %s" % UserProfileId)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Psycopg2 to create a record using a FK

2016-03-12 Thread Aaron Christensen
On Sat, Mar 12, 2016 at 5:26 AM, Peter Otten <__pete...@web.de> wrote:

> Aaron Christensen wrote:
>
> > Hello,
> >
> > I am running the following versions of software:
> >
> > Python 3.5
> > psycopg2==2.6.1
> > Postgres 9.4.5
> >
> > I have 2 tables.  Table User has UserId (serial PK), LastName, FirstName,
> > Gender, DateOfBirth, and DateEnrolled.  Table UserProfile has
> > UserProfileId
> > (serial, PK), UserId (FK), DateEntered, FaveNumber, and Activity.  There
> > is a one-to-many relationship.
> >
> > The following PostgreSQL works and ultimately creates a record in
> > UserProfile with an associated UserId (FK).
> >
> > \set last_name '''Sara'''
> > \set first_name '''Jackson'''
> > \set gender '''F'''
> > \set dob '''1941-1-12'''
> > \set fave_number '''3'''
> > \set activity '''volleyball'''
> >
> >
> > WITH ins_user AS (
> > INSERT INTO User
> > (LastName, FirstName, Gender, DateOfBirth, DateEnrolled)
> > VALUES (:last_name, :first_name, :gender, :dob, now())
> > RETURNING UserId)
> > INSERT INTO UserProfile
> > (UserId, DateEntered, FaveNumber, Activity)
> > VALUES ( (SELECT UserId FROM ins_user), now(), :fave_number :activity);
> >
> > How can I build a psycopg2 cur.execute query that will accomplish the
> > above
> > PostgreSQL?  I've read documentation but can't seem to get a handle on
> how
> > I should structure this command.
>
> I have not tried it, but wouldn't the straight-forward
>
> cur.execute("""
> WITH ins_user AS (
> INSERT INTO User
> (LastName, FirstName, Gender, DateOfBirth, DateEnrolled)
> VALUES (:last_name, :first_name, :gender, :dob, now())
> RETURNING UserId)
> INSERT INTO UserProfile
> (UserId, DateEntered, FaveNumber, Activity)
> VALUES ( (SELECT UserId FROM ins_user), now(), :fave_number :activity);
> """,
> dict(
> first_name="Sara",
> last_name="Jackson",
> gender="F",
> dob=datetime.date(1941, 1, 12),
> fave_number=3,
> activity="volleyball"
> ))
>
> work?
>

Hi Peter,

Yes, thank you.  It turns out that I can pass a dictionary as an argument.
I have combined your response with Dieter's and am running into some issues
now.  I need to figure out how to pass a dictionary AND the returned Id.

>
> > My starting point is:
> >
> > cur.execute( \
> > """INSERT INTO User \
> > (LastName, FirstName, Gender, DateOfBirth, DateEnrolled) \
> > VALUES (%s, %s, %s, %s, %s) RETURNING UserId;""", \
> > (last_name, first_name, gender, date_of_birth, now(), ??...??)
> >
> >
> > Also, I have a second question.  Is it possible to extract that value
> > derived from "RETURNING UserId" so that it can be used in a later query?
> >
> > Thank you for your time!
> > Aaron
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Psycopg2 to create a record using a FK

2016-03-11 Thread Aaron Christensen
Hello,

I am running the following versions of software:

Python 3.5
psycopg2==2.6.1
Postgres 9.4.5

I have 2 tables.  Table User has UserId (serial PK), LastName, FirstName,
Gender, DateOfBirth, and DateEnrolled.  Table UserProfile has UserProfileId
(serial, PK), UserId (FK), DateEntered, FaveNumber, and Activity.  There is
a one-to-many relationship.

The following PostgreSQL works and ultimately creates a record in
UserProfile with an associated UserId (FK).

\set last_name '''Sara'''
\set first_name '''Jackson'''
\set gender '''F'''
\set dob '''1941-1-12'''
\set fave_number '''3'''
\set activity '''volleyball'''


WITH ins_user AS (
INSERT INTO User
(LastName, FirstName, Gender, DateOfBirth, DateEnrolled)
VALUES (:last_name, :first_name, :gender, :dob, now())
RETURNING UserId)
INSERT INTO UserProfile
(UserId, DateEntered, FaveNumber, Activity)
VALUES ( (SELECT UserId FROM ins_user), now(), :fave_number :activity);

How can I build a psycopg2 cur.execute query that will accomplish the above
PostgreSQL?  I've read documentation but can't seem to get a handle on how
I should structure this command.

My starting point is:

cur.execute( \
"""INSERT INTO User \
(LastName, FirstName, Gender, DateOfBirth, DateEnrolled) \
VALUES (%s, %s, %s, %s, %s) RETURNING UserId;""", \
(last_name, first_name, gender, date_of_birth, now(), ??...??)


Also, I have a second question.  Is it possible to extract that value
derived from "RETURNING UserId" so that it can be used in a later query?

Thank you for your time!
Aaron
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Network Simulator

2016-02-24 Thread Aaron Christensen
On Feb 23, 2016 9:55 PM, "nikhil amraotkar" 
wrote:
>
> Hi...I need help to design a network simulator consisting for 5 routers
in python...Any help would be appretiated...
> Thanks..
> --
> https://mail.python.org/mailman/listinfo/python-list

What is the purpose for designing it in Python? I'm a network engineer and
use GNS3 and Packet Tracer.  I could see the benefit of creating Python
scripts to manage networking devices but not sure why you would want to use
Python.  I use Python to generate configuration scripts but haven't used it
for any management yet.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: good python tutorial

2016-02-23 Thread Aaron Christensen
Thanks for sharing!

On Tue, Feb 23, 2016 at 1:48 AM, Mike S via Python-list <
python-list@python.org> wrote:

> This site was recommended by a friend, it looks really well put together,
> I thought it might be of interest to people considering online tutorials.
>
> http://www.python-course.eu/index.php
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A newbie's doubt

2016-01-07 Thread Aaron Christensen
That's an awesome response!
On Jan 7, 2016 6:35 AM, "Chris Angelico"  wrote:

> On Thu, Jan 7, 2016 at 2:20 PM, Henrique Correa  wrote:
> > Is Python's Tutorial (by Guido) a good and complete reference for the
> > language? I mean, after reading it, should I have a good basis on Python?
> >
> > I've came from js and php, and already know the very basics of py.
> >
> > Thank you!
>
> If by "good and complete" you mean "enough to write code in", then
> yes, I would say it is.
>
> If you mean "enough to write applications that you can sell for
> money", then it's probably insufficient; you'll want to also learn a
> few libraries, possibly including third-party ones like Flask/Django
> (to write web applications) or numpy/pandas (to write computational
> code) or matplotlib (to crunch numbers and make graphs).
>
> If, on the other hand, you mean "enough to understand how Python works
> internally", then no, it's not. It's not meant to go into that kind of
> detail. But you don't need to know that anyway.
>
> I would recommend going through that tutorial. You'll get a decent
> handle on how Python works. As a general rule, Python's object model
> is similar to what you'll know from JS; the scoping rules are
> different (instead of "var x;" to declare that x is local, you would
> have "global x" to declare that x is global - but you need declare
> only those globals that you assign to, not those you reference). As
> you go through it, write down some notes of everything that interests
> or confuses you; once you've completed the tutorial, go through your
> notes again. Some of what you've written down will now make perfect
> sense, and you can delete it; some will still confuse you, but you'll
> understand more of *why* it confuses you. So then you come back here
> to python-list with the bits that confuse you, and we'll be happy to
> explain stuff!
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python and multiple user access via super cool fancy website

2015-12-25 Thread Aaron Christensen
On Dec 25, 2015 12:22 PM, "Jason Friedman"  wrote:
>
> >> I have a hunch that you do not want to write the program, nor do you
> >> want to see exactly how a programmer would write it?
> >>
> >> The question is more like asking a heart surgeon how she performs
> >> heart surgery:  you don't plan to do it yourself, but you want a
> >> general idea of how it is done?  How do you keep the patient from
> >> bleeding to death?  Does the heart stop while performing the surgery,
> >> and if yes, how does the patient stay alive?
>
> > What gives you that idea?
>
> You said:  I am not a programmer but I do have an incredible interest in
it.
>
> Many people say:  I am not a programmer but I want to become one.
>
> I just wanted to make sure your actual question was being answered.
> Sounds like it is.
>
> Also, the general practice is to put your response at the bottom of your
reply.

Understood.  I say I'm not a programmer because my degrees and day job are
not programing.  Thanks for making sure my question was answered!  My
question was answered but it also made me think of several other different
things.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python and multiple user access via super cool fancy website

2015-12-25 Thread Aaron Christensen
On Dec 25, 2015 12:38 PM, "Chris Warrick" <kwpol...@gmail.com> wrote:
>
> On 25 December 2015 at 13:15, Aaron Christensen
> <aaron.christen...@gmail.com> wrote:
> > LOL. Thanks!  PHP was definitely not very easy to pick up and I'm still
> > having some issues. Last night I watched some tutorials on Django and
plan
> > on reading all of the links on the docs page of Django.  I will also
look at
> > your recommendation.  I think that will give me a good understanding.
> > Hopefully Django isn't a copy/paste kinda "put your website together"
like
> > WordPress because my objective is to actually learn Python.
>
> That’s not what WordPress is. WordPress is a blog engine that can be
> used as a general-purpose CMS, full stop. You don’t need any coding
> skills to build a website with WordPress. Many people have done that —
> especially on wordpress.com or shared hosting services with one-click
> WP installers; and even without an installer, setting up WordPress on
> shared hosting requires a FTP client and reading comprehension
> anyways.
>
> On the other hand, Django is nothing like this. Django can do anything
> you tell it to, and you need to write code. While Django handles some
> things for you (eg. the admin panel or the ORM), you still need to
> write models, views, URL configuration, etc. yourself. You need an
> understanding of relational databases, HTTP, HTML/CSS, the template
> engine, and you do need to write actual code.
>
> And while there are tons of ready-made blog applications for Django
> that you can install and use, you can (and should!) write your own in
> an hour or two.  And it’s a lot more fun to do that than lazily
> downloading something.
>
> --
> Chris Warrick <https://chriswarrick.com/>
> PGP: 5EAAEA16
> --
> https://mail.python.org/mailman/listinfo/python-list

That's excellent news. I am looking forward to learning and working with
Django. I imagine that I will have Django related questions in a few weeks
or so.  I appreciate your lengthy responses and explanations!

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


Re: Python and multiple user access via super cool fancy website

2015-12-25 Thread Aaron Christensen
Hi Jason,

What gives you that idea?
On Dec 25, 2015 12:23 AM, "Jason Friedman"  wrote:

> > I am not sure if this is the correct venue for my question, but I'd like
> to
> > submit my question just in case.  I am not a programmer but I do have an
> > incredible interest in it, so please excuse my lack of understanding if
> my
> > question isn't very thorough.
> >
> > As an example, a website backend is developed using Python.  Users can
> > submit their input through the website and PHP (or some other language)
> > transfers the user input from the website fields to a database such as
> > MySQL.  There is a main script called main_script.py which extracts the
> > user data from MySQL, processes it, stores output in MySQL and sends
> output
> > to the user (via webpage and email).
> >
> > About main_script.py
> > # main_script.py extracts user input from MySQL, processes it, stores
> > output in MySQL and send output to user (via webpage and email).
> > # Inputs: User personal information such as age, dob, nationality,
> hobbies,
> > and 20 or 30 other fields
> > # Output: main_script.py is going to do something with it such as access
> > the database and some shelve files or other py scripts. I have no clue
> what
> > it's going to do, but my point is that the processing of the input to
> > output will take longer than simply a print('Hello, %r!' %user_name).
> >
> > My question:  I am curious to know how Python handles something like
> this.
> > Let's say that there are 10, 20, 50, or even 1000 users accessing the
> > website.  They all put in their 20 to 30 pieces of input and are waiting
> on
> > some fancy magic output.  How exactly does that work?  Can multiple users
> > access the same script?  Does the Python programmer need to code in a
> > manner that supports this?  Are requests to the script handled serially
> or
> > in parallel?
>
> I have a hunch that you do not want to write the program, nor do you
> want to see exactly how a programmer would write it?
>
> The question is more like asking a heart surgeon how she performs
> heart surgery:  you don't plan to do it yourself, but you want a
> general idea of how it is done?  How do you keep the patient from
> bleeding to death?  Does the heart stop while performing the surgery,
> and if yes, how does the patient stay alive?
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python and multiple user access via super cool fancy website

2015-12-25 Thread Aaron Christensen
LOL. Thanks!  PHP was definitely not very easy to pick up and I'm still
having some issues. Last night I watched some tutorials on Django and plan
on reading all of the links on the docs page of Django.  I will also look
at your recommendation.  I think that will give me a good understanding.
Hopefully Django isn't a copy/paste kinda "put your website together" like
WordPress because my objective is to actually learn Python.
On Dec 25, 2015 3:59 AM, "Chris Warrick" <kwpol...@gmail.com> wrote:

> [Forwarding your message to the mailing list — please use the Reply
> All (or Reply to List) button in the future]
>
> On 25 December 2015 at 05:02, Aaron Christensen
> <aaron.christen...@gmail.com> wrote:
> > Hi Chris,
> >
> > Thank you for your response and information.  I enjoy doing Python on my
> > free time so when I get closer to some kind of web application, then I
> can
> > provide more information.
> >
> > Thanks for pointing me in the right direction so far.  I will replace any
> > shelve usage with the database.  I also started looking at WSGI servers
> and
> > just found a great deal of information on fullstackpython.com.
>
> Full Stack Python is a good resource, which teaches many things
> considered best practices in the Python web world (I personally
> recommend uWSGI instead of Gunicorn, but that’s mainly just my
> preference)
>
> > I have some experience in PHP (which is why I mentioned it).  I am
> > unfamiliar with Django, Flask, or Pyramid.  I am looking into Django,
> but am
> > a little hesitant because of all the time I spent learning PHP.
>
> I’m sorry, but you wasted your time. PHP is an awful language with
> multiple problems and bad design decisions. Here’s some laughing
> stock:
>
> http://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/
> http://reddit.com/r/lolphp
> http://phpsadness.com/
>
> On the other hand, Python web frameworks are really fun and easy to
> learn, even though their general design is a bit different from PHP’s:
>
> https://docs.djangoproject.com/en/1.9/intro/tutorial01/
> http://tutorial.djangogirls.org/en/
>
> --
> Chris Warrick <https://chriswarrick.com/>
> PGP: 5EAAEA16
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python and multiple user access via super cool fancy website

2015-12-25 Thread Aaron Christensen
Great thank you!  I will look into it. I watched some tutorials on Django
last night. It appears to be somewhat of a bootstrap but for the backend.
I'm not sure if my opinion is correct.
On Dec 25, 2015 5:27 AM, <one...@onemanifest.net> wrote:

> > On 25 December 2015 at 05:02, Aaron Christensen
> > <aaron.christen...@gmail.com> wrote:
> >> Hi Chris,
> >>
> >> Thank you for your response and information.  I enjoy doing Python on my
> >> free time so when I get closer to some kind of web application, then I
> can
> >> provide more information.
> >>
> >> Thanks for pointing me in the right direction so far.  I will replace
> any
> >> shelve usage with the database.  I also started looking at WSGI servers
> and
> >> just found a great deal of information on fullstackpython.com.
> >
> > Full Stack Python is a good resource, which teaches many things
> > considered best practices in the Python web world (I personally
> > recommend uWSGI instead of Gunicorn, but that’s mainly just my
> > preference)
> >
> >> I have some experience in PHP (which is why I mentioned it).  I am
> >> unfamiliar with Django, Flask, or Pyramid.  I am looking into Django,
> but am
> >> a little hesitant because of all the time I spent learning PHP.
> >
> > I’m sorry, but you wasted your time. PHP is an awful language with
> > multiple problems and bad design decisions. Here’s some laughing
> > stock:
> >
> > http://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/
> > http://reddit.com/r/lolphp
> > http://phpsadness.com/
> >
> > On the other hand, Python web frameworks are really fun and easy to
> > learn, even though their general design is a bit different from PHP’s:
> >
> > https://docs.djangoproject.com/en/1.9/intro/tutorial01/
> > http://tutorial.djangogirls.org/en/
>
> If you want to get a good overview of what it means to use a python web
> framework, try Miguel Grinberg’s great flask tutorial [1]. It’s based on
> flask, a more lightweight web framework compared to django, but the basic
> principles are the same. He covers about anything you need to know in easy
> to follow lessons. Only basic python knowledge is required.
>
> [1]
> http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world
>
> my 2 cts,
>
> oneman
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Python and multiple user access via super cool fancy website

2015-12-24 Thread Aaron Christensen
Hi all,

I am not sure if this is the correct venue for my question, but I'd like to
submit my question just in case.  I am not a programmer but I do have an
incredible interest in it, so please excuse my lack of understanding if my
question isn't very thorough.

As an example, a website backend is developed using Python.  Users can
submit their input through the website and PHP (or some other language)
transfers the user input from the website fields to a database such as
MySQL.  There is a main script called main_script.py which extracts the
user data from MySQL, processes it, stores output in MySQL and sends output
to the user (via webpage and email).

About main_script.py
# main_script.py extracts user input from MySQL, processes it, stores
output in MySQL and send output to user (via webpage and email).
# Inputs: User personal information such as age, dob, nationality, hobbies,
and 20 or 30 other fields
# Output: main_script.py is going to do something with it such as access
the database and some shelve files or other py scripts. I have no clue what
it's going to do, but my point is that the processing of the input to
output will take longer than simply a print('Hello, %r!' %user_name).

My question:  I am curious to know how Python handles something like this.
Let's say that there are 10, 20, 50, or even 1000 users accessing the
website.  They all put in their 20 to 30 pieces of input and are waiting on
some fancy magic output.  How exactly does that work?  Can multiple users
access the same script?  Does the Python programmer need to code in a
manner that supports this?  Are requests to the script handled serially or
in parallel?

I've tried some searches, but not getting much except for "appending to the
same file", etc.

I hope my question is a good question.  Thank you for your time!
Aaron
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to use python 3.5

2015-12-23 Thread Aaron Christensen
Wow, you can find cyber bullies just about anywhere...

On Wed, Dec 23, 2015 at 8:00 AM, Chris Warrick  wrote:

> On 23 December 2015 at 07:38, Ankit Deshmukh  wrote:
> > Hi there,
> >
> >
> >
> > I am maters student in India,
>
> We don’t care (expect that you made a typo there).
>
> > I have installed python 3.5 in my windows 10
> > 64bit machine. Everything works fine except package installing. When in
> use
> > “pip install numpy” is shows unable to find *‘vcvarsall.bat’* I don’t
> know
> > how to fix it. I tried several things nothing works.
>
> You clearly haven’t tried enough, as this question is answered by a
> simple Google search. You need to:
>
> (a) install Visual Studio 2015 and configure it; or
> (b) find a binary package, eg. here:
> http://www.lfd.uci.edu/~gohlke/pythonlibs/
>
> A student who wants to work in programming should be able to find
> answers to their questions online. And know better than putting a
> phone number in their e-mail signature for the whole world to see.
>
> --
> Chris Warrick 
> PGP: 5EAAEA16
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


In Python 3, how to append a nested dictionary to a shelve file with the added difficulty of using a for loop?

2015-12-21 Thread Aaron Christensen
Hello,

I am trying to figure out how to populate a shelve file with a nested
dictionary.

These are my requirements:

-Create shelve file called people.db
-Append the shelve file with new people (person_1, person_2, etc.).
-Use a for loop to iterate through 'attributes' so that I do not need to
write out the lengthy code line by line to populate to the shelve file.
-Need to reference shelve file data for future use

Here is the key/value format that I would like to append to the shelve
file.

person_1 = { 'name': 'Bob', 'type': 'employee', 'attributes':
[{'game': 'basketball', 'high score': '100', 'time': '3.34'},
{'game': 'bridge', 'high score': '10', 'time': '30.34'},
{'game': 'foosball', 'high score': '2', 'time': '24'}]
'''
50+ other attributes
'''
}

# Example: s['person_1]['attributes'][2]['time'] would call out '24'.
# 's' is from 's = shelve.open('people')'
I have a dictionary dictPeople.py file (created using pprint() that
contains the information of person_1, etc. And I am extracting only a small
percentage of the data that is needed.

I have tried the following, but I get an invalid key error.

import shelve, dictPeople
s = shelve.open('people')
person = 'person_1'
s[person]['name'] = dictPeople.person_1['name']
s[person]['type'] = dictPeople.person_1['type']
# I need to use this for loop because there are 50+ attributes.
for attribute in range(0, len(dictPeople['attributes'][attribute])):
s[person]['attributes'][attribute]['game'] = \
dictPeople['attributes'][attribute]['game']
s[person]['attributes'][attribute]['high score'] = \
dictPeople['attributes'][attribute]['high score']
s[person]['attributes'][attribute]['time'] = \
dictPeople['attributes'][attribute]['time']
It turns out, I get the key error because I am not allowed to reference a
key/value pair the same way that I can with a dictionary. However, the
crazy thing is that I can call values in the db file using the same exact
format when trying to write.

For example: I can read data from the .db file using:

x = s['person_1']['name']
print(x)
BUT! I cannot write to that .db file using that exact format or I get an
invalid key error. Makes no sense!

s['person_1']['name'] = 'Bob'
# Returns invalid key entry.  Makes no sense.
Therefore, I tried to extract data and populate the db file using the
following:

s[person] = {   'name': dictPeople.person_1['name'],
'type': dictPeople.person_1['type'],
for attribute in range(0, len(dictPeople['attributes'][attribute])):
['game':  dictPeople['attributes'][attribute]['game'],
'high score': dictPeople['attributes'][attribute]['high score'],
'time': dictPeople['attributes'][attribute]['time']]

}
But, this obvously doesn't work because of the for loop. How can I do this?

-I am trying to figure out how to extract data from the dictionary
dictPeople.py file and store it in the people.db file.
-I am trying to add new people to the people.db file as more people become
available.
-I need to use the for loop because of the 50+ attributes I need to add.
-My future steps would be to modify some of the data values that I extract
and used to populate the people.db file, but my first step is to, at least,
extract, and then populate the people.db file.

Any help or guidance is greatly appreciated.  Thank you for your time and
reading my question.

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


Re: In Python 3, how to append a nested dictionary to a shelve file with the added difficulty of using a for loop?

2015-12-21 Thread Aaron Christensen
Hi Peter,

Thanks for the response!  Several things you stated definitely got me
thinking.  I really appreciate the response.  I used what you said and I am
able to accomplish what I needed.

Thanks!
Aaron



On Mon, Dec 21, 2015 at 7:23 PM, Peter Otten <__pete...@web.de> wrote:

> Aaron Christensen wrote:
>
> > Hello,
> >
> > I am trying to figure out how to populate a shelve file with a nested
> > dictionary.
> >
> > These are my requirements:
> >
> > -Create shelve file called people.db
> > -Append the shelve file with new people (person_1, person_2, etc.).
> > -Use a for loop to iterate through 'attributes' so that I do not need to
> > write out the lengthy code line by line to populate to the shelve file.
> > -Need to reference shelve file data for future use
> >
> > Here is the key/value format that I would like to append to the shelve
> > file.
> >
> > person_1 = { 'name': 'Bob', 'type': 'employee', 'attributes':
> > [{'game': 'basketball', 'high score': '100', 'time': '3.34'},
> > {'game': 'bridge', 'high score': '10', 'time': '30.34'},
> > {'game': 'foosball', 'high score': '2', 'time': '24'}]
> > '''
> > 50+ other attributes
> > '''
> > }
> >
> > # Example: s['person_1]['attributes'][2]['time'] would call out '24'.
> > # 's' is from 's = shelve.open('people')'
> > I have a dictionary dictPeople.py file (created using pprint() that
> > contains the information of person_1, etc. And I am extracting only a
> > small percentage of the data that is needed.
> >
> > I have tried the following, but I get an invalid key error.
> >
> > import shelve, dictPeople
> > s = shelve.open('people')
> > person = 'person_1'
> > s[person]['name'] = dictPeople.person_1['name']
> > s[person]['type'] = dictPeople.person_1['type']
> > # I need to use this for loop because there are 50+ attributes.
> > for attribute in range(0, len(dictPeople['attributes'][attribute])):
> > s[person]['attributes'][attribute]['game'] = \
> > dictPeople['attributes'][attribute]['game']
> > s[person]['attributes'][attribute]['high score'] = \
> > dictPeople['attributes'][attribute]['high score']
> > s[person]['attributes'][attribute]['time'] = \
> > dictPeople['attributes'][attribute]['time']
> > It turns out, I get the key error because I am not allowed to reference a
> > key/value pair the same way that I can with a dictionary. However, the
> > crazy thing is that I can call values in the db file using the same exact
> > format when trying to write.
> >
> > For example: I can read data from the .db file using:
> >
> > x = s['person_1']['name']
> > print(x)
> > BUT! I cannot write to that .db file using that exact format or I get an
> > invalid key error. Makes no sense!
> >
> > s['person_1']['name'] = 'Bob'
> > # Returns invalid key entry.  Makes no sense.
> > Therefore, I tried to extract data and populate the db file using the
> > following:
> >
> > s[person] = {   'name': dictPeople.person_1['name'],
> > 'type': dictPeople.person_1['type'],
> > for attribute in range(0, len(dictPeople['attributes'][attribute])):
> > ['game':  dictPeople['attributes'][attribute]['game'],
> > 'high score': dictPeople['attributes'][attribute]['high score'],
> > 'time': dictPeople['attributes'][attribute]['time']]
> >
> > }
> > But, this obvously doesn't work because of the for loop. How can I do
> > this?
> >
> > -I am trying to figure out how to extract data from the dictionary
> > dictPeople.py file and store it in the people.db file.
> > -I am trying to add new people to the people.db file as more people
> become
> > available.
> > -I need to use the for loop because of the 50+ attributes I need to add.
> > -My future steps would be to modify some of the data values that I
> extract
> > and used to populate the people.db file, but my first step is to, at
> > least, extract, and then populate the people.db file.
> >
> > Any help or guidance is greatly appreciated.  Thank you for your time and
> > reading my question.
>
> You don't need these loops. The problem is that when you read the dict from
> the db
>
> db = shelve.open(...)
> person = db["person_1"]
>
> person is a Python object completely independent of the shelve and the
> shelve has no way to trace changes to that object:
>
> $ python3
> Python 3.4.3 (default, Oct 14 2015, 20:28:29)
> [GCC 4.8.4] on linux
> Type "help