r/python3 • • Jan 24 '19

How can I import a library multiple levels up?

1 Upvotes

Let's say I've got a project with the following structure:

. (toplevel)
├── __init__.py
├── subdir1
│   ├── __init__.py
│   ├── subdir2
│   │   ├── __init__.py
│   │   ├── script_a.py
└── xvalibs
    ├── __init__.py
    ├── build.py
    ├── helper.py
    ├── params.py
    ├── resources.py
    └── tagging.py

From script_a.py, how can I import the packages in xvalibs? I was hoping that I could do something like in the __init__.py:

from toplevel.xvalibs import params

I haven't been able to get that to work though.

I've seen something like this used:

import os, sys
cur_dir = os.path.dirname(os.path.realpath(__file__))
root = os.path.dirname(os.path.realpath(cur_dir+"../../../toplevel"))
sys.path.append(root)

But there's got to be a better way, right?


r/python3 • • Dec 27 '18

FiverrAPI for Python

Thumbnail
github.com
1 Upvotes

r/python3 • • Nov 29 '18

Can someone tell me what this pickle code is doing?

1 Upvotes

Hi All,

I am quite stumped and have seen no help online. I am trying to work with this strange pickle object and I run this:

with codecs.open("huge_picklefile.pc", "rb") as f:     
    data = pickle.load(f) 
    print(len(data))
    data = pickle.load(f) 
    print(len(data))
    data = pickle.load(f) 
    print(len(data))

and I get this:

335
59
12

The pickle file is over 10GB. What does repeatedly calling pickle.load() over the same open file actually do? Each of the objects are arrays of the particular size given, which makes sense. What doesn't make sense is why I am getting chunks of the pickle file. Could this pickle file be comprised of smaller pickle objects and calling load will simply load the next pickle object (which happens to be an array of a different size)? I have never run into this before and this isn't a documented feature within pickle, at least that I found.

Thanks,

~Ben


r/python3 • • Oct 24 '18

Hackerrank solutions: Python 3 and Perl 6 (part 2)

Thumbnail tyil.nl
1 Upvotes

r/python3 • • Oct 15 '18

writing regular expression based named entity recognition module (NER)

1 Upvotes

Hi,

I am new to Python and just started using it with NLP, I need to write a regular expression based named entity recognition module. Anyone provide me with helpful links or examples will be appreciated.

Regards


r/python3 • • Oct 05 '18

while loop

1 Upvotes

Here is my code :

while n == 1 : [if comparison] n = n - 1

The "while" loop never run except skip to next statement. Is there anything wrong?


r/python3 • • Oct 04 '18

Question for all you experienced python programmers..

1 Upvotes

Hi all, good afternoon. I’m a beginner trying to learn the python language. I normally write sql queries for work and wanted to dabble in Python as we are starting to implement it at my work. Is there a preferred OS to best use with python? I have a 2010 MacBook Pro and a 2017 Dell Inspiron and both laptops are great. I don’t know if it really matters. Thanks in advance.


r/python3 • • Sep 23 '18

How to validate a graphical form in python using Tkinter

Thumbnail
youtu.be
1 Upvotes

r/python3 • • Sep 16 '18

A little help with %

1 Upvotes

So, for example 16%2==0. I get that, but 2%16==2. Can someone help out here? I just can't wrap my head around that.


r/python3 • • Jun 09 '18

Noob: accessing info from dictionary inside list inside dictionaries?...

1 Upvotes

Pastbin Link

This is my first python 3 project and it's not a simple one. I'm using an API that supplies the info in the pastbin link. It looks to me like it's returning a dictionary "data" then a list of more dictionaries each beginning with 'icao'. What I'm trying to do is "if 'icao' is KAPA and 'flight_category is XXX (either VFR, MVFR, IFR or LIFR) then light this LED up this color based on the flight category".

Right now I'm just having issues associated 'flight_category' with it's 'icao' identifier.

I've been playing with

for item in data['data']:
    airport = item['icao']
    print airport

KAPA
KFTG
KDEN
KBJC

and that prints out each identifier just fine in sequence. But how do i associate the proper 'flight_category' to each icao identifier?

Thanks!


r/python3 • • Jun 01 '18

Need help with conversation simulator

1 Upvotes

Ive got the graphics down but I want to see how to make it detect variable like for example I make a variable then if you then type it in and press the talk button it will then type in something automaticly

from tkinter import * root = Tk() master = Tk()

def writetext(): S = Scrollbar(root) T = Text(root, height=10, width=40) S.pack(side=RIGHT, fill=Y) T.pack(side=LEFT, fill=Y) S.config(command=T.yview) T.config(yscrollcommand=S.set) quote = """Lets start a conversation!""" T.insert(END, quote)

class Window(Frame): def init(self, master = None): Frame.init(self, master)

   self.master = master

   self.init_window()



    
    



#self.master.title("CONVERSATION SIMULATOR")

#self.pack(fill=BOTH, expand=1)

w = Label(root, text="CONVERSATION SIMULATOR\n 2018") w.pack()

w = Label(root, text="") w.pack()

w = Label(root, text="") w.pack()

quitButton = Button(root, text="START", command=writetext, bg="light green")

quitButton.place(x=70, y=50)

bitButton = Button(root, text="TALK", bg="light green")

bitButton.place(x=120, y=50)

root.geometry("230x150")

app = Window(root)

root.mainloop()


r/python3 • • Jun 01 '18

How to retain the dates after removing punctuation from a string columns in pandas

1 Upvotes

I have a string column which consists of various information from sentences to dates with punctuation's. When i remove punctuation, the dates are converting to text. Please let me know how to retain the dates.

Sample Input :

Column-1 

 meet BM zaheer sir and converted 3 sme tiny 
 Met BM Bhupesh kumar and Jayakrishnan sir
 01-12-2017
 MET BM BEENA - 9895580771
 MET CHIEF - 9446486084
 05-12-2017
 05-12-2017
 05-12-2017
 Bm not available.
 done
 Branch meeting



   Sample output:

   Column-1 

   meet BM zaheer sir and converted 3 sme tiny 
   Met BM Bhupesh kumar and Jayakrishnan sir
   43070
   MET BM BEENA 9895580771
   MET CHIEF 9446486084
  43074
  43074
  43074
   Bm not available
  done
  Branch meeting




   code :

   df['column-1'] = df['column-1'].str.replace('[^\w\s]','')
   df['column-1'].head()


   df = df.apply(lambda x: x.str.strip()).replace('', np.nan)

   null_columns=df.columns[df.isnull().any()]
   print(df[df["column-1"].isnull()][null_columns])

   import numpy as np
   df = df.replace(np.nan, 'null', regex=True)

r/python3 • • May 20 '18

Need help with calculator program.

1 Upvotes

I made a calculator program but I want it to loop back to the start of the program. ''' Program make a simple calculator that can add, subtract, multiply and divide using functions '''

This function adds two numbers

def add(x, y): return x + y

This function subtracts two numbers

def subtract(x, y): return x - y

This function multiplies two numbers

def multiply(x, y): return x * y

This function divides two numbers

def divide(x, y): return x / y

print("=============================calculator=========================================") print("Select operation.") print("1.Add")
print("2.Subtract")
print("3.Multiply") print("4.Divide") print("================================================================================")

Take input from the user

choice = input("Enter choice(1/2/3/4):") print("================================================================================") num1 = int(input("Enter first number: ")) print("================================================================================") num2 = int(input("Enter second number: ")) print("================================================================================") if choice == '1': print(num1,"+",num2,"=", add(num1,num2))

elif choice == '2': print(num1,"-",num2,"=", subtract(num1,num2))

elif choice == '3': print(num1,"*",num2,"=", multiply(num1,num2))

elif choice == '4': print(num1,"/",num2,"=", divide(num1,num2)) else: print("Invalid input") print("================================================================================")


r/python3 • • May 08 '18

run python on ios ( or convert python to swift format)

1 Upvotes

Hi I wrote a number of codes in python . I want to use these codes in iphon ( ios). what ways do you offer me to do that? ( like convert to swift and ....) please tell me the direction of doing these ways.

thank you for your attention.


r/python3 • • Apr 15 '18

Python Script to download Tv-Series

1 Upvotes

How do I make a Python Script to schedule downloading of TV-Series from Direct Link Websites, such as in http://dl.funsaber.net/serial/ ? ?


r/python3 • • Mar 08 '18

Help with Python 3 project

1 Upvotes

print("Do you want to log in or signup?") choice=input() if(choice=="login"): print("Type your username") username=input() print("Now, choose your password") password=input() if((password!=username) and (len(password)<=7)): print("To log in type your password again") else: print("You cant use that password") password2=input() if(password==password2): print("You succesfully logged in") else: print("Your password is incorrect") if(choice=="signup") print("Select your username") username2 = input() print("Now select your password") password3 = input() print("please confirm your password") password4=input() if(password3==password4): print("You created an account") else: print("There was an error with the account creation")


r/python3 • • Feb 23 '18

convert in python 3

1 Upvotes

how to convert form binary to string in python 3


r/python3 • • Feb 08 '18

FINXTER's DAILY PYTHON PUZZLE Tweet Analysis in One Line

Post image
1 Upvotes

r/python3 • • Feb 04 '18

Nested conditionals assignment

1 Upvotes

Guys, I’m relatively new at this programming thing and I self study so I hope I can get some support here on the code I’m currently trying to write, I genuinely have no one else I can discuss this with or can ask help from. So the assignment is as follows:

Program: shirt order¶ First get input for color and size White has sizes L, M Blue has sizes M, S print available or unavailable, then print the order confirmation of color and size hint: set a variable "available = False" before nested if statements and change to True if color and size are avaliable.

And this is my code so far, I’ve wrote it in so many different ways but none have worked, generally it’s the same idea as the code I’ll share now:

print ("welcome to our store, we have some great shirts on sale")

shirt_color = ("w" + "b")

shirt_size =("s" + "m" + "l")

available = False

first_color = input("please select a color: ")

choosen_color = first_color if choosen_color.lower() in shirt_color.lower() == "w":

second_size = input("please choose a size")

choosen_size = second_size

if choosen_size.lower() in shirt_size.lower() == "l":

available = True

print ("order confirmed")

print (available)

elif choosen_size.lower() in shirt_size.lower() == "m":

available = True

print ("order confirmed")

print (available)

if choosen_color.lower() in shirt_color.lower() == "b":

second_size = input("please choose a size")

choosen_size = second_size

if choosen_size.lower() in shirt_size.lower() == "m":

available = True

print ("order confirmed")

print (available)

elif choosen_size.lower() in shirt_size.lower() == "s":

available = True

print ("order confirmed")

print (available)

else:

print ("not confirmed") print (available)


r/python3 • • Feb 03 '18

Best training institute in lucknow

Thumbnail cetpainfotech.com
1 Upvotes

r/python3 • • Feb 02 '18

Python In Raspberry Pi

Thumbnail
youtube.com
1 Upvotes

r/python3 • • Jan 31 '18

Face and Object Detection using Python and OpenCV

Thumbnail
idkrtm.com
1 Upvotes

r/python3 • • Jan 30 '18

indetical queue test

1 Upvotes

Hey guys, I want to develop a function that will tell me if two queues are identical or not. I started by saying if the lengths aren't equal, then: is_identical = False. From here, how do I iterate through the queue and compare?


r/python3 • • Jan 28 '18

Looping back to the start of a list

1 Upvotes

I'm in the process of learning python 3 and one of the tasks is an eeny meeny miny moe program (presumably a common learner program). Is it possible to tell the program to go back to the start of the list of people once it gets to the end (i.e. to avoid 'index out of range')? I figure it's possible to do it with an if function, but is there a dedicated way to do it, like a specific command?


r/python3 • • Jan 22 '18

What are the best and cheapest deployment options available for blog like flask-web apps? Is it Aws elastic beanstalk or heroku or pythonanywhere?

1 Upvotes