Questions tagged [python]

Python is a multi-paradigm, dynamically typed, multipurpose programming language, designed to be quick (to learn, to use, and to understand), and to enforce a clean and uniform syntax. Two similar but incompatible versions of Python are commonly in use, Python 2.7 and 3.x. For version-specific Python questions, add the [python-2.7] or [python-3.x] tag. When using a Python variant or library (e.g. Jython, PyPy, Pandas, Numpy), please include it in the tags.

Filter by
Sorted by
Tagged with
0
votes
0answers
2 views

tf.function and tf.while loop in Tensorflow 2.0

I am trying to parallelize loop using tf.while_loop. As suggested here, the parallel_iterations argument doesn't make a difference in the eager mode. So I attempted to wrap tf.while_loop with tf....
0
votes
0answers
5 views

django middleware modify response message

I need to write a custom django middleware where i need to modify the response message from the view.Is it possible with process_response method of the middleware something like this class ...
-1
votes
1answer
11 views

Python program that implements “control break” logic

I need to create a python program that implements "control break" logic. We have the raw data for sales broken down by country Region. This is our input file: SalesRawData.txt North2010 North50 ...
1
vote
0answers
8 views

Django session deletion effects another django application

I have two applications running on the same server with different ports and with their SQLite DB's are also different which is used to store user sessions data. if request.session.exists(...
0
votes
0answers
6 views

bcp utility from IO and not actual file

Is it possible to use the bcp utility without actually passing a file but a memory buffer instead? Pandas can do a to_csv with StringIO but that buffer cannot be passed to the bcp using this library ...
-7
votes
0answers
26 views

It is a question related to file handling [closed]

count = 0 number = 0 myfile = open("text.txt", "r") for line in myfile: line = line.rstrip() line = line.split() if not count: number = len(line) count = count + 1 if ...
0
votes
1answer
9 views

How to remove repition of documents in mongodb using pycharm

I just coded a database for my project and when I open the database in MongoDB Compass it repeates the data every time the compass is loaded. [Compass showing repetition of data1
0
votes
0answers
21 views

Find all possible subsets to get a sum equal to a given number? [closed]

To find possible subsets that sum up to a given number, with contrains that you can not use number greater than a 'max' number. Sum =4, max=3 (1,1,2),(1,2,1),(2,1,1),(1,3),(3,1),(2,2), (1,1,1,1) are 7 ...
0
votes
1answer
11 views

Django: Problem with Adding Editing and Deleting Functionality in Django Form with TemplateView

I am learning Django by building an application, called TravelBuddies. It will allow travelers to plan their trip and keep associated travel items (such as bookings, tickets, copy of passport, ...
0
votes
0answers
18 views

How to eliminate overlapping lines in python?

I have a list containing a list of coordinates each representing a line in an SVG path. In some cases there will be smaller lines that fully overlap another one. For example: lines = [[1, 1, 2, 1], ...
0
votes
0answers
13 views

How to efficiently segment NumPy array by creating separate binary arrays

I'm trying to separate distinct objects in an image stored in the form of a NumPy array. For instance, if I have the 2D NumPy array: X = ([1.4E14, 1.4E14, 1.6E14], [1.4E14, 1.6E14, 1.6E14], [1.6E14, ...
0
votes
0answers
10 views

Python 3 Django 3.0 Running but not listening or opening port

I am using PyCharm and an instance running in AWS for remote debugging. When I start debugging the server starts and continues to run. However, it is inaccessable and doesn't appear to be grabbing ...
0
votes
0answers
13 views

Hitting 500 error on django with debug=False even with ALLOWED_HOSTS=[“*”]

I am getting 500 errors on every page I try to go with. The only thing that i'm changing is DEBUG to False. Here is my config: SECRET_KEY = os.environ.get("SECRET_KEY", "0$ke!x1bz5cj0mpzo1zfx4omw-...
0
votes
1answer
9 views

django, update modified_at when doing update()

Following field gets updated whenever model_obj.save() happens. modified_at = models.DateTimeField(auto_now=True, db_index=True) However, it is not updated when doing MyModel.objects.filter(id=...
0
votes
0answers
5 views

Tensorflow data validation serialization error

I am running tensorflow data validation v0.15 on python v3.5. I am trying to calculate the default set of statistics for anomaly detection pdf=spark.table("xxx").toPandas() # Small DF, fits into ...
-2
votes
0answers
12 views

Is Django REST framework suppose to be public?

I recently found some security holes in my university website. Among other issues was that, a page for viewing and managing api requests, using Django REST framework was found to be public. There were ...
0
votes
0answers
11 views

Matplotlib click events not working on multiple tkinter window

So I implemented this in the main window. And everything works fine. And whenever input_button is called a new window is created canvas = FigureCanvasTkAgg(f, self) f.canvas....
0
votes
0answers
16 views

Why column name with Many to Many relationship doesn't get retrieved? SQLAlchemy

I have the following model: class Actividad(Base): __tablename__ = "Actividad" codigo = Column(Integer, primary_key=True, unique=True) productos = relationship("Producto_Actividad") ...
0
votes
2answers
19 views

Python - Loop through User input number, calculate and output the entered values

I have been learning Python for nearly 6 weeks now and below is my first program. What I would like to get are user input for patient no, carb, protein and fat requirement. With the below code, I ...
0
votes
1answer
28 views

BeautifulSoup html.parser does not show all the source code

Firstly, I'd like to scrap the values off of this table on this URL: https://www.trademap.org/Product_SelCountry_MQ_TS.aspx?nvpm=1%7c076%7c%7c%7c%7cTOTAL%7c%7c%7c2%7c1%7c1%7c2%7c2%7c3%7c1%7c1%7c1 ...
0
votes
0answers
14 views

Can I set up PYTHONPATH for Lambda Function of Cloud9?

I created 2 Lambda Functions from AWS Resources menu in Cloud9. I wanna have common modules for these Functions. I made New Folder for the common modules and add the path ~/environment/python/lib to ...
-2
votes
1answer
25 views

Python — how many elements present in a list [closed]

st = 'Print every word in this sentence that has an even number of letters' x = [st.split()] len(x) Why is the output showing 1? It should be 13.
-2
votes
0answers
9 views

How to specify geometry in tkinter?

I am Trying to learn tkinter.when I used geometry method of tkinter,it shows an error: _tkinter.TclError: bad geometry specifier
-4
votes
0answers
13 views

CSRF verification failed only in production, Django [closed]

{% csrf_token %} is set. Tried @ensure_csrf_cookie as well. code: views.py: https://bpaste.net/show/UANTI template (landing.html): https://bpaste.net/show/P5YJA form_fields.html: https://bpaste....
0
votes
5answers
33 views

Replace only if “.” is the only value in a data frame column in python

I have a data frame that I am working with where missing values are specified with a dot (".") and I'm trying to replace the missing data with "Not_Given". However, some other columns have "." within ...
0
votes
0answers
5 views

Using Ansible to execute a bat file in windows machine

I have executed bat file in a windows machine using ansible by below command.It executes perfectly. I want to execute it in cmd where it command prompt keeps open. - hosts: windows1 tasks: ...
-2
votes
0answers
16 views

WinError 267 The directory name is invalid

I tried this code in jupyter notebook, and this error occured. Error : [WinError 267] The directory name is invalid: 'plantdisease/PlantVillage/Pepper__bell___Bacterial_spot/0022d6b7-d47c-4ee2-ae9a-...
0
votes
1answer
27 views

chessboard pieces won't display

Code: import tkinter, os from PIL import ImageTk, Image def sortFileImages(files): black = [i for i in files if 'black' in i] white = [i for i in files if 'white' in i] pawns = [[i]*7 ...
0
votes
1answer
10 views

Tensorflow tf.map_fn errors

a = tf.constant([[1, 2, 3, 1], [4, 5, 6, 1], [7, 8, 9, 1]]) mul = tf.constant([1, 3, 2]) result = [] for i in range(3): print(a[i], mul[i]) result.append(tf.tile(a[i], [mul[i]])) with tf....
-1
votes
0answers
7 views

Is there a way to cookie a “button disable” for each buttons with each unique ID? (Python, Flask, Web App) [closed]

Im doing a project for my school which is building a webpage using flask. I'm almost done with it. I have a page where it renders "motions(form data from users)" from my silly database. (yes, a.txt ...
0
votes
0answers
10 views

How to clear buffer of SScursor using pymysql?

I tried the following codes (from pymysql test code): https://github.com/PyMySQL/PyMySQL/blob/master/pymysql/tests/test_cursor.py def test_cleanup_rows_unbuffered(self): conn = self....
0
votes
2answers
32 views

How to make this function work more efficiently to count dominators?

I have to make a function where it would count the amount of dominators in a given list (number to the right of any number has to be smaller for it to be counted as a dominator.) For example, given ...
1
vote
1answer
16 views

Website works with half my webscraping code but other half gives an error message

I am new to web scraping and am having a hard time figuring out how to manage an issue: The website I am scraping is cooperating with half my code but now for the other half. I am scraping data from ...
-3
votes
0answers
15 views

How do I turn a table of a set of answers and the corresponding recommendations into a Python program? [closed]

I'm learning Python and I would like to develop a simple app. How do I turn this table—Recommendations of 3D printing materials (Link to table)—into a python program whereby there is a questionnaire ...
0
votes
1answer
18 views

How to create clusters/groups from knowing associations?

I have a dataframe that has 2 columns: [ID, ASSOCIATED_ID] For each ID, I have a list of other associated IDS from the dataframe. Here is a synthesized version of it: ID ASSOCIATED_ID 1 ...
-4
votes
1answer
28 views

Is there any function to fulfill the byte array to defined length with white spaces or anything else, which don't affect the exact data?

I am using the encryption technique, and the requirement for plain text's length is 384 bytes to be encrypted. My data is 220 bytes. Is there any function to fulfill this []byte with whitespaces or ...
1
vote
1answer
24 views

What is the most elegant way to go into a subdirectory, run a command, and come back out?

I have the following directory structure. data │   ├── 2019-12-11 │   └── 2019-12-12 │   ├── ADAZ19.json │   ├── BCHZ19.json I want to go in, run a tar command from os.system, and then go ...
2
votes
2answers
21 views

Write an txt file with fastq pair names with python

I'm new to python and want to improve it. Now I want to write a python script to organize my fastq file names into a txt file, like this: My files are like this: d1_S10_L001_R1_001.fastq ...
-1
votes
2answers
19 views

Taking a users input and saying it is part of a bigger category

Say for example that I have an Array of samples = { "Object": "chairs", "Stationary": "pencils", "Thing": "apples", } And I have a code saying print('Which stuff would you like?') ...
0
votes
0answers
8 views

How to make multithread socket on different vms

I want to implement multithreaded-server receives connection from multiple clients on different VMs. 3 VMs are in the same subnet. I would ask how to make it can connect to each other by configuring ...
0
votes
1answer
13 views

Matplotlib tables layout issue

I am trying to put a large table in an A4 report. pyplot.show() presents the layout such that the entire table is visible. However, pyplot.savefig() generates a pdf whereby the table is concealed by ...
-3
votes
2answers
42 views

What is the problem in this multiple inheritance?

class A: def __init__(self,name): self.name=name class B(A): def __init__(self,name,add): super().__init__(name) self.add = add class C(A): def __init__(self,...
2
votes
1answer
31 views

trying to remove list element with index found in another function

Using the function searchAccount I found the index of a list element that I searched for using the user's input. I want to use that same index to pop the element from the list. This should be super ...
0
votes
0answers
10 views

OpenCV : Add Alpha image to the original image to make a transparent image [duplicate]

I wan't to "fuse" the original image with a alpha channel to make a PNG. I have this two picture Original Picture Alpha Channel And I want to make this result. Result I tried to search about it, ...
-2
votes
0answers
12 views

How can I get simple text inputs from users online in Python? [closed]

suppose I'm a restaurant owner and want that my customers make them order opening a link and simply write what want. And this input be sending for my Python program that, for example, print it. There'...
1
vote
1answer
25 views

Python string to int/float [pandas/web scrapping with BeautifulSoup]

I have question that I could not find an answer on the web for this I have some Dataframe which I created from some web scrapping in my Dataframe there is a column with numbers the data there is of ...
-1
votes
0answers
16 views

How I can detect when the screen is being moved?

I have been trying how to detect when the window/screen moves in pygame. I saw that the libery 'os' may help, but I could only find how to move the screen with SDL_envars https://www.libsdl.org/...
-1
votes
2answers
30 views

Python list referencing same dictionary

I encountered behavior in Python that I didn't expect when appending a dictionary to a list. Specifically, I tried list_val=[] local_dict={} for val in ['a', 'b', 'c']: local_dict['first']=val ...
-1
votes
1answer
20 views

slicing 3 dimensional array in neural network python

In line X_train_1 = X_train[:,0:10081,:] in the model below, slicing seems to involve 3-dimensional data where the dataset is actually 921 x 10161. Can someone please explain how come we can do a 3-...
-1
votes
0answers
12 views

Raspberry pi cam V2 preview not showing [closed]

The raspberry pi cam is connected properly and I have been able to take and view pictures from it but when I try to see a preview from the camera with: from picamera import PiCamera from time import ...