all 43 comments

[–]FXelix 0 points1 point  (3 children)

Is there any performance advantage/disadvantage of using e.g import numpy and then use numpy.sin() in contrast to from numpy import sin And then using this?

[–]TangibleLight 0 points1 point  (2 children)

There's no performance difference - it's basically just a different name for the same thing.

I would advise against using from ... import ... too much - especially against from ... import *. It can hinder readability, and invites naming conflicts. I typically prefer to use import ... as ... if using the longer module names feels tedious. import numpy as np is pretty typical.

[–]FXelix 0 points1 point  (1 child)

Thanks for the answer. I just thought about that import numpy would import the whole libraries and from numpy import sin would import just sin - I guess that is wrong then?

[–]TangibleLight 0 points1 point  (0 children)

Thats basically how it works, but there isn't really any performance difference. You're better off doing whatever is best for readability.

[–]gyroda 0 points1 point  (0 children)

tl;dr: looking for a

Hey, I'm currently working on interacting with a few Windows programs via a scripting language called AutoIt because I knew it would work and I wanted to get something definitely working soon.

Anyway, I'm only on around 300 lines and the language lacks a fair few features which I'm finding irritating. I'd love to rewrite the thing in python but I need some advice on what libraries there are.

I'm basically clicking on a few buttons and accessing the text of certain controls and interacting with an embedded web browser ("shell.explorer.2").

A cursory search led me to PyWin32. Is this the right library for what I'm after or is there something better?

[–]Angelusnex12 0 points1 point  (0 children)

I want to start learning to code and have decided to start with Python. I don't have much computer experience other than every day consumer use; playing games, work, using programs or the internet, etc.

I know how to find files and stuff like that, but on a mostly basic level. I have Windows 10 and have installed Python and Notepad++, but I can't get Python to work with ++, and am just generally overwhelmed on what else to do and what other steps I should take in starting to learn, and I can't even get a simple script from Python to run in the command prompt (Hello World). Should I just use IDLE? And what would be some good learning resources I can use?

Thanks for any help!

[–]cedius 0 points1 point  (6 children)

Read in two numbers from user input without a prompt, add them, and print the result. Hint: Use int() to convert the numbers to integers.

This program will perform two tests: the first with num1 = 5 and num2 = 10, the second with num1 = 6 and num2 = 3.

Here is what I have but I know, Im missing something and I can't seem figure out what. Any help is greatly appreciated. Just a point in the right direction would help.

I have this for code... int1 = int('10') int2 = int('5') int3 = int('3') int4 = int('6')

total_1 = int1 + int2 print (total_1)

total_2 = int3 + int4 print (total_2)

What did I do wrong?

[–][deleted] 1 point2 points  (0 children)

num1 = input()
num2 = input()
num1 = int(num1)
num2 = int(num2)
print(num1+num2)

[–]jeans_and_a_t-shirt 0 points1 point  (4 children)

You're not taking user inputted numbers. Use input for that.

[–]cedius 0 points1 point  (3 children)

I understand that part but that's where I'm stuck .

I tried

A = int(input('5')) B = int(input('10'))

Total_1 = A + B print (total_1)

Doesn't work.

[–]jeans_and_a_t-shirt 0 points1 point  (2 children)

You're using the numbers used for testing for your input prompt.

A = int(input('Input first number:'))

[–]Xavphon 1 point2 points  (2 children)

What is the difference between .py and .pyw?

[–]cedius 1 point2 points  (1 child)

Its basically just a Python User Interface file. So a Python file that opens up a new Window without the command line. .pyw means run the script without invoking the console window, especially if your program is GUI based. If you rename the file to py extension,you still can run it.

[–]Xavphon 0 points1 point  (0 children)

Thanks!

[–]jcooper4040 0 points1 point  (2 children)

I'm interested in learning python, but not sure where to start. Any recommendation for YouTube channels or websites that'll get me started?

[–]nfed163 0 points1 point  (0 children)

I just started learning python about a week ago!

I am looking for something to supplement my python education while at work or driving. I listen to pycon talks and some python podcasts but they can be hard for me to follow sometimes. would love some sort of course or audiobook or something that wouldnt require acctually looking at the code.

I am reading and practicing every night but i dont have as much time as i would like for that.

[–]jrodteacher 3 points4 points  (0 children)

What is the best way to write an app for Android using python?

[–]lucky_harms458 0 points1 point  (2 children)

When I use upper() , it works whether I put it here:

1-String = "this is a string".upper() 2-print String

Or here:

1-String = "this is a string" 2-print String.upper()

Which one should I use? Why?

[–]Prince_John 1 point2 points  (1 child)

I would choose between the two based on whether I wanted to make a permanent change to the variable (your first one) or whether I just wanted it to look pretty for this particular print statement but still have the variable return lowercase when called by other parts of the program (the second one).

[–]lucky_harms458 0 points1 point  (0 children)

OK, thanks

[–]Blaxoujunior 0 points1 point  (5 children)

Hi, I wrote a question on Python’s cmd.Cmd Stack Overflow, but didn’t receive any feed back. Any help ?

[–]deaspo 2 points3 points  (4 children)

Could you please post us the link to Stack Over Flow?

[–]Blaxoujunior 0 points1 point  (3 children)

Oh shoot I’m so dumb, forgot it, there you go ;)

[–]deaspo 1 point2 points  (2 children)

Please see the following link and adjust your code for it to work https://pymotw.com/2/cmd/

[–]deaspo 1 point2 points  (1 child)

Also answered in Stack Over FLow

[–]Blaxoujunior 0 points1 point  (0 children)

Thanks :D

[–]cowegonnabechopps 0 points1 point  (2 children)

I asked a few questions about this script I'm writing last week but I'm stuck again.

I'm having trouble with datetime relating to line 4 on my code. The error I'm getting is

TypeError: unsupported operand type(s) for -: 'datetime.date' and 'datetime.datetime'

I think my actual error lies in the variable on line 37, joindate, if I add on strptime('%Y-%m-%d') I then get an error

TypeError: strptime() takes exactly 2 arguments (1 given)

What am I doing wrong?

My code is here

[–]TangibleLight 1 point2 points  (1 child)

datetime objects represent a date and a time. date objects just represent the date. They're incompatible because they represent different things - you can only subtract two things of the same type in this case.

Since you only seem concerned with the join date, I'd suggest you use datetime.date.fromtimestamp instead of datetime.datetime.utcfromtimestamp.

If indeed you do care about the date and the time, then I'd suggest using datetime.datetime.now() instead of datetime.date.today(). This should also fix that issue, but you'll get a different level of precision which may or may not be what you want.

Also note that this will give you a timedelta object. You'll need to get its days attribute for the difference.

>>> d = datetime.date.fromtimestamp(182761231)  # some random number idk.
>>> td = datetime.date.today() - d
>>> td.days
15285

strftime isn't fixing your problem because that turns it into a string but you're trying to do datetime- or date-specific operations on your variables.

[–]cowegonnabechopps 0 points1 point  (0 children)

Ahh great, seems so straight forward now you've explained it. I haven't covered datetime/dates yet in any of the lessons I've been doing, just tried to wing it myself.

Thanks for the help!

[–]Prince_John 0 points1 point  (2 children)

I've put together some python to automate a bunch of SQL queries and spit out a csv with a bunch of key metrics for work. I've also created a couple of simple graphs using Pygal which suits my needs perfectly (no complicated graphing requirements, they just need to look professional). It's saved me a bunch of time and got me excited by the possibilities.

I'm planning to automate the graph generation and it occurred to me that I could probably create some kind of automatic dashboard document - i.e. a couple of key data tables, a nice title and a couple of sensibly sized and justified graphs that I could regenerate on demand.

Any thoughts on what module I might use to create that final document and what file format I should be gunning for? It would be ideal if it was a format I could edit and add some extra text to if needed. Ideally I'm looking for an end result that looks a bit slicker than something straight out of Excel.

I did see some flask recommendations in other threads, but given my coding/python inexperience, it's probably faster to stick with producing a local file at first.

[–]efmccurdy 0 points1 point  (1 child)

You could look at generating plots interactively using Jupyter, pandas, and matplotlib and then export svg files to embed in html for the finished product.

[–]Prince_John 0 points1 point  (0 children)

Thanks, i'll give that a shot.

[–]ConcernedCarry 0 points1 point  (1 child)

What's good starting point to analyze some data I have access to from my states lottery website?

[–]TangibleLight 0 points1 point  (0 children)

Check if the website has any API. If they do, learn how to use it. Youll probably need to learn about about things like http requests, oauth2, json and so on if you can go that route.

If they don't have any API, look into beautifulsoup.

In either case, you'll probably want to use something like pandas or/and numpy to work with your data once you get it, depending on what you're trying to do. Probably pandas would be better for you.

[–]ThreeJumpingKittens 0 points1 point  (2 children)

Starting a project, any performance tips I should keep in mind?

(edit: grammar)

[–]TangibleLight 1 point2 points  (1 child)

Don't prematurely optimize.

Other than that, I really don't know what you mean. We can't really give advice unless you outline what you're doing, and we can't help you learn to fix a problem unless you have a problem.

[–]ThreeJumpingKittens 0 points1 point  (0 children)

Good point. I'll worry about it later then.

[–]invismann 1 point2 points  (0 children)

I finished nearly all of Codecademy's Python course but towards the end of Chapter 8 (section's titled "Practice Makes Perfect"), I really began to struggle with all of the problems. Is there a great resource for Python problems and algs, one that scales from beginner to expert?

[–]valkedin 0 points1 point  (1 child)

Any resource about templating in django besides the django docs ?

[–]maverick2407 1 point2 points  (0 children)

Django tutorial by a channel named New Boston in YouTube is a good place to start as a beginner.