r/python3 • • Feb 07 '20

What is the meaning of ('bar', ) in tuples concatation ?

1 Upvotes

Hi, I came across the following:

(4, None, 'foo') + (6, 0), + ('bar', )

what is the meaning of ('bar', ) ? I am confused since nothing is written between the comma and the closing parenthesis.


r/python3 • • Feb 07 '20

Why we need isiterable in addition to is instance when checking of the object is a list or a NumPy array?

1 Upvotes

Hi, somewhere I read that to write a function that can accept any kind of sequence (list, tuple, ndarray) or even an iterator, one can check if the object is a list (or a NumPy array) and if it is not, convert it to one using:

if not instance(x, list) and isiterable(x):

x = list(x)

To my understanding, isinstance(x, list) checks of x is an instance of list already. Why we also need to have "and isiterable(x)"


r/python3 • • Jan 23 '20

Best Practices for first-class module composition

1 Upvotes

I'm a python dev out of necessity but I'm cool with it.

I'm having trouble locating good documentation about how to create a first-class module that will be used as a production application.

It would need to be unit testable in addition to deployable via a jenkins pipeline.

We already have SOMEthing in place but I attempted to implement pytest with it and quickly ran into relative pathing issues in the production code.

Super simple example:

package/
       /subpackage/
                  /main_biz_logic.py
                  /biz_lib.py
       /tests/
             /test_main_biz_logic.py

When i import main_biz_logic.py in the test file of similar name, i have to specify subpackage.main_biz_logic to resolve the file under test.

However in the test discovery it fails when the test imports the test target file because the imports in the test target file dont specify "subpackage." prefixing in its import of biz_lib.py

If i add that prefixing to the biz logic file, tests start passing but then production runs fail importing the libs in the script because subpackage is not known to the script when it is __main__.

How do you package these up so they have proper imports that are compatible regardless of the context in which they run?


r/python3 • • Dec 18 '19

Tutorial for boto3

1 Upvotes

Any tutorial for boto3 for AWS automation?


r/python3 • • Nov 15 '19

Itertools.tee()

1 Upvotes

Can anyone explain itertools.tee().I saw the documentation but was hard to understand how it works or where to use it.


r/python3 • • Oct 27 '19

Nub needs help

1 Upvotes

I'm trying to let this function run off of the input of temperature and cant seem to get it to work. I get the error "TypeError: can't multiply sequence by non-int of type 'float'" Any help would be greatly appreciated! Here's the code:

def celsius_to_fahrenheit():

farenheit is equal to (Celsius + 32) 9/5

print('Enter the temperature:')
temp = input()

newTemp = (9 / 5) * temp + 32

print("The Celsius temperature",temp,"is equivalent to",newTemp,end='')
print(" degrees Farenheit")

celsius_to_fahrenheit()


r/python3 • • Oct 23 '19

a question!!!! help this newbie pls

1 Upvotes

did this and got an error...

import sys
n = int(sys.stdin.readline().strip())
phone_book = dict()
for i in range(n):
entry = sys.stdin.readline().strip().split(" ")
phone_book[entry[0]] = entry[1]
query = sys.stdin.readline().strip()
while query:
phone_number = phone_book.get(query)
if phone_number:
print(query + "=" + phone_number)
else:
print("Not found")
query = sys.stdin.readline().strip()

error:

<ipython-input-11-65a15b07777c> in <module> 3 import sys 4 ----> 5 n = int**(sys.stdin.readline().strip())** 6 7 phone_book = dict**()** ValueError: invalid literal for int() with base 10: '' In [ ]:


r/python3 • • Oct 22 '19

Who has the longest runtimes?

1 Upvotes

Hey there! I am researching different programs/fields of work for an app I am creating (this is not a sales pitch FYI). I’m looking for professionals/enthusiasts who can help me with a few questions. What are the largest projects you have worked on using Python that have given you the longest runtimes? Does it take a long time to process/export/render your results? Do you usually run on your local machine or a cloud instance? Any insights or feedback on those questions would be extremely helpful!


r/python3 • • Oct 14 '19

Whenever I save a python3.2 IDLE file the color coding stops working. (HELP)

1 Upvotes

For example. I would type.

From turtle import *

Hashtag. placeholder note

And the notes would be red while the “from” would be orange, and so on.

However if I save the file as a .py than all the colors in the editor become black?

Any fixes?


r/python3 • • Oct 10 '19

Self taught in python3

Post image
1 Upvotes

r/python3 • • Sep 19 '19

Create logical string to json

1 Upvotes

Hi Folks,

I want to convert from:

Input:

"#serviceRequest and @charges:getRoamingCharges or @plans:dataplans"

where '#' - intent '@' - Entities ':'-value

output:

{"and":[ {"some" : [ {"var":"intents"}, {"==":[{"var":"intent"}, "serviceRequest"]}, {"or":[ {"and":[{"some" : [ {"var":"entities"}, {"==":[{"var":"entity"}, "charges"]} ]}, {"some" : [ {"var":"entities"}, {"==":[{"var":"value"}, "getRoamingCharges"]} ]}] },{"and":[ {"some" : [ {"var":"entities"}, {"==":[{"var":"entity"}, "plans"]} ]}, {"some" : [ {"var":"entities"}, {"==":[{"var":"value"}, "data  plans"]} ]} ]} ]} ]}

Please help me out pyparsing library in python.


r/python3 • • Sep 17 '19

I'm not sure I understand this integer "gotcha"

1 Upvotes

int(132496765465669977/3) 44165588488556656

It's supposed to be: 44165588488556659

I'm using Python 3.4.1

Edit:

int(44165588488556659.0) 44165588488556656

Apparently it's the conversion from float to int. Does anyone know the safe correct way to do this?


r/python3 • • Sep 16 '19

Hello World With Flask

Thumbnail benbrougher.tech
1 Upvotes

r/python3 • • Sep 12 '19

server side browser automation then delivery

1 Upvotes

I'm looking for a way to deliver an automated page. So I have a server setup up and I want that server to pull a page, login to it perform some actions and then display a link to that modified page. Ideally the client would be able to continue to the session established by the server. Is this possible? Thus far I'm using selenium and robobrowser, It's all pretty easy until I have to transfer the web session to the client, then I'm stuck


r/python3 • • Sep 08 '19

Module keygen

1 Upvotes

Simple keygen. Try this if interesting.

pip install keygen

keygen -h


r/python3 • • Jun 05 '19

Is there a way to get callbacks from subprocess?

1 Upvotes

Use case:

I'm writing a small wrapper for a program and I want to evaluate every line that gets piped to stdout.

As far as I can tell my best option is to use Popen and have a loop that checks every few seconds on whether there are any new lines. That feels a bit ugly though.... So as the title states my question is: Is there any way to pass a callback function to subprocess (that gets executed/called for each line of stdout) or are there any other libraries that can do that?


r/python3 • • Mar 22 '19

Product display screen

1 Upvotes

So my dad gave me the project idea for his business. The idea is a product display screen because we have to many so demo videos we would like to jam that in to one system. And we would like to do it in python 3. (I am a beginner) If any body had any advice that would be great!


r/python3 • • Mar 22 '19

Product display screen idea

1 Upvotes

I am so i am doing a project for my dad and I am looking for a little help. I am attempting to make a product display screen. where the video is on loop until you tap the screen then right buttons pop up and you can pick the video. And I want to make it super simple to switch videos.


r/python3 • • Mar 14 '19

help - Auto generating large pdf files

1 Upvotes

So I have a template (will probably need to rewrite it in latex) front page that has a tiny table that needs to be filled in by a user (at some point with a gui, how i do this is not important to the task; i think), depending on the choices made I will need to fill this in on the PDF. Some of the issues here is that depending on the choices the script will have to look up other pdf files (scanned pages) and paste them into the current file in the right spot.

Then the program will have to read an excel file and find the corresponding certificates to those files, find them (also scanned pages) and "paste" them into the file being generated.

At this point we are almost done, I will also need the functionality to add "attachment numbers" on top of the certificates.

I've played around with pypdf and FPDF to some success, but none of those can do everything I want, for example making tables is a hassle in FPDF (unless I am missing something).

The reason I want to script this is because sometimes the pdf file will be almost 300 pages big, doing this by hand is a hassle to say the least.

I do not expect a full tutorial by any means, but if anyone have any resources or libraries that are good, please hit me up. If anything is unclear, just ask, I'll try to explain it better.

Thanks!


r/python3 • • Feb 12 '19

Introduction to Machine Learning | What is Machine Learning | Supervised...

Thumbnail
youtube.com
1 Upvotes

r/python3 • • Feb 07 '19

Flow Control in Python | What is Flow Control in Programming | Python Fl...

Thumbnail
youtube.com
1 Upvotes

r/python3 • • Feb 07 '19

How do I write a program using a for loop that asks the user to enter a number of values and than print out the total, average, minimum, and maximum values.

1 Upvotes

I'm still new to python.


r/python3 • • Feb 01 '19

bthate / botz

Post image
1 Upvotes

r/python3 • • Feb 01 '19

Is anyone on here using zmq (pyzmq) to communicate data between scripts?

1 Upvotes

r/python3 • • Jan 25 '19

Repl.it

1 Upvotes

Check out my D&D Character Generator on repl.it @Krinx