Re: [Tutor] Questions

2019-04-08 Thread George Fischhof
Diana Katz  ezt írta (időpont: 2019. ápr. 7., V,
10:01):

> 1) Can you use python from excel? Or just export to excel?
> 2) I am trying to see if there's a way using python to automate all of this
> work that I need to do. I have to collect quarterly segment data for
> hundreds of public companies and go back at least 12-16 quarters. We use an
> aggregator like factset and they actually don't have this option available
> in an automated way. So I'm trying to see if there's a way to build this.
> Basically, I get my data from sec.gov and they have interactive data -
> they
> even have the data in excel (though it's a messy file and hard to read). I
> attached some of the steps and the data that i'd want to see.
> Basically i'd want the excel to look like:
> old to new quarters - going back 12 to 16 quarters (more if possible but
> not if it will stop the project).
>  Columns: 3/31/2017, 6/30/2017, 9/30/17, 12/31/17, 3/313/2018...
> Rows:
> Sales for segment A
> Sales for Segment b
> Sales for SEgment C
> …(for as many segments as they have)
>
> Earnings for Segment A
> .Earnings for Segment B
>
> Depreciation for Segment A
> Depreciation for Segment B
> Depreciation for Segment C...
>
> I included where I get the data in the attached document.
>
> All the best,
>
> Diana Katz
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor



Hi Diana,

you can write excel addins in Python with this program:
https://www.pyxll.com/index.html

and you can use excel from Python too.
The two ways:

- If you do not need the excel process itself (it means that you do not
want to recalculate for example, or do any calculation, then perhaps
openpyxl would be a great choice for you:
https://pypi.org/project/openpyxl/
there are some templates and other stuff as well:
https://pypi.org/search/?q=openpyxl

- the other way is, when you want to  do calculations, then xlwings is your
package:
https://pypi.org/project/xlwings/
it uses win32com API, there are some edge cases where it does not allow you
to access low level com API functions. I faced with this, and created an
excel helper over win32com API instead of using xlwings, but I do not think
you will need that. (If yes, then code of xlwings can help you


BR,
__george__
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to get Selenium to wait for page load

2019-02-01 Thread George Fischhof
 ezt írta (időpont: 2019. jan. 31., Cs 12:07):

> Hi all,
>
>
>
> I have found an excellent article on identifying stale elements. The issue
> is when I try and use their example code. I get a failure where for_wait is
> not defined.
>
>
> http://www.obeythetestinggoat.com/how-to-get-selenium-to-wait-for-page-load-
> after-a-click.html
> 
>
>
>
> Traceback (most recent call last):
> File "", line 5, in 
> NameError: name 'wait_for' is not defined
> >>>
>
>
>
> When I look through the examples. I only find one reference for the above
> function. But it doesn't look correct and I am confused. The author
> indicates the definition of the function is half way up the page. As I
> cannot see, this reference doesn't help. So can someone help and provide
> the
> definition for this method/function?
>
>
>
> The code which generated the error:
>
>
>
> rows = []
>
> pageNav = browser.find_element_by_id("center-5")
>
> curr_page = pageNav.find_element_by_css_selector('span
> .pageNumberElement').text
>
> prev_page = ""
>
> while prev_page in curr_page:
>
> #wait_for(link_has_gone_stale):
>
> prev_page = curr_page
>
> rows.extend(tableNavigation (pageNav))
>
> if wait_for(link_has_gone_stale):
>
> pageNav = browser.find_element_by_id("center-5")
>
> curr_page = pageNav.find_element_by_css_selector('span
> .pageNumberElement').text
>
> if prev_page == curr_page:
>
> print ("Page no has not changed:",curr_page)
>
> else:
>
> prev_page = curr_page
>
>
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor



Hi,

Try splinter package.
That is an abstraction layer over selenium, and exactly does similar things.

__george__

>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] XML Programs

2018-04-16 Thread George Fischhof
Hi,

Maybe you should give a try to xmltodict package

George

leam hall  ezt írta (időpont: 2018. ápr. 16., H 15:14):

> Yeah, understood.
>
> Okay, knowing that others are smarter about python, and ElementTree,
> here's some code I was using to parse XML. Took a while to recover
> from.  :)
>
> Leam
>
> #
>
> import xml.etree.ElementTree as ET
> import os
> import argparse
> import fnmatch
>
> def show_info(file, element):
>   action  = ""
>   net_proto   = ""
>   trans_proto = ""
>   r_port  = ""
>   l_port  = ""
>   direction   = ""
>   name= ""
>   has_info= False
>   f_name  = ""
>
>   id= element.attrib['name']
>   f_name= os.path.splitext(file)[0]
>
>   for setting in element.iter('Setting'):
> if setting.attrib['name']  == 'Action':
>   action= setting.attrib['value']
>   has_info  = True
> elif setting.attrib['name'] == '+NetworkProtocol#0':
>   net_proto = setting.attrib['value']
>   has_info  = True
> elif setting.attrib['name'] == '+TransportProtocol#0':
>   trans_proto = setting.attrib['value']
>   has_info= True
> elif setting.attrib['name'] == '+RemotePort#0':
>   r_port= setting.attrib['value']
>   has_info  = True
> elif setting.attrib['name'] == '+LocalPort#0':
>   l_port= setting.attrib['value']
>   has_info  = True
> elif setting.attrib['name'] == 'Direction':
>   direction = setting.attrib['value']
>   has_info  = True
> elif setting.attrib['name'] == 'Name':
>   name  = setting.attrib['value']
>   has_info  = True
>
>   if has_info:
> outfile.write("%s ; %s ; %s ; %s ; %s ; %s ; %s ; %s ; %s\n" %
> (f_name, id, name, action, net_proto, trans_proto, l_port, r_port,
> direction))
>
>
>
> ## Main
> parser = argparse.ArgumentParser()
> parser.add_argument("-o", "--outfile", default = "new_out.csv",
> help="File to write to.")
> parser.add_argument("-d", "--dir", default = ".", help="Directory of
> the XML files.")
> args = parser.parse_args()
>
> indir   = args.dir
> outfile = open(args.outfile, 'w')
> outfile.write("File ;Rule ID ;Name ;Action ; Network Protocol;
> Transport Protocol; Local Port; Remote Port; Direction\n")
>
> for file in os.listdir(indir):
>   if fnmatch.fnmatch(file, '*.xml'):
> full_file = indir + "\\" + file
> tree   = ET.parse(full_file)
> root   = tree.getroot()
> for element in root.iter('PolicySettings'):
>   show_info(file, element)
>
> outfile.close()
>
> 
>
> On Mon, Apr 16, 2018 at 9:07 AM, Glen  wrote:
> > I understand, I'd love to use something else but the save game files are
> in
> > XML so I have no choice :'(
> >
> > On 16 April 2018 at 13:54, leam hall  wrote:
> >>
> >> On Mon, Apr 16, 2018 at 7:10 AM, Glen  wrote:
> >> > Hey guys,
> >> >
> >> > I'm writing a save-game editor for a game I play (just a project to
> >> > learn).
> >> > But I am struggling on how to structure the code, how to store the xml
> >> > data
> >> > in data structure etc,
> >> >
> >> > Can anyone recommend some source I can review that reads and writes
> data
> >> > from an xml file.
> >>
> >> A friend's comment was "life is too short for XML". I like that. Have
> >> you considered JSON? Taking it a step further, MongoDB (JSON) or
> >> SQLite (SQL)? Both are pretty common and standard.
> >>
> >> While Python has its own stuff, like Pickle, that means you can only
> >> use Python. Using something like JSON or SQL means others can use the
> >> data and you get a chace to develop in a shared environment.  :)
> >> ___
> >> Tutor maillist  -  Tutor@python.org
> >> To unsubscribe or change subscription options:
> >> https://mail.python.org/mailman/listinfo/tutor
> >
> >
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pythonic

2018-03-30 Thread George Fischhof
2018-03-30 4:48 GMT+02:00 Pat Martin :

> Hello all,
>
> I have written the following program. It generates a template for Pelican
> web site static generator. It works just fine, it generates the template
> and then I put the info in it to customize. But I was wondering, is this
> the "right" way to do it in python?
>
> #!/usr/bin/env python3
> """Generate a Pelican markdown base page."""
>
> import argparse
> import datetime
>
>
> def Main():
> """Run if run as a program."""
> parser = argparse.ArgumentParser()
> parser.add_argument("-T", "--title", type=str, required=True,
> help='Title for site, also generates the slug',
> metavar="")
> parser.add_argument("-c", "--category", required=True,
> help='Category or categories of post', metavar="")
> parser.add_argument("-t", "--tags", type=str, required=True,
> help="Tags for post", metavar="")
> parser.add_argument("-a", "--author", type=str, default="Pat Martin",
> help="Author of post", metavar="")
> args = parser.parse_args()
>
> now = datetime.datetime.now()
> slug = args.title.replace(" ", "-").lower()
>
> with open("{}.md".format(slug), 'w') as f:
> f.write("Title: {}\n".format(args.title))
> f.write("Date: {}-{}-{} {}:{}\n".format(now.year,
> now.month,
> now.day,
> now.hour,
> now.minute))
> f.write("Modified: {}-{}-{} {}:{}\n".format(now.year,
> now.month,
> now.day,
> now.hour,
> now.minute))
> f.write("Category: {}\n".format(args.category))
> f.write("Slug: {}\n".format(slug))
> f.write("Authors: {}\n".format(args.author))
> f.write("Summary: \n")
>
>
> if __name__ == "__main__":
> Main()
>
>
>
> Thanks for any input.
>
> WP
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



Hi Pat,

my thoughts:


1.)
def Main():

function names are written with small letter with underscore between the
words
check PEP-8
https://www.python.org/dev/peps/pep-0008/
http://docs.python-guide.org/en/latest/writing/style/

It is better to name the functions according to what they do, in this case
for example: create_template() or something like that


2.)
argparse

it is good, but you can write more Pythonic code using click
https://pypi.python.org/pypi/click/
it is also Pythonic to use / know the Python ecosystem (the packages)


3.)
with open("{}.md".format(slug), 'w') as f:
   f.write("Date: {}-{}-{} {}:{}\n".format(now.year,
now.month,

Python is mainly about readability
https://www.python.org/dev/peps/pep-0020/

you can use more meaningful variable names: template_file instead of f
if you have Python 3.6, you can use the newest formatting method, which is
more readable:
template_file.write(f"Date: {now.moth}-{now.day}") etc

https://www.python.org/dev/peps/pep-0498/

the more readable open:
slug_file_name = f"{slug}.md"
with open(slug_file_name, "w") as slug_file:

and if you use Python 3, the open should contain encoding:
with open(slug_file_name, "w", encoding="UTF-8") as slug_file:


BR,
George
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to schedule the SFTP folder sync using python

2017-11-02 Thread George Fischhof
Hi Pareshkumar,

I do not know what pysftp lib can do for you, but maybe you will need the
scheduler too:

https://pypi.python.org/pypi/schedule/


BR,
George

2017-10-31 20:30 GMT+01:00 Pareshkumar Panchal :

> Hi,
>
> can you help me about scheduling the folder sync between sftp and local
> directory?
>
> pysftp library is good or you recommend different library?
>
> thank you
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need Help with install of Python!

2017-09-22 Thread George Fischhof
2017-09-20 2:18 GMT+02:00 Alan Gauld via Tutor :

> On 19/09/17 21:13, Larry Staley wrote:
> > Hello I am very new to Python just having installed Python Version 2.7
> onto
> > my windows 8.1 laptop.  I thought the install was successful and was
> > entering information for my first assignment when I received an
> unexpected
> > error.
>
> Where did you get your vesion of Python?
> If it was the standard distribution from python.org or
> activestate.com then it does not include any of the SciPy
> packages(*) and you need to install them separately.
>
> If you expect to be using mamny of these types of package
> you are best fetching a distribution  that includes them
> all, for example, Anaconda or Enthought
>
> (*)Pandas is part of the SciPy suite of third party add-ons.
>
> > I executed a Sheets command using an earlier generated getSheetNames
> > function that successfully was entered by me.
>
> When you define a function the code inside is not
> executed merely compiled into a function object
> ready for execution.
>
> > However, when I ran the Sheets command I received the following:
>
> Its only when you call the function that the code inside
> gets executed.
>
> > def getSheetNames(excelfile):
> > from pandas import ExcelFile
>
> Its normal in Python to put all imports at the top of
> the file rather than inside any functions. In this
> case you try to import pandas everytime you call
> the function and while its not a big overhead it
> mounts up if you were calling this inside a
> repeating loop.
>
> And if the import was outside the function you would
> pick up the import error earlier.
>
>  excelfile=r:"C:\Users\Larry
>  sheets=getSheetNames
> > (excelfile);sheets
>
> I'm not sure what you are doing with that
> final ;sheets. I assuyme trying to evaluate the result of the function?
>
> It would be normal to just print it:
>
> >>> print getSheetNames(excelFile)
>
> or, if you need to store the result:
>
> >>> sheets=getSheetNames(excelfile)
> >>> sheets
>
> Combining commands on a single line doesn't save
> much typing and makes debugging harder.
>
> > I have in addition included the actual Python I executed and received the
> > message.  It is attached in the file.
>
> attachments often get rejected by the mailer,
> if its not a huge file(>100 lines) just paste
> it into the email.
>
> Always include the full error trace too.
>
> > If I need to install Pandas, please indicate clearly how I do using my
> > current ver 2.7 python install.
>
> The easiest way is just to grab one of the
> all-inclusive Python distros mentioned above.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>




Hi Larry,

If You just installed Python 2.7, maybe it would be a good idea to replace
it with Python 3.6. It will not solve Your problem, but support of Pyhon 2
will be finished in 2020, and that time You will have to learn Python 3
anyway. So it is better to start with it if You have no any special
requirement to use Python 2.
(Python 3 is more modern, and is the future)
;-)


@tutors
Hi Tutors,

I think we should encourage people new to Python to use Python 3 instaed of
Python 2 as this is the future. ;-)


BR,
George
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New to Python

2017-09-08 Thread George Fischhof
2017-09-07 20:39 GMT+02:00 boB Stepp :

> Welcome to Tutor!
>
> On Thu, Sep 7, 2017 at 8:14 AM, Vikram Singh
>  wrote:
> > I've been learning Python from Google For Education
> > . A little help will be
> > appreciated regarding the right way and right tutorials to learn Python
> > from. Thanks in advance.
>
> This is a very common question on this list as you might imagine.  If
> you go to the searchable Tutor list archives at
>
> https://www.mail-archive.com/tutor@python.org/
>
> and search for "learn python", you will get 8048 hits!  You might want
> to do that, look over the results and perhaps perform other searches
> for topics that more closely match your interest.
>
> One thing I notice about the Google course you link to is that it is
> Python 2-based.  The latest version of Python is now in version 3.6,
> and generally speaking, if you are just starting out with Python, you
> probably should be focusing your efforts on Python 3.
>
> As a fellow learner, I can recommend some things *not* to do:
>
> 1)  Keep buying bunches of interesting books on Python and not
> studying any of them thoroughly!  Instead, find a resource -- printed
> on paper or online -- that speaks to you and work through it
> thoroughly.
>
> 2)  Starting new project after new project and finishing very few of
> them!  Instead, pick something interesting and start working on it,
> planning on augmenting it as your knowledge grows in parallel with
> your more formal studying.
>
> 3)  Working earnestly for a while, then taking long breaks off!  If
> you are like me, you will tend to forget many things you have studied
> previously, even forgetting you have asked about these things
> previously on Tutor!!  Instead, try to work on at least a little bit
> of Python studying each and every day, longer when life allows.
>
> 4)  I have more I could share, but I think you take my points!
>
> If you have never done any programming, you may need to find a very
> gentle resource to start out with that explains not only Python, but
> general programming/computer science concepts in a lot of detail.
> OTOH, if you already have experience with programming, then you
> probably can greatly accelerate your learning progress, perhaps even
> getting by with studying the official Python tutorial at
>
> https://docs.python.org/3/tutorial/index.html
>
> Bear in mind that Python has its own culture and ways of doing things
> that can be a bit different from other languages you may have
> studied/worked in.  You might enjoy the "Zen of Python" by Tim Peters.
> You can access it in the Python interpreter by typing
>
> >>> import this
>
> I have been rambling a bit.  I just noticed that the searchable Tutor
> archive is back up and searched for all of my previous posts.  Five
> years and I have not come very far.  Do as I say and not as I do!!!
> ~(:>))
>
> And always ask questions here when you get stuck.  Try not to top
> post.  Give your OS and Python version and all other relevant
> information to allow the experts to diagnose your problem(s).  Always
> COPY AND PASTE both your relevant code and FULL ERROR TRACEBACK into a
> plain text email to Tutor.  Try to limit your code to just the part
> that is causing you to pull your hair out (If you still have any!
> ~(:>)) ).
>
> And come back with more specific goals for your self-study along with
> any relevant background.  Perhaps someone might be able to offer
> advice that is more tailored to your needs and goals.
>
> And again, welcome!  This is a very friendly and helpful place to learn!!
>
> Cheers!
>
>
> --
> boB
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



Hi Tutors,

As this is a really frequent question, maybe it would be good to put a
short list (the answers cumulated no more than about 10 websites) into the
welcome message of the Tutor mailing list.

BR,
George
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need advice on testing python code.

2017-08-28 Thread George Fischhof
2017-08-28 9:43 GMT+02:00 Anubhav Yadav :

> Hi George,
>
> > And pytest has more than 200 plugins to make it easier to test things.
> As I remember it has mongo plugin as we well
> >
>
> Thank you for your comments.
>
> I have been using `py.test` for only two reasons.
>
> 1. To run my tests places in the `/tests` directory.
> 2. To run them whenever I save any file int he project using `py.test -f`
> (after installing pytest-xdist plugin).
>
> I will have a look at py.test again and look at examples. This is a great
> start for me.
>
> I usually work with writing APIs using Flask, which I test using
> `fixtures` and `mock`. I also write a lot of code which interacts with a
> lot of external modules like
> `rabbitmq`, `databases` etc. I want to be better at write maybe
> integration tests and functional tests.
>
> If you have any more advice regarding those please let me know. Any
> recommended reading would help immensely.
>
> - Anubhav.
>
>


Here is the compatibility list of plugins:
http://plugincompat.herokuapp.com/

here is the rabbitmq plugin:
https://pypi.python.org/pypi/pytest-rabbitmq

and here is one for databases:
https://pypi.python.org/pypi/pytest-sqlalchemy/0.1

docker
https://pypi.python.org/pypi/pytest-docker/0.6.0


And if you do not have a CI system yet, then the buildbot CI can be good
for you
https://buildbot.net/
which is written in Python (and of course you manage it in Python)
(used by Python, Mozilla, Chrome etc)


George
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need advice on testing python code.

2017-08-28 Thread George Fischhof
2017. aug. 28. de. 2:15 ezt írta ("Anubhav Yadav" ):

Hello.

I am a python developer and I write a lot of python code everyday. I try to
do as much unit testing as possible. But I want to be better at it, I want
to write more test cases, specially that rely on database insertions and
reads and file io. Here are my use-cases for testing.
How to test if things are going into the database properly or not?
(mysql/mongo). I want to be able to create a test database environment as
simple as possible. Create and delete the test environment before each
functional test case is run.
Sometimes I write code that read some data from some rabbitmq queue and do
certain things. How can I write end to end functional test that creates a
test rabbitmq environment (exchanges and queues) -> wait for sometime ->
see if the intended work has been done -> delete the test environment.
I want to be able to make sure that any new commit on my self hosted gitlab
server should first run all functional test cases first before accepting
the merge.
Since we use lot of docker here to deploy modules to productions, I want to
write functional test cases that test the whole system as a whole and see
if things are happening the way they are supposed to happen or not. This
means firing up lot of docker containers, lot of test databases with some
data, and run all the test cases from an end user point of view.
Can you suggest me the right python testing frameworks that I should be
using? Right now I am using unittest to write test cases and manual if/else
statements to run the functional test cases.
I try to create rabbitmq queues and bind them to rabbitmq exchanges using
the pika module. I then run the module using python -m moduleName and then
sleep for sometime. Then I kill the processs (subprocess) and then I see if
the intended consequences have happened or not. It's a pain in the ass to
be doing so many things for test cases. I clearly need to learn how to do
things better.
Any suggestion/book/article/course/video will help me immensely in becoming
a developer who writes better code with lot of test cases.

Thanks for reading.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



And pytest has more than 200 plugins to make it easier to test things. As I
remember it has mongo plugin as we well

George
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need advice on testing python code.

2017-08-28 Thread George Fischhof
2017. aug. 28. 2:15 ezt írta ("Anubhav Yadav" ):

Hello.

I am a python developer and I write a lot of python code everyday. I try to
do as much unit testing as possible. But I want to be better at it, I want
to write more test cases, specially that rely on database insertions and
reads and file io. Here are my use-cases for testing.
How to test if things are going into the database properly or not?
(mysql/mongo). I want to be able to create a test database environment as
simple as possible. Create and delete the test environment before each
functional test case is run.
Sometimes I write code that read some data from some rabbitmq queue and do
certain things. How can I write end to end functional test that creates a
test rabbitmq environment (exchanges and queues) -> wait for sometime ->
see if the intended work has been done -> delete the test environment.
I want to be able to make sure that any new commit on my self hosted gitlab
server should first run all functional test cases first before accepting
the merge.
Since we use lot of docker here to deploy modules to productions, I want to
write functional test cases that test the whole system as a whole and see
if things are happening the way they are supposed to happen or not. This
means firing up lot of docker containers, lot of test databases with some
data, and run all the test cases from an end user point of view.
Can you suggest me the right python testing frameworks that I should be
using? Right now I am using unittest to write test cases and manual if/else
statements to run the functional test cases.
I try to create rabbitmq queues and bind them to rabbitmq exchanges using
the pika module. I then run the module using python -m moduleName and then
sleep for sometime. Then I kill the processs (subprocess) and then I see if
the intended consequences have happened or not. It's a pain in the ass to
be doing so many things for test cases. I clearly need to learn how to do
things better.
Any suggestion/book/article/course/video will help me immensely in becoming
a developer who writes better code with lot of test cases.

Thanks for reading.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



Hi Anubhav,

I think, pytest will be good for you
https://docs.pytest.org/en/latest/contents.html

BR
George
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python isn't working with Apache (Windows)

2017-07-31 Thread George Fischhof
2017-07-31 22:37 GMT+02:00 Christopher McGrath :

> Someone told me the problem is within the second line of the code.
>
>
> print ("Content-type: text/html")
> print (" ")
> print ("")
> print ("")
> print ("")
> print ("Hello Python.")
> print ("")
>
>
> There should be no space. I copied and pasted that code from somewhere and
> somehow that space has some hidden char that python didn't like...
>
>
> The one "who" does not like that space is not the Python, but the CGI
standard.
https://en.wikipedia.org/wiki/Common_Gateway_Interface

citation:

print "Content-type: text/plain\n\n";

end citation


there is blank line after content-type.


But when you use a framework, you do not have to care with cgi ;-)


BR

George


>
> *Christopher McGrath*
>
>
>
> *www.aawisdom.com <http://www.aawisdom.com> (716) 240-7786*
>
>
>
> --
> *From:* georgefisch...@gmail.com  on behalf of
> George Fischhof 
> *Sent:* Monday, July 31, 2017 8:34 PM
> *To:* Christopher McGrath
> *Cc:* tutor@python.org
> *Subject:* Re: [Tutor] Python isn't working with Apache (Windows)
>
>
>
> 2017-07-31 7:31 GMT+02:00 Christopher McGrath :
>
>> I am trying to run a simple python web script in a browser with apache. I
>> have apache installed and running perfectly. I installed Ruby and Perl
>> using instructions from here and worked perfect.
>> http://editrocket.com/articles/python_apache_windows.html
>>
>> I did have to change my “shebang lines” for PERL and RUBY like these:
>> #!Q:\LifeForce\perl\perl\bin\perl.exe
>> #!Q:\LifeForce\Ruby24-x64\bin\ruby.exe
>> As you can see, I didn’t install them on C: drive. They worked.
>>
>> I had Python 3.6 installed before and tried to test with these
>> #!Q:\LifeForce\Python36-32\Scripts\pip3.exe
>> #!Q:\LifeForce\Python36-32\Scripts\pip.exe
>> #!Q:\LifeForce\Python36-32\Scripts\pip2.6.exe
>> All the pip files in the Script directory.
>> I also tried with #!Q:\LifeForce\Python36-32\python.exe. This one works
>> worked from Window Command, but didn’t work from web browser like PERL and
>> RUBY.
>> I tried downgrading to Python 2.7 and installed directly at C: drive and
>> tested with
>> #!C:\Python27\python.exe
>> #!C:\Python27\Scripts\pip2.7.exe
>> #!C:\Python27\Scripts\pip2.exe
>> #!C:\Python27\Scripts\pip.exe
>> Nothing worked. I don’t have any idea anymore. Please help!
>> This is the simple code:
>> print ("Content-type: text/html")
>> print (" ")
>> print ("")
>> print ("")
>> print ("")
>> print ("Hello Python.")
>> print ("")
>>
>> I am trying to run directly from Apache htdoc dir. Not from cgi dir. I
>> think something is wrong with the shebang line.
>> This is the error output in the web browser:
>> Internal Server Error
>> The server encountered an internal error or misconfiguration and was
>> unable to complete your request.
>> Please contact the server administrator at postmaster@localhost to
>> inform them of the time this error occurred, and the actions you performed
>> just before this error.
>> More information about this error may be available in the server error
>> log.
>> Additionally, a 500 Internal Server Error error was encountered while
>> trying to use an ErrorDocument to handle the request.
>> This is what is shown in Apache’s error log:
>> [Mon Jul 31 01:06:54.266478 2017] [cgi:error] [pid 5156:tid 1688] [client
>> 98.5.128.152:51723] malformed header from script 'test.py': Bad header:
>> [Mon Jul 31 01:06:54.270479 2017] [authz_core:error] [pid 5156:tid 1688]
>> [client 98.5.128.152:51723] AH01630: client denied by server
>> configuration: C:/Apache24
>>
>>
>>
>>
>>
>> Christopher McGrath
>>
>> [http://aawisdom.com/Top_of_main_files/BizCard-Front-hotmailSignature.jpg
>> ]
>> [http://aawisdom.com/Top_of_main_files/image001.gif]
>> www.aawisdom.com<http://www.aawisdom.com> (716) 240-7786
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>>
>
>
> Hi Christopher,
>
> unfortunately I do not know much about your problem but I think it can be
> useful to read about WSGI and WSGI web services, servers:
>
> https://en.wikipedia.org/wiki/Web_Server_Gateway_Interface
>
> https://www.python.org/dev/peps/pep-0333/
>
> https://wiki.python.org/moin/WebFrameworks
>
> https://www.fullstackpython.com/wsgi-servers.html
>
>
> According to these articles I chose Flask for application server (it has a
> built-in development webserver as well) and Waitress for webserver.
> Maybe you can give them a try ;-)
>
> BR
> George
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python isn't working with Apache (Windows)

2017-07-31 Thread George Fischhof
2017-07-31 7:31 GMT+02:00 Christopher McGrath :

> I am trying to run a simple python web script in a browser with apache. I
> have apache installed and running perfectly. I installed Ruby and Perl
> using instructions from here and worked perfect. http://editrocket.com/
> articles/python_apache_windows.html
>
> I did have to change my “shebang lines” for PERL and RUBY like these:
> #!Q:\LifeForce\perl\perl\bin\perl.exe
> #!Q:\LifeForce\Ruby24-x64\bin\ruby.exe
> As you can see, I didn’t install them on C: drive. They worked.
>
> I had Python 3.6 installed before and tried to test with these
> #!Q:\LifeForce\Python36-32\Scripts\pip3.exe
> #!Q:\LifeForce\Python36-32\Scripts\pip.exe
> #!Q:\LifeForce\Python36-32\Scripts\pip2.6.exe
> All the pip files in the Script directory.
> I also tried with #!Q:\LifeForce\Python36-32\python.exe. This one works
> worked from Window Command, but didn’t work from web browser like PERL and
> RUBY.
> I tried downgrading to Python 2.7 and installed directly at C: drive and
> tested with
> #!C:\Python27\python.exe
> #!C:\Python27\Scripts\pip2.7.exe
> #!C:\Python27\Scripts\pip2.exe
> #!C:\Python27\Scripts\pip.exe
> Nothing worked. I don’t have any idea anymore. Please help!
> This is the simple code:
> print ("Content-type: text/html")
> print (" ")
> print ("")
> print ("")
> print ("")
> print ("Hello Python.")
> print ("")
>
> I am trying to run directly from Apache htdoc dir. Not from cgi dir. I
> think something is wrong with the shebang line.
> This is the error output in the web browser:
> Internal Server Error
> The server encountered an internal error or misconfiguration and was
> unable to complete your request.
> Please contact the server administrator at postmaster@localhost to inform
> them of the time this error occurred, and the actions you performed just
> before this error.
> More information about this error may be available in the server error log.
> Additionally, a 500 Internal Server Error error was encountered while
> trying to use an ErrorDocument to handle the request.
> This is what is shown in Apache’s error log:
> [Mon Jul 31 01:06:54.266478 2017] [cgi:error] [pid 5156:tid 1688] [client
> 98.5.128.152:51723] malformed header from script 'test.py': Bad header:
> [Mon Jul 31 01:06:54.270479 2017] [authz_core:error] [pid 5156:tid 1688]
> [client 98.5.128.152:51723] AH01630: client denied by server
> configuration: C:/Apache24
>
>
>
>
>
> Christopher McGrath
>
> [http://aawisdom.com/Top_of_main_files/BizCard-Front-hotmailSignature.jpg]
> [http://aawisdom.com/Top_of_main_files/image001.gif]
> www.aawisdom.com (716) 240-7786
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


Hi Christopher,

unfortunately I do not know much about your problem but I think it can be
useful to read about WSGI and WSGI web services, servers:

https://en.wikipedia.org/wiki/Web_Server_Gateway_Interface

https://www.python.org/dev/peps/pep-0333/

https://wiki.python.org/moin/WebFrameworks

https://www.fullstackpython.com/wsgi-servers.html


According to these articles I chose Flask for application server (it has a
built-in development webserver as well) and Waitress for webserver.
Maybe you can give them a try ;-)

BR
George
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Query regarding output

2017-07-02 Thread George Fischhof
2017-06-29 15:55 GMT+02:00 shubham goyal :

> Thanks all
> Great place to learn Python.
>
> On Jun 29, 2017 7:24 PM, "shubham goyal"  wrote:
>
> Thankyou all.
>
> Great place to learn.
>
> On Jun 29, 2017 5:55 PM, "Mats Wichmann"  wrote:
>
> > On 06/29/2017 03:02 AM, Alan Gauld via Tutor wrote:
> > > On 29/06/17 03:14, shubham goyal wrote:
> > >
> > >> This Question is asked in some exam. i am not able to figure it out.
> > >>
> > >> a = [0, 1, 2, 3]
> > >> for a[-1] in a:
> > >> print(a[-1])
> > >>
> > >> its giving output 0 1 2 2
> > >>
> > >> it should be 3 3 3 3 as a[-1] belongs to 3.
> > >> can anyone help me figuring it out.
> > >
> > > This is quite subtle and it took me a few minutes to figure
> > > it out myself.
> > >
> > > It might be clearer if we print all of 'a' instead
> > > of a[-1]:
> > >
> >  for a[-1] in a:
> > > ...print(a)
> > > ...
> > > [0, 1, 2, 0]
> > > [0, 1, 2, 1]
> > > [0, 1, 2, 2]
> > > [0, 1, 2, 2]
> > >
> > > What is happening is that a[-1] is being assigned the value
> > > of each item in a in turn. The final iteration assigns a[-1]
> > > to itself, thus we repeat the 2.
> >
> >
> > Ugh.  I guess on an exam where they're trying to see if you can tease it
> > out, as you may one day have to debug such a sequence... but don't write
> > code like that.  One of the reasons people like "functional programming"
> > is it avoids these kind of side effects.
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor
> >
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



Hi All,

just a comment ;-)
Actually I do not know why it is good to ask similar things on a Python
exam... Yes, I know that if one can answer these questions they show that
they understand it.  (Just a side question: Really understand? ;-) )

But a Pythonista never will write a code like this.

I think this behaviour is just to "show" to the student that this is very
strong school... :-(

I think it would be better to teach how to write Pythonic code...

BR,
George
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Collecting output from Python scripts executed via Cron

2017-05-19 Thread George Fischhof
2017-05-19 3:48 GMT+02:00 Leo Silver :

> I have written a several Python scripts to collect data from external
> sources (an email account and an sftp site).
>
> In development I run the scripts from IDLE or the command line and can view
> the output of various print statements in the scripts which helps me to
> monitor progress and confirm correct operation.
>
> However, in production I will be running the scripts via Cron.
>
> Is there a recommended/ elegant way to collect this output on the fly for
> later review/ processing.
>
> Previously I have written bash scripts simply redirecting the standard
> output to a text file and emailed this back to myself but I would like to
> do this directly within Python rather than having to wrap the Python script
> in a bash script.
>
> Thanks, Leo.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



Hi,

There are two task here: as You wrote, firstly log must be written to files

You could use the logging subsystem for this purpose
https://docs.python.org/3/library/logging.html

The second is to collect it and do someting.
To do this You can use for example the scedule module
https://docs.python.org/3/library/sched.html

BR,
George
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] While Loop Question

2017-05-11 Thread George Fischhof
2017-05-11 3:53 GMT+02:00 Rafael Skovron :

> Sorry I left out the indents in my previous email. It seems like j is
> always reset to zero. Why does j vary?
>
> Are there two different instances of j going on?
>
>
> for i in range(1, 5):
>
> j=0
>
>while j < i:
>
>  print(j, end = " ")
>
>  j += 1
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



Hi,

As there is a j = 0 statement in the for cycle, it will be set to 0 every
time the while cycle finishes. (The while cycle will then increment j, then
if j == i j will be set to 0 again).

George
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python help

2017-04-13 Thread George Fischhof
Hi Christina,

you should use an editor or an IDE (Integrated Development Environment) (a
quite good and my favorite IDE is PyCharm
https://www.jetbrains.com/pycharm/download/#section=windows ), write the
script in it,then save,  then run it from the IDE or from command line with
similar command:
python script_name.py

BR,
George

2017-04-13 16:33 GMT+02:00 Christina Hammer :

> Hi,
> I downloaded the newest version of Python on my windows computer and am
> having some trouble using it. I need to save my work because I am using it
> for an online class and am going to have to send it to my professor. But I
> cannot access a tool bar that would allow me to save it. I'm not sure if
> someone can help me with this.
> Thank you
> Christina Hammer
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Network Sniffing on Windows with Python 3.6

2017-04-07 Thread George Fischhof
2017-04-07 7:07 GMT+02:00 Some Developer :

> Hi,
>
> This is more a query about where to look for information rather than
> asking for specific code.
>
> There is a game that passes data over the network and I want to sniff the
> network protocol used by the game to pass data between the client and the
> server (before anyone asks no I am not cheating it is an MMO and I want to
> create a database site that holds information on all the items and quests
> in the game etc).
>
> How would I go about writing a Python 3.6 script for Windows that would
> sniff the network traffic and take the individual packets and then
> reassemble them into something that is useful data? I've never done
> something like this before.
>
> I was thinking of installing Wireshark to have a look at the network
> communications but I wasn't really sure what I would do with the data. Are
> there any library functions in Python 3.6 that would help with this task?
>
> Basically I need to lock onto the games process and sniff any incomming or
> outgoing network traffic from that process. Is that possible?
>
> Also does the Python script require admin permissions for this to work or
> can it run as a normal user? It doesn't matter if it does require admin
> permissions but it would be better for my users if it didn't require admin
> permissions.
>
> I'm just looking for some help to push me in the right direction. If there
> are any books on the subject that would be even better as I like reading
> books on programming subjects.
>
> Thanks for any help :).
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



Hi,

some days ago I started to investigate similar problem (check traffic) and
I found the following libraries (maybe it helps You):

https://pypi.python.org/pypi/pyshark_parser/0.1

https://pypi.python.org/pypi/pyshark/0.3.6.2

https://www.wireshark.org/docs/man-pages/tshark.html

BR,
George
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error when trying to use classes

2017-02-07 Thread George Fischhof
2017-02-07 16:34 GMT+01:00 Rafael Skovron :

> I'm trying to learn how to use Classes but I keep getting  NameErrors no
> matter what code I put into the script.
>
> Any ideas why?
>
> My general workflow is I edit in vim, then invoke python3 interpreter,
> import the module and try to use the Class and methods from the class.
>
> For example, importing customer.py and assigning this object yields:
>
> >>> rafael = Customer('rafael',100.0)
> Traceback (most recent call last):
>   File "", line 1, in 
> NameError: name 'Customer' is not defined
>
>
>
> class Customer(object):
> """A customer of ABC Bank with a checking account. Customers have
> thefollowing properties:
> Attributes:name: A string representing the customer's
> name.balance: A float tracking the current balance of the
> customer's account."""
>
> def __init__(self, name, balance=0.0):
> """Return a Customer object whose name is *name* and starting
>   balance is *balance*."""
> self.name = name
> self.balance = balance
>
> def withdraw(self, amount):
> """Return the balance remaining after withdrawing *amount*
>dollars."""
> if amount > self.balance:
> raise RuntimeError('Amount greater than available balance.')
> self.balance -= amount
> return self.balance
>
> def deposit(self, amount):
> """Return the balance remaining after depositing *amount*
>   dollars."""
> self.balance += amount
> return self.balance
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


Hi,

with this statement:
>>> rafael = Customer('rafael',100.0)
you (the program) creates an instance of Customer class

to import the class (this is the first), you should use the import
statement:
>>> from customer import Customer
after this the program will work.

BR,
George

PS.: pycharm from JetBrains is a very good python ide. ... (instead of vim
;-) )
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Function annotations

2017-02-06 Thread George Fischhof
2017-02-05 9:36 GMT+01:00 Steven D'Aprano :

> On Sat, Feb 04, 2017 at 10:11:39PM -0600, boB Stepp wrote:
>
> > Are the people making linters implementing checking function
> > annotations?  Or is this something only gradually being adopted?
>
> Depends which linter :-)
>
> MyPy is still the reference implementation for type hinting in Python:
>
> http://mypy-lang.org/
>
> As for pychecker, pylint, jedi, pyflakes, etc you'll have to check with
> the individual application itself.
>
> > Steve, are you making use of function annotations?  If yes, are you
> > finding them worth the extra effort?
>
> Not yet.
>
>
> --
> Steve
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



Hi,

Pycharm ide has a built-in linter, and it is very good!  It shows the
result in code writing time.

George
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How can I run this test script using selenium while making connection and running the code I am facing issue Please see my code below

2017-01-18 Thread George Fischhof
2017-01-18 11:18 GMT+01:00 Sarika Shrivastava :

> import unittest
> from selenium import webdriver
> from selenium.webdriver.common.keys import Keys
> import time
>
> class PythonOrgSearch(unittest.TestCase):
>
> def setUp(self):
> self.driver =
> webdriver.Chrome('C:\Users\uidk9685\Downloads\chromedriver.exe')
> # print self.driver
> time.sleep(0.5)
>
> def test_search_in_python_org(self):
> driver = self.driver
>
> # driver.get("http://www.python.org";)
> # self.assertIn("Python", driver.title)
> # elem = driver.find_element_by_name("q")
> # elem.send_keys("pycon")
> # elem.send_keys(Keys.RETURN)
> # assert "No results found." not in driver.page_source
>
>
> def tearDown(self):
> pass
> # self.driver.close()
>
> if __name__ == "__main__":
> unittest.main()
>
>
>
>
> [image: Inline image 2]
> --
> Best regards,
>
> Sarika Shrivastava
> Associate Engineer
>
> Continental Automotive Components (India) Pvt. Ltd.,
> 8th Floor, Gold Hill Supreme Software Park,
> Plot No. 21, 22, 27 & 28, Shanthipura Road,
> Electronics City, Phase II, Hosur Road,
> Bangalore-560 100
>
> Tel: +919741457409
> Mobile: +919741457409
> E-Mail: sarika.shrivast...@continental-corporation.com
> Web: www.continental-corporation.com
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


Hi Sarika,

maybe it is better and easyer to use pytest instead of unittest.
pytest automaticallt finds the tests in files named test_*.py or *_test.py,
and will run functions with the similar names.


You can find pytest documentation on the following link:
http://docs.pytest.org/en/latest/

and pytest can be installed by pip:
pip install pytest

BR,
George
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How can I run this test script using selenium while making connection and running the code I am facing issue Please see my code below

2017-01-18 Thread George Fischhof
2017-01-18 11:18 GMT+01:00 Sarika Shrivastava :

> import unittest
> from selenium import webdriver
> from selenium.webdriver.common.keys import Keys
> import time
>
> class PythonOrgSearch(unittest.TestCase):
>
> def setUp(self):
> self.driver =
> webdriver.Chrome('C:\Users\uidk9685\Downloads\chromedriver.exe')
> # print self.driver
> time.sleep(0.5)
>
> def test_search_in_python_org(self):
> driver = self.driver
>
> # driver.get("http://www.python.org";)
> # self.assertIn("Python", driver.title)
> # elem = driver.find_element_by_name("q")
> # elem.send_keys("pycon")
> # elem.send_keys(Keys.RETURN)
> # assert "No results found." not in driver.page_source
>
>
> def tearDown(self):
> pass
> # self.driver.close()
>
> if __name__ == "__main__":
> unittest.main()
>
>
>
>
> [image: Inline image 2]
> --
> Best regards,
>
> Sarika Shrivastava
> Associate Engineer
>
> Continental Automotive Components (India) Pvt. Ltd.,
> 8th Floor, Gold Hill Supreme Software Park,
> Plot No. 21, 22, 27 & 28, Shanthipura Road,
> Electronics City, Phase II, Hosur Road,
> Bangalore-560 100
>
> Tel: +919741457409
> Mobile: +919741457409
> E-Mail: sarika.shrivast...@continental-corporation.com
> Web: www.continental-corporation.com
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


I am sorry, I saw only the first part of the title of Your message. And I
thought that You have issues with the unittest framework.
For web automation I use the library splinter, which uses selenium, but it
is easier.

BR,
George
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Trouble Launching Python

2016-12-21 Thread George Fischhof
2016-12-19 23:38 GMT+01:00 Joseph Olugbohunmi via Tutor :

>  Hello,Good day, I installed Python 3.5.2 on my Windows 8.1 PC and then I
> tried launching IDLE as well as the Interpreter but I got a message that
> api-ms-win-crt-runtime-l1-1-0.dll was missing. I downloaded and installed
> that after which I got another message that
> api-ms-win-crt-math-l1-1-0.dll was also missing, I got that, and then
> another dll was missing and it goes on and on. Please what can I
> do?ThanksJoseph
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


Hi Joseph,

this is a Microsoft visual c++ redistributable is missing from system.
I found this stackoverflow link which seems to describing a solution

http://stackoverflow.com/questions/33265663/api-ms-win-crt-runtime-l1-1-0-dll-is-missing-when-opening-microsoft-office-file

BR,
George
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unknown syntax error

2016-12-17 Thread George Fischhof
Hi Oliver,

Your else statement should be unindented by one level ;-)
The else must be at same indent level as the if it belongs to.

BR,
George

2016-12-11 17:30 GMT+01:00 oliver patterson <
oliverjamespatter...@hotmail.com>:

> hey i dont know if this is the right place but i was just coding in idle
> and kept getting this syntax error and i can not see m to fix it here is my
> bit of code:
>
> my_age=14
> age=input("How old are you?:")
> print("type start()")
> def start():
> print("hey")
> if age == my_age:
> print("i'm",age,"too")
> else:
> if age < 14:
> print(" i'm older that you i'm",my_age,":)")
> else:
> print("your older than me i'm",my_age,":(")
>
>
>
> please help thank you.
>
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Created Function, Need Argument to be a String

2016-12-17 Thread George Fischhof
2016-12-12 17:29 GMT+01:00 Bryon Adams :

> Is there a way to force my argument to always be a string before entering
> the function? Else, is there a better way to go about this? In whatever
> program I write, I could change what I want as input to be a string prior
> to tossing it into the function but I think it would make more sense for my
> function to already do it. The function otherwise works. This is on
> Python3.5 under Fedora 25
>
> The only other thing I could think of would be to put exceptions in for
> syntax error and whatever else pops up as I go along, though to be honest
> it *should* always be a string that gets dumped into the function. Not sure
> how I'd put the exception together though since it's not making it into the
> function prior to failing.
>
> ---
> Error from interpreter: (looks like it's taking issue with it being a
> number it doesn't know how to deal with)
>
> >>> ip_checker(169.254.0.1)
>   File "", line 1
> ip_checker(169.254.0.1)
>^
> SyntaxError: invalid syntax
>
> ---
> My function:
>
> def ip_checker(ip_address):
>   '''
>   Takes one IP address and checks whether it is valid or not.
>   '''
>   # Try to convert to integers
>   try:
> ip_addr = [int(i) for i in ip_address.split('.')]
>   except ValueError:
> print('Invalid characters were entered or an octet is empty, please
> try again.')
> return False
>
>   # Determine how many octets were entered
>   if len(ip_addr) != 4:
> print('Incorrect number of octets, please try again.')
> return False
>
>   # Determine validity of first octet
>   if ((ip_addr[0] > 223) and (ip_addr[0] < 256)) or (ip_addr[0] == 0):
> print('First octet is reserved or zero.')
> return False
>
>   # Determine if this is a loopback address
>   if ip_addr[0] == 127:
> print('I think that was a loopback address, please try again.')
> return False
>
>   # Determine if this is an APIPA address
>   if (ip_addr[0] == 169) and (ip_addr[1] == 254):
> print('I think that was an APIPA address, please try again.')
> return False
>
>   # Determine if the last three octets are between 0-255
>   for octet in (ip_addr[1], ip_addr[2], ip_addr[3]):
> if octet not in [i for i in range(0,256)]:
>   print('Octet too large or too small, please try again.')
>   return False
> else:
>   print('The IP address {} is valid.'.format(ip_address))
>   return True
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



Hi Btryon,

to to force to process a string is convert the function argument to string:


def ip_checker(ip_address):
  '''
  Takes one IP address and checks whether it is valid or not.
  '''
  ip_address = str(ip_address)

And after this you can process it as a string.


To write more readable and more beautiful code, You can put all your
checkings into small functions inside the ip_checker function:




def ip_checker(ip_address):
def determine_validity_of_first_octet():


def determine_if_this_is_a_loopback():

...

determine_validity_of_first_octet()
determine ...

and so on
:-)

BR.
George
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor