Click here to Skip to main content
15,890,897 members
Everything / Programming Languages / Python

Python

Python

Great Reads

by Thomas Weller
Demonstrates how to run Python scripts from C#
by Clark Fieseln
Protect your privacy against malicious network activity and policy violations
by Akhil Mittal
Creating a real-time chatbot using Amazon Lex Services and deploying the bot over Facebook messenger
by Marc Clifton
My adventure with hardware and communicating between a BeagleBoneBlack and a C# app on Windows.

Latest Articles

by Azim Zahir
This article is a demonstration of some of the capabilities of the OpenCV library of Python.
by Oliver Li 2024
Java Code Change Impact Analysis
by Chris Maunder
Learn how to process a video file offline using CodeProject.AI Server
by Matthew Dennis
Create a ChatGPT-like AI module for CodeProject.AI Server that handles a long-running process.

All Articles

Sort by Title

Python 

19 Nov 2022 by Ιωάννα Χατζαντουριάν
hello, Im trying to run this github code : https://github.com/SamuelLiebana/4G3_Coursework_2/blob/master/code/question_1/exercise_4/hopfield_network_an_and_sim_rand_init.py import numpy as np import matplotlib.pyplot as plt import random from...
27 Oct 2023 by Member 16125293
i have the same question with u. Hope someone to give some help.
15 Aug 2022 by Prathmesh Upadhyay
-2 I am working with mongodb and python flask. Every time I run flask I receive this error on the local host and the terminal query = db.Data.find(upsert=True) AttributeError: 'NoneType' object has no attribute 'Data' What I have tried: ...
15 Aug 2022 by Richard MacCutchan
You need a method to get the database reference, the db variable does not exist in the functions you are using. See Welcome to Flask — Flask Documentation (2.1.x)[^] for details of how to do it correctly.
13 Aug 2020 by HamzaMcBob
Trying to hit log in after putting in email and password for https://app.libertex.com/[^] finally managed to tidy up the tiny bugs for inputting the email and password but it wont hit click If you want to test this stuff on the website your...
26 Mar 2022 by Shekhar fauzdar
"getVehicleCount()" • Get any property of any type of vehicle using a method named using the convention "getProperty()", e.g. getNickname() What I have tried: yes but nothing is work please help me bc bachalo bha kese bhi
11 Mar 2023 by Apoorva 2022
I have a function that divides the values of a numeric column into the specified number of bins/categories, based on the ranges they fall into. These categories are numbered from 0 to the limit specified. And the column values are replaced with...
11 Mar 2023 by Dave Kreskowiak
I don't do Python, but the error seems to be telling you that you're trying to iterate (for...) over something that is not a collection, but is a single object.
29 Apr 2023 by Member 8840306
I am new in using tensorflow keras using python.I am trying to run this statement in Jupter Notebook import matlab.engine It is givng this error ModuleNotFoundError: No module named 'matlab.engine'; 'matlab' is not a package For...
29 Apr 2023 by Richard MacCutchan
The relevant messages are: FileNotFoundError: [WinError 2] The system cannot find the file specified // and RuntimeError: MATLAB installation not found in Windows Registry: [WinError 2] The system cannot find the file specified And the...
11 Feb 2021 by kk009911
I had a problem for trying to analysis my dataframe: Here is the dataframe: x y z 1 2 0.886499 1 2 0.178829 2 2 0.954949 2 2 0.678957 1 1 0.112355 2 1 0.151515 I am trying to perform various calculation on z (I.e. calculate the mean, max...
11 Feb 2021 by Richard MacCutchan
You cannot use strings as logical expressions: o="df.loc[(df['x'])==1)" | (df['y']="=1)," 'z'].max() should be: o=df.loc[(df['x'])==1) | (df['y']==1), 'z'].max() I suggest you go to the numpy documentation to check the rules for these...
16 Feb 2024 by Apoorva666
I'm working on building a semantic search engine using 'Azure Cognitive Search'. I uploaded my Excel dataset programmatically using Python. To search & run the queries, each field/column in the Excel dataset can be associated with features like...
13 Feb 2024 by Wessel Beulink
You're facing an issue where only the 'retrievable' attribute can be selected for the fields in your Azure Cognitive Search index, while other attributes like 'searchable', 'sortable', 'filterable', and 'facetable' are disabled. This might be...
29 Apr 2021 by Member 15053137
I'm writing an app in Python that used Firestore/Firebase! I've got the database all set up. Now I've managed to add an account number into the database see below. Now each time the program runs it just writes over the already added account...
22 Nov 2022 by DosNecro
def removeDigits(str): return str.translate({ord(i): None for i in '0123456789'}) def fileinput(): with open('constant.txt') as f: lines = f.readlines() print('Initial string: ', lines) res = list(map(removeDigits,...
22 Nov 2022 by Richard Deeming
Your res variable is a list of strings. You can't convert a list to upper-case; you need to convert each string within the list to upper-case. You can do that using the map function[^] again.
19 Dec 2020 by SHIVAM SAH
from bs4 import BeautifulSoup import html5lib import requests tw_link = open("TW_Links.txt","r") im_link = open("IMG_Links.txt","w+") def get_images(urli): rs = requests.Session() urls=rs.get(urli) soup = BeautifulSoup(urls.text ,...
19 Dec 2020 by SHIVAM SAH
from bs4 import BeautifulSoup import html5lib import requests import time tw_link = open("TW_Links.txt","r", encoding = 'utf-8') im_link = open("DCDN_Links.txt","w+") kak_link = open("KCDN_Links.txt","w+") def get_images(urlset): for x in...
28 Aug 2022 by Apoorva 2022
Following is a date validation program. I'm trying to print the date in words. I got the 'str' object is not callable' error at this line --> av=date(day, month, year).strftime('%d %B %Y') But I did convert day, month, & year into integers...
28 Aug 2022 by OriginalGriff
Look at the error message: 'str' object is not callable' error at this line --> av=date(day, month, year).strftime('%d %B %Y') You are calling two functions here: date and strftime so one of those is wrong. Break the line in two and see if that...
28 Aug 2022 by Richard MacCutchan
I gave you the answer to this two days ago at Python date validation program - output query[^].
24 Jun 2021 by Sukesh Bera
Water_heat_capacity=4.186 Electricity_price=8.9 j_to_kwh=2.777e-7 mass=float(input("Enter the amount of water in millitliters:")) d_temp=float(input("Enter the temperature increase:")) q=mass*d_temp*Water_heat_capacity print("That will require %d...
24 Jun 2021 by OriginalGriff
IF you don't understand an error message, the first thing to do is google it: 'tuple' object is not callable - Google Search[^] The top hit explains why you get it: Python TypeError: ‘tuple’ object is not callable Solution | Career Karma[^] ...
24 Jun 2021 by Richard MacCutchan
I just ran that code and got the following results: Enter the amount of water in millitliters:1000 Enter the temperature increase:5 That will require 20930 joules of energy. That much energy will cost 0.05 cents.
3 Feb 2023 by j ton
I see this on web, I want to try myself but stock - .py (can get sql data and pass on index_test_0203.html) import mysql.connector import webbrowser import time import pymysql from flask import Flask,render_template,request app =...
2 Feb 2023 by Richard MacCutchan
I suggest you take a look at Welcome to Flask — Flask Documentation (2.2.x)[^], and work through the tutorial.
3 Feb 2023 by Burhanchaudhry
Yes I trieed this solution in CMD prompt and this is the answer that it gave me, it gave me this as a result not to sure but I tried to execute the code and it didn't properly work out. The code you provided would just give me a repeated error...
10 May 2018 by Member 13822063
Hey all, I'm a student and doing a practice for my exam. I will have to create a program that converts an input into binary. So far, I got the code working BUT I need my output to be in reverse order. I used [::-1] yet it doesn't seem to be doing it. Thanks! What I have tried: def...
10 May 2018 by Thomas Daniels
output is always just a one-letter string (because it's inside the loop), so reversing it just gives the same string. What you need to do, is reversing the whole string before printing it: def binary_converter(num): reverse = "" while num != 0: output = num % 2 # 0 or 1 ...
2 Oct 2021 by eboolean
def asallar(limit): limitn = limit+1 asal_degil = [False] * limitn asal_listesi = [] for i in range(2, limitn): if asal_degil[i]: continue for f in xrange(i*2, limitn, i): asal_degil[f] = True ...
23 Apr 2015 by BacchusBeale
For C, something like in the comments:def asallar(limit): \\ void asallar(int limit, int* asal_listesi){ limitn = limit+1 \\ int limitn =limit+1; asal_degil = [False] * limitn \\ int *asal_degil = malloc(...) asal_listesi = [] \\ vector asal_listesi; for i in range(2,...
10 Dec 2018 by CPallini
#include using namespace std; vector asallar(size_t limit) { vector nov(limit+1, false); vector result; for (size_t i=2; i
20 May 2016 by CHill60
This was answered on your previous post **Not sure what programming language should I choose? **[^] and you accepted the answer!As I said there - use the reviews from Amazon to judge what people think of the books available.I also gave you a list of free websites to choose from and...
19 May 2016 by ZcrossGames
Guys!!!I really need your answers...So i tried a lot in c and c++ But i had to advantage of those thing.then i found Java And Python...Those are fine but now i am having problem to choose from them .......so i made my mind and choose Python.but i can't find any good sites to learn free....And...
19 May 2016 by CHill60
As phil.o says this post "will more likely attract personal opinions rather than verified facts""Good" is a subjective word, so you will have to decide which sites are good for you from this list[^]As for books, I would use the User Feedback on a site such as Amazon.com: Books[^] to...
16 Mar 2023 by abdullah habib
- Use iterative deepening search increment 2. - How much solutions you can found? What is solution depth? What I have tried: please solve thes Question now
16 Mar 2023 by OriginalGriff
Two things: 1) There is nowhere near enough information there to even begin giving you a sensible, useful answer - we have no idea what you are trying to do, or where you are starting from. We don't even have any idea where you are stuck, or...
20 Aug 2015 by CHill60
See the solutions posted on your earlier post Python Syntax Error with correct code[^]There is no shortcut for actually learning the language and the IDE
20 Aug 2015 by Sergey Alexandrovich Kryukov
The code line is correct and will work. This line should not be ">>> print("game over")", it can be "print("game over") You can enter this line in a file and save it in your file. Then the "syntax" will bepython gameover.pyOf course, you need to have working directory the same as the one...
29 May 2013 by _frog_
Hello! I am beginner in Python programming and I want to make an application (GUI) in Python 2.6 + wxPython for process data stored in .mat files . (I make such data processing in MatLAB.) My application consists in:-selecting the path of the files process and the file i want to...
7 Aug 2014 by Jerry.Wang
Modify methods' IL codes on runtime even if they have been JIT-compiled, supports release mode / x64 & x86, and variants of .NET versions, from 2.0 to 4.5.
23 Jun 2010 by ignaciordc
How can I use a .NET DLL from Python?How can I access a .NET DLL from a C program (not .NET)?If I get an anwer to the second question, I will answer the first myself.Working in Python, I use several DLL writen in C or C++, thanks to wrappers that can be easily written with...
23 Jun 2010 by William Winner
Did you try a simple google search? Try here: http://tinyurl.com/2bdrjby[^]I would start there.
5 Dec 2021 by OriginalGriff
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for...
5 Dec 2021 by Dave Kreskowiak
Forgot the language and the rest of the app. You have a rather large problem just defining what this app is supposed to do. You MUST define what you mean by "anonymous activity", and in what context that definition has meaning. Is it disk...
25 Jul 2017 by Member 13328753
response = { "instances": [ { "id": "i-123456789abcdef10", "name": "instance1", "type": "t2.micro", "ami_id": "ami-ea45f78a", }, { "id": "i-111213141516171819", "name": "instance2", ...
25 Jul 2017 by David_Wimbley
I'm not python expert and your code isn't very clear so I am assuming set([i[ami_id]for i in response["instances"]]) is the call that is causing the error. I think you need to change i[ami_id] to i[self.ami_id] in order for you to access instance members.
25 Jul 2017 by Haranadh gupta
ami_id is not a declared variable, and it is a key in your dictionary, you just need to put it into double quotes. and then execute. For example you would try with: data = set([i["ami_id"]for i in response["instances"]])
25 Jul 2017 by Richard MacCutchan
Your set comprehension needs a quoted string for ami_id thus: set([i["ami_id"]for i in response["instances"]])
6 Jan 2021 by KarstenK
First you must know which language and tools you are allowed. I guess that you DONT have tried a lot. Cure your dumbness with learning like from some tutorials like Learn C++ or some Youtube videos. No one will give you homeworks for free. It...
6 Jan 2021 by OriginalGriff
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us...
5 May 2015 by Tomasz Naumowicz
Take a closer look at scenarios where working with GUID and UUID in a MongoDB environment becomes tricky. We will make you aware of those configurations and provide a set of best practices to follow.
10 Jul 2021 by johnathan indigo
public class AddressBook { private String[] firstNames = new String[1000]; int firstNameCount = 0; private String [] lastNames = new String[1000]; int lastNameCount = 0; private String[] addresses = new String[1000]; int...
10 Jul 2021 by OriginalGriff
Well, it's not C. Or Python. Or Javascript. And that's three already ... After that ... it looks like student grade code - which isn't a compliment; it uses magic numbers that aren't explained; it's never head of the modulus operator; the method...
10 Jul 2021 by KarstenK
In my mind the worst problem is, that you want to cheat by letting other help you to solve your homework. Bad is ofcourse the use of the "magic numbers" 2 and 1000 and no check for the file input. I personally hate to name a string "bit".
16 Mar 2021 by Richard MacCutchan
See The Python Tutorial — Python 3.7.10 documentation[^]
16 Mar 2021 by Patrice T
Quote: 3. Ask the user for 2 integer numbers then print the numbers So your main effort is paste your homework, you do not claim any problem, you do not have stated a single word. Your question is: Do my homework, urgently. How rude of you. The...
16 Nov 2015 by Sergey Alexandrovich Kryukov
Please see:http://code.activestate.com/recipes/483730-port-forwarding[^],http://voorloopnul.com/blog/a-python-proxy-in-less-than-100-lines-of-code[^],see also: http://stackoverflow.com/questions/1874331/python-port-forwarding-multiplexing-server[^].—SA
17 May 2016 by Member 12523929
1. The C expression 10 / 3 has a value of ________. 3.333333 3 1 3.000000 2. If the initial value of num2 is 10, then value of num1 and num2 respectively will be ________ after the expression num1 = num2++; . 10 and 10 11 and 10 ...
17 May 2016 by Dave Kreskowiak
And is there some particular reason you're trying to get other people to do your homework for you? Read: Never going to happen.For all we know, you just highlighted random answers in the hope that someone naive is going to correct you, giving you all the answers.
3 Jul 2019 by Cloudster
Deploy a 360 image gallery with Django, Bootstrap, Python, A-Frame, and PostgreSQL
9 Nov 2020 by OriginalGriff
Please don't repost if your question does not appear immediately: both of these went to moderation and required a human being to review them for publication. In order to prevent you being kicked off as a spammer, both had to be accepted, and then...
7 Jul 2020 by OriginalGriff
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here... A very quick search gave nearly 3 million hits: usb modem python - Google Search[^] Start reading there, and begin to get...
12 Feb 2019 by D4rkTrick
Code for a 4-bit encoder to store 15 different symbols with higher efficiency
20 Oct 2020 by samar lulu
I'm not sure if the answer is true. I need help What I have tried: #exe4 x = input("enter the number of seconds") a = float(x) miunte = a // 60 sec = a % 60 print(x, "returned to", miunte, "minutes","and", sec, "second")
20 Oct 2020 by Patrice T
Quote: I'm not sure if the answer is true. I need help Obviously, you know that 1 minute is 60 seconds. What input gives result which makes you doubt of this code ? Test your code by running it with inputs you know the result and see if it...
7 Aug 2018 by Leonid Fofanov
Raspberry PI implementation of binary counter originally developed for Arduino board.
9 Jun 2012 by Ghazanfar_Ali
Implementation of A* algorithm using Python and PyGame for solving an 8-Puzzle automatically.
19 Nov 2022 by Tomas Sanchez Garcia
Hello, I have a problem that I do not understand. Everything works fine but sometimes the application crashes and closes (tkinter window) when clicking on the checkbuttom What should it be? It does not throw any code error or anything, it just...
19 Nov 2022 by Richard MacCutchan
The only clue you have is the line: [Finished in 7.7s with exit code -5] So you need to find out where that exit code is coming from, and what it means.
31 Aug 2020 by Kil'Shin LQM
Below is the code puppeteer. I want to switch to pyppeteer. Is there any way? Thanks! counter = 0; page.on('response', async (response) => { const matches = /.*\.(jpg|png|svg|gif|webp)$/.exec(response.url()); if (matches &&...
31 Aug 2020 by OriginalGriff
This is not a code conversion service: we are not here to translate code for you. Even if we did, what you would end up with would not be “good code” in the target language – they are based on very different frameworks, and what makes something...
31 Aug 2020 by Richard MacCutchan
See pyppeteer · PyPI[^]
10 Nov 2013 by OriginalGriff
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.Try it yourself, you may find it...
16 Jun 2016 by baotdinh
Hi,I want to skim data from some websites. But with my code, i can get it correctly at 1st time. But when i run again, it still generates body data with 200 code. But the data does not look like as the 1st time i got. I think maybe they block connection. How can i solve it ?What I have...
20 May 2016 by Member 12535948
Hi! I am creating a game using pygame. Please do note that I am new to game development and programming. I'm using Tiled to create a tile map for my game. However, this error occurs when I try to run my program with pygame:Traceback (most recent call last):File "C:\Users\Rose\Desktop\mp2...
20 May 2016 by Richard MacCutchan
See binascii.Error: Incorrect padding - Google Search[^].
23 Dec 2020 by Vlad Țepeș ツ
Hey, I'm trying to learn python and I have a problem. from tkinter import * from PIL import ImageTk, ImageTk root = Tk() root.title("Learn to Code at Codemy") root.iconbitmap("C:/Py Python/gui/forpyt/favicon.ico") my_img =...
23 Dec 2020 by Richard MacCutchan
For basic syntax errors you should always check the documentation first: ImageTk Module — Pillow (PIL Fork) 8.0.1 documentation[^]
23 Dec 2020 by CHill60
Shouldn't my_img = ImageTk.PhotoImage(Image.open("C:/Users/Vlad/Desktop/python/pytt.png")) be my_img = ImageTk.PhotoImage(file="C:/Users/Vlad/Desktop/python/pytt.png") see Basics For Displaying Image In Tkinter Python[^]
8 Jun 2020 by zarovsky
I have a for loop that in each iteration goes through a list of url and grabs the tag of each one and then writes it to a file. here is the code: #!/usr/bin/env python import os import requests from bs4 import BeautifulSoup import time,...
7 Jun 2020 by OriginalGriff
You need to be aware that threading is not a "magic bullet" that will solve all your performance woes at a stroke - it needs to be carefully thought about and planned, or it can do two things: 1) Slow your machine to a crawl, and make your...
2 Mar 2017 by xXxRevolutionxXx
hey ! I am using python 2.7, and i want to open through my python script another executable in a subprocess. I am specifically using subprocess.Popen method. Now, what i want is to open this program in a subprocess... but also pass arguments to it. Is there a way ?? ThanksWhat I have...
2 Mar 2017 by Richard MacCutchan
17.1. subprocess — Subprocess management — Python 2.7.13 documentation[^].
27 Apr 2017 by Yaseen M
Solution: I changed the comparison to: if int(guess[i]) == number[i]: Full Program: import random def generateNumbers(): numbers = []; i = 0 while i
27 Apr 2017 by OriginalGriff
guess is not an [] - so it can;t be used with a subscript index. Try: if guess == number[i]:
27 Apr 2017 by Patrice T
Quote: That would defeat the purpose of the original code. Do the correction of solution 1, and use the debugger to see what your code is doing. Somewhere, your code is not doing what you expect. When you don't understand what your code is doing or why it does what it does, the answer is...
18 Mar 2021 by lukeer
Hi forum, there is a python program using flask and socket.io to create a web server which runs on my development machine. On the same machine, I can access the server and get the website it serves by typing localhost:5000 in the address field...
18 Mar 2021 by lukeer
In an attempt to find out how other web servers on the same machine would be treated, I started$ winpty python -m http.server 5000 (Found that somwhere in the internet). That triggered the firewall to tell that it had just blocked python.exe and...
12 Sep 2017 by The Zakies
Question answer chatbot using natural language parsing and web scrapping
25 Feb 2013 by Creepystranger
hi all curretly in my project everyday I need to open a particular URL(which is kind of like app view in Control-m) and search for some jobs and send its status in a mail and believe me its very boring and i want to automate it.although m not very versed with scripting in perl and python i...
30 Apr 2018 by Dominic Abraham
This article is to give you a basic introduction to Python programming language with small examples. It will help to start with your first Python program.
15 Oct 2018 by Member 13508014
L=[1,2,3,4,5] print L[4:1] #prints an empty list. Can not traverse in reverse direction. How does L[::-1] can traverse in reverse direction? What I have tried: Trying to understand list traversal in python by different indices/slicing.
16 Oct 2018 by Richard MacCutchan
See 3. An Informal Introduction to Python — Lists[^]. [edit] The missing start and stop values indicate that it should use the entire list. Setting a step value of -1 causes the values to be reversed, so it treats it as list[end:start:step] However, this only works for types that have a...