r/learningpython • u/Intelligent_Peanut90 • May 30 '21
HELP! I have a very basic loop I need help with.
Can anyone help? Ill explain in DMs
r/learningpython • u/Intelligent_Peanut90 • May 30 '21
Can anyone help? Ill explain in DMs
r/learningpython • u/lljc00 • Apr 20 '21
Noob here.
What is it called when you type your variable and add something like ".upper" - dot upper - to it to make it uppercase? To me, it kind of feels like you are "operating" on it, no?
And how is it different (or why is it different) than performing a function on something (which would be the parameter, technically, correct?)
Another example - and I'm not sure if this is a function or whatever the answer to my first question is:
"".join((rightlettersguessed))
this is coming from my Hangman that I wrote, copying from what I saw in another Hangman program. it's blank with a dot join, and then my variable.
I find it somewhat helpful to read other people's code, but I feel like I need to give this "operation" a name so I can process it in my head as to what the code is trying to do.
r/learningpython • u/Life_Ad2865 • Feb 17 '21
Does anybody know how to install videocapure? I got using it down but I got a new computer and can’t get it on. I’m using py charm and python 2.7 btw
r/learningpython • u/tapherj • Feb 05 '21
I am trying to do a tutorial on Colab and Pandas and they have us using the following:
df = pd.DataFrame.from_records(rows)
This brings in the entire worksheet from the Google workbook/spreadsheet. I don't want the first row to be displayed. It only contains a title and date. The headers for the columns start on the second row. How can I skip this first row. I've tried what i would do if using a csv file (skiprows = 1) but it does not work.
Any suggestions appreciated, yes I have Googled it, looked at the documentation and search for other sample code.
r/learningpython • u/Lazosa • Jan 17 '21
Hey guys I get the following Error Message.
No module named 'request'My Code is the following
import panda as pd
FCD_Data = pd.read_csv("D:\Python\Master\FCD_Export.xlsx")
print(FCD_Data.shape)When I want to install 'requests' i get the following Output.
Requirement already satisfied: requests in c:\users\stabi\anaconda3\lib\site-packages (2.25.1)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\stabi\anaconda3\lib\site-packages (from requests) (2020.6.20)
Requirement already satisfied: idna<3,>=2.5 in c:\users\stabi\anaconda3\lib\site-packages (from requests) (2.10)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\users\stabi\anaconda3\lib\site-packages (from requests) (1.25.9)
Requirement already satisfied: chardet<5,>=3.0.2 in c:\users\stabi\anaconda3\lib\site-packages (from requests) (3.0.4)So if I get this right already have the request installed?
What else can I do? Am I missing something?
r/learningpython • u/idify • Jan 10 '21
Hi I've always run python locally, and it's been easy to save and access files.
Now I have a heroku app that's running from a github file.
I'd like my program to save dataframes or csvs and be able to access those files in future.
I'm just wondering what is the best way to do it. Can I save them to github, or should I use an alternative data host?
I don't expect to need more than 50-100mbs in total for all the files
r/learningpython • u/SaturnAer • Nov 23 '20
https://cdn.discordapp.com/attachments/626942275024322569/780554507238113300/3.png This array shows x=4 and y=1 but im so confused as to how x is getting a final value of 4. Any explainers would be greatly appreciated!
r/learningpython • u/[deleted] • Nov 05 '20
I'm testing app which uses OpenCV 4.4 on Android and in the moment when the app supposed to launch the camera the camera won't launch and in logs I get:
cv2.error: OpenCV(4.0.1) /home/mark/frontend_android/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/opencv/armeabi-v7a__ndk_target_21/opencv/modules/highgui/src/window.cpp:610: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvNamedWindow' I installed libgtk2.0-dev and pkg-config was already present.
I'm using pip packages:
opencv-python 4.4
opencv-contrib-python 4.4 P4A recipes I'm using:
opencv
opencv_extrasI've found this on the web but I'm not sure if it's relevant to my problem:
MacOS and Linux wheels have currently some limitations:
video related functionality is not supported (not compiled with FFmpeg)
for example cv2.imshow()
will not work (not compiled with GTK+ 2.x or Carbon support)
I'm not using imshow() attribute but I do use VideoCapture(0).
Any help much appreciated.
r/learningpython • u/hhwt • Oct 16 '20
Any recommendations on a learning resource for working with strings and substrings using Pandas for beginners to Python? All of the resources I’ve found so far assume a greater knowledge of Python than I have right now.
I’ve been handed a project that will probably work better with Python. It is a large, messy Excel file with several text variables I need to recode into dichotomous variables based upon various substrings.
I’ve successfully read the file into Python and searched and replaced line feeds in the dataset with plain text separators.
The data are still messy with some, but not all, having leading and trailing separators used within the body of the text string.
Once I get those cleaned up, I’ll need to figure out how to slice and dice the strings based upon whether one of several substrings are in the string.
Thanks for any help in navigating the bewildering array of resources that are out there.
r/learningpython • u/HauntingRex9763 • Oct 03 '20
def vowelDetectora(myString):
return (myString.count("a"))
def vowelDetectore(myString):
return (myString.count("e"))
def vowelDetectori(myString):
return (myString.count("i"))
def vowelDetectoro(myString):
return (myString.count("o"))
def vowelDetectoru(myString):
return (myString.count("u"))
def vowelDetectorA(myString):
return (myString.count("A"))
def vowelDetectorE(myString):
return (myString.count("E"))
def vowelDetectorI(myString):
return (myString.count("I"))
def vowelDetectorO(myString):
return (myString.count("O"))
def vowelDetectorU(myString):
return (myString.count("U"))
print ('what is the text that you would like to count the vowels in? ')
myString = input()
if (vowelDetectora(myString) + vowelDetectore(myString) + vowelDetectori(myString) + vowelDetectoro(myString) + vowelDetectoru(myString) + vowelDetectorA(myString) + vowelDetectorE(myString) + vowelDetectorI(myString) + vowelDetectorO(myString) + vowelDetectorU(myString) > 1):
print (vowelDetectora(myString) + vowelDetectore(myString) + vowelDetectori(myString) + vowelDetectoro(myString) + vowelDetectoru(myString) + vowelDetectorA(myString) + vowelDetectorE(myString) + vowelDetectorI(myString) + vowelDetectorO(myString) + vowelDetectorU(myString) + ' vowels detected')
elif (vowelDetectora(myString) + vowelDetectore(myString) + vowelDetectori(myString) + vowelDetectoro(myString) + vowelDetectoru(myString) + vowelDetectorA(myString) + vowelDetectorE(myString) + vowelDetectorI(myString) + vowelDetectorO(myString) + vowelDetectorU(myString) == 1):
print (vowelDetectora(myString) + vowelDetectore(myString) + vowelDetectori(myString) + vowelDetectoro(myString) + vowelDetectoru(myString) + vowelDetectorA(myString) + vowelDetectorE(myString) + vowelDetectorI(myString) + vowelDetectorO(myString) + vowelDetectorU(myString) + ' vowel detected')
else:
print ('0 vowels dected')
r/learningpython • u/WombatHat42 • Sep 20 '20
I am working on a BFS for a larger program assignment. This is part of my test to see if my search is working and I keep getting a node that isn't supposed to be being added (0,'l').
The purpose of this is to search down and find the possible routes the program can take. It will start at index[0] and move the number of spaces of the number at that node(IE if number is a 2 it moves 2 spaces in the determined direction). However, the input is a in string form(2322443122G22124131321422), the reality is that the computer should see it as a 5x5 grid:
2 3 2 2 4
4 3 1 2 2
G 2 2 1 2
4 1 3 13
2 1 4 2 2
Rules for movement: If in column 1 it cannot move "left", column 5 cannot move "right". Top row cannot move up, bottom row cannot move down. Stop when "G" is found.
There are a few other issues with the code, but I am trying to focus on things one at a time and this one is quite annoying lol
Here is my code:
pond = "2322443122G22124131321422"
i=0 #counter
pos = int(pond[i])
routes = []
new_pos = 0
##direction = ""
while new_pos not in routes:
pos = int(pond[i])
# moves to right
new_pos = i+pos
if i//5 == new_pos // 5:
## new_pos = i+pos
## i+=new_pos
routes.append((new_pos,"r"))
## routes.append((new_pos))
## routes.append(("r"))
routes.pop
else:
pass
#moves to left
new_pos = i-pos
if new_pos >= 0 and i//5 == new_pos // 5:
## new_pos = i-pos
# i+=new_pos
routes.append((new_pos,"l"))
#outes.append(("l"))
else:
pass
if new_pos == "G":
pass
#move down
new_pos = i + pos*5
if i <= 24:
# i+=new_pos
routes.append((new_pos,"d"))
##
###move up - commented out bc testing of down,left,right is incomplete
##new_pos = i - pos*5
##if i >= 0:
## routes.append((new_pos,"u"))
## if new_pos == "G":
pass
i+=pos
#print(i)
#print(new_pos)
print(routes)r/learningpython • u/Comprehensive-Signal • May 03 '20
I was reading about documentation and all this stuff but when I try to put in my cmd this:
pydoc my_module
Says that is not recognized
r/learningpython • u/nave1235 • Apr 28 '20
w, h = 8, 8;
Matrix = [[0 for x in range(w)] for y in range(h)]
for w in Matrix:
for h in w:
print (w[h],end = " ")
print()
numA = int(input())
numB = int(input())
Matrix[numA - 1].pop(numB - 1)
Matrix[numA - 1][numB - 1] = J = 1
for w in Matrix:
for h in w:
if h == 0:
print(w[h],end = " ")
else:
print("@",end = " ")
print()
it won't show the last spot in the line where you change the number.
try it and see
(im using python 3.7 and notepad++ btw)
r/learningpython • u/[deleted] • Apr 07 '20
I'm trying to figure out a good to solve this problem and maybe talking to someone else might help the ideas stick while doing a problem from Code wars.
I'm essentially trying to return a string suggesting how many glasses of water you should drink to not be hungover.
my pseudocode is pretty simple
if x beers were drank:
drink y cups of water
below is what is given
def hydrate(drink_string):
# your code here
pass
@test.describe('Example Tests')
def example_tests():
test.assert_equals(hydrate("1 beer"), "1 glass of water")
test.assert_equals(hydrate("1 shot, 5 beers, 2 shots, 1 glass of wine, 1 beer"), "10 glasses of water")so far I have
def hydrate(drink_string):
drinks = 0
if
else:
pass
returnI know its not much but I've been racking my brain for the past 2 hours now. I'm having trouble with substituting. At the moment my thought proces leads me to do %d as a placeholder for the amount of beers drank but that number is currently in a string and idk a good way to automate the program to extract numbers from a string, add the numbers up if there are more than one, and have the output of those numbers equal amount of glasses of water.
r/learningpython • u/[deleted] • Apr 06 '20
I hope I'm asking the right question. I'm currently on code wars trying to test my skills and ability on python so I can get better and apply them to real world issues. I'm currently trying to figure out how to find the smallest integer from a list.
Below is what is given, I am having troubles using the arr argument if that's the correct term for the word in the ().
def find_smallest_int(arr):
# Code here
test.assert_equals(find_smallest_int([78, 56, 232, 12, 11, 43]), 11)
test.assert_equals(find_smallest_int([78, 56, -2, 12, 8, -33]), -33)
test.assert_equals(find_smallest_int([0, 1-2**64, 2**64]), 1-2**64)Below is what I have coded so far. I opted to use the sort method and just print the first element in the array. It works for the first two lists but not the third since it does the math. My question is how can I use the definition in the code and how can I not make list 3 do the math and just spit out the numbers instead? Please no direct answer I really want to learn and try and solve it. Any link to any video helping with learning would be appreciated
def find_smallest_int(arr):
list1 = [78, 56, 232, 12, 11, 43]
list2 = [78, 56, -2, 12, 8, -33]
list3 = [0, 1 - 2 ** 64, 2 ** 64]
#sorting the list
list1.sort()
print('The smallest element in the first list is' , *list1[:1])
#sort list 2
list2.sort()
print('smallest element in the second list is' , *list2[:1])
#sort list3
list3.sort()
print('smallest element i the third list is ', *list3[:1])
find_smallest_int(arr)r/learningpython • u/Jhohn83 • Mar 21 '20
When I try to schedule a function that is async I get an error. that is how my code is written:
def Sheduling():
while True:
schedule.run_pending()
async def Asyncfunction():
#stuffs
ScheduleDaily= schedule.every().monday.do(Asyncfunction)
Thread = Thread(target=Sheduling, daemon=True)
Thread.start()What I can do? I get that error:
RuntimeWarning: coroutine 'Asyncfunction' was never awaited
self._run_job(job)
RuntimeWarning: Enable tracemalloc to get the object allocation tracebackCan you please help me? Thank you in advance.
r/learningpython • u/_Americuh_ • Mar 10 '20
My current issue is trying to run python3 in terminal. I went through with the sublime build for python3. Per chapter 7 where I'm directed to chapter 1, page 16 'Running Python Programs from a Terminal'. This is the instructional code:
~$ cd Desktop/python_work/
~/Desktop/python_work$ ls
hello.world.py
~/Desktop/python_work$ python hello_world.py
Hello Python world!It says to use python or python3 to run commands. Here's what I return:
>>> cd Desktop/python_work/
File "<stdin>", line 1
cd Desktop/python_work/
^
SyntaxError: invalid syntax
>>> I want to mention that my terminal changed to ZSH, not BASH. Does that matter? TIA.
r/learningpython • u/J-Rock0223 • Feb 03 '20
Hello Everyone,
I have been working on this code for the past couple days. I am fairly new at python. When I run the doctest for this code, I keep gettting the 'Got Nothing' error message. Any suggestions on how to fix it.
def add_beans(self, num):
"""
>>> add_beans(83, 15)
98
"""
self.beans = self.beans + num
r/learningpython • u/rommon010110 • Jan 28 '20
I am using Visual Studio Code, and wondering if there are any especially helpful extensions for newbies to download for Python to assist learning, or if using it basically "raw" from extensions is best?
I did install couple recommended extensions that plays the script within VSC, and another for indentation, however I'm wondering if there are any that people would recommend to assist with syntax or anything that might help the learning process?
Thanks!
r/learningpython • u/Quizlebeck • Nov 14 '19
So i'm begun to learn Python and part of my online course used from PIL import Image.
It keep failing due to no module named 'PIL'
I've been able to install Pillow used my command prompt but when I try to install it on Pycharm it will not work!
Does anybody have any work around at all? It's driving me insane and I cannot find a fix that works anywhere.
r/learningpython • u/[deleted] • Oct 23 '19
I'm trying to create a function that runs through a range of numbers and applies them all to a function as below.
y = np.linspace(0,5,100)
def parameter(y):
for i in y:
if y > 0.91:
return (-9.8*y) + 18.4
elif y < 0.91:
return (17.5*y) - 6.5
In running this, it tells me for line 3 (the opening line in the for loop) the error occurs as named in the title. I don't know where I'm going wrong and I've been at this trying to figure out how to fix this but with no luck.
r/learningpython • u/XoRDroopy • Jul 31 '19
So I have been trying to design a GUI recently. Something to help me learn to make different kinds of programs. I heard it is a decent place to start after learning absolute basics. So here I am with an issue:
All I want to do is make it so that when a checkbox is checked, turn a specific label's background to the color green. When it is unchecked, make it white.
So I can get this working easily but the issue is that I can only click it once and the label stays as if the button is checked even though I may have unchecked it.
This is what I use for that:
import tkinter as tk
w1 = tk.Tk()
def sdone2():
s2.configure(bg="green")
b2 = tk.Checkbutton(w1, text="Done", command=sdone2)
b2.place(x="1125", y="150")
s2 = tk.Label(w1,text="just some text.", fg="white", bg="black")
s2.place(x="250", y="150")
Now I tried to use IntVar() to aid me in this situation, I'm trying to research and learn as I go along with creating this GUI. So I stumbled upon many Indian men in many youtube videos all saying to do something like this:
intvar1 = tk.IntVar()
def sdone1():
s1.config(bg="green")
s1 = tk.Label(w1,text="Some More Text :D ", fg="white", bg="black")
b1 = tk.Checkbutton(w1, text="Done", variable=intvar1)
print(intvar1.get())
if intvar1.get() == 1:
s1.config(bg="green")
elif intvar1.get() == 0:
s1.config(fg="white", bg="black")
b1.place(x="1125", y="100")
This does work if you make a button that is meant to check for the condition of the checkbox but that isn't entirely what I want to do. I just kinda want it to update the label and have it check itself if that is possible. If there isn't a way in python (I doubt there isn't) then I guess I will just use a button to check for the status of the checkbox. I was thinking about a way to constantly check it. Like it checks and updates every half second but I couldn't really think of a way to do that. I'm aware that this isn't the cleanest looking code you have ever seen, but I've been messing with these lines for like 2 days at this point and am having a bit of a hard time so I haven't really been clean with my experimentation I guess you could say.
r/learningpython • u/TheOuterLinux • Jul 30 '19
Project file in question: https://theouterlinux.gitlab.io/website/Downloads/img2qb.py
Purpose: To help make it much easier to create sprites or small images for QB45, QBX, and QB64 projects
Uses: Python 2.7 or 3, ImageMagick, PIL, numpy, ptyprocess, six, and colorama
For a little while now, I've been working on a Python script called img2qb.py for both Python 2.7 and 3 that temporarily creates three color palettes based off of RGB values from three arrays (paletteCGA, palette16, and palette256) whose values are based off of QuickBasic's COLOR numbers from a QB script I made (https://theouterlinux.gitlab.io/website/Downloads/COLORHLP.BAS). Afterwards, img2qb.py converts an image to match said palettes based off of a chosen SCREEN mode. Then finally, img2qb.py creates a plain text file (filename.qbd) from which each pixel of the converted image that matched a palette's rgb value is replaced with the actual QuickBasic COLOR number values. When all is said and done, you basically get a DOS-friendly GIF (87a) file to either further edit or use with dinosaur or modern software and a plain text file to edit and use with QuickBasic, a two-for-one kind of deal. Unfortunately, only menu items relating to converting/outputing as monochrome, black and white, CGA, or 16-colors work; 256 (SCREEN 13 option) does not provide the correct output when it when the time comes to create filename.qbd.
However, my 256 palette (technically 245) will create and work on the preview image (I'm using ImageMagick for conversion) but does not output as it should when it comes time for PIL to convert the pixels to numbers to be placed in a text file (filename.qbd). Matter of fact, and perhaps one of the issues causing this, is the color order of the palette256.gif file is randomized. I don't want it this but without the lines (357 and 358):
palette256 = np.random.randint(low=0, high=entries256, size=(entries256 * 3), dtype=np.int)
palette256 = np.concatenate([palette256, np.zeros(entries256 * 3 - len(palette256))]).astype(np.int).tolist()...I get:
TypeError: integer argument expected, got floatYet, I don't need those lines for creating the 4 or 16 color palettes. So moving on, I can get an image to convert to a paletted GIF87 image but when it comes time to replace each of it's pixels with numbers on a plain text file and the palette256 is used, there are "DATA" at the beginning of each line (a default output option) but no numbers at all. The strange thing is I even used things like (in a for-loop; see line 861):
if r==range(0,16): r=0
if r==range(16,20): r=16
if r==range(20,28): r=20
if r==range(28,32): r=28
...so on and so forth until 255...to make absolutely sure that even if the palette used during the conversion didn't want to play nice, there's no way a number isn't going to match at some point. However, the ranges are not necessary for the 4 and 16 color palettes, only the 256 (technically 245). I'm just really confused as to why it isn't working and part of me thinks it may have something to do with the temporarily created palette256.gif file not using the rgb values I'm telling it to. I've tried quantizing with im.quantize(palette=palette256), but even it deviates from the actual unadulterated array version of palette256.
But to be honest, quite a bit of this script is based off of pure luck from many Internet searches, so any explainations or help need to be "exlpained like I'm five." I hope some of what I said makes sense. Best thing to do is try it and just see what I mean. All works as intended except when using the SCREEN 13 menu option. Also, I don't run Windows, so I have no idea if some of the code added to make if more cross-platform will actually work or not.
r/learningpython • u/Raymon1432 • Jul 30 '19
I'm trying to normalize a list of audio files in pydub and whenever I use file.dBFS, ffmpeg pops up. Is there any way to prevent ffmpeg from popping up?