qid
int64
46k
74.7M
question
stringlengths
54
37.8k
date
stringlengths
10
10
metadata
listlengths
3
3
response_j
stringlengths
17
26k
response_k
stringlengths
26
26k
38,043,683
I'm writing a git pre-commit hook, but it requires user input and hooks don't run in an interactive terminal. With Python I could do something like this to get access to user input: ``` #!/usr/bin/python import sys # This is required because git hooks are run in non-interactive # mode. You aren't technically suppose...
2016/06/26
[ "https://Stackoverflow.com/questions/38043683", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13973/" ]
by combining @julian-portalier's answer and @asterite's we have working way to redefine stdin: ``` STDIN.reopen(File.open("/dev/tty", "a+")) ``` Which, I believe, is just [FileDescriptor#reopen](http://crystal-lang.org/api/IO/FileDescriptor.html#reopen) `STDIN`, `STDOUT`, and `STDERR` can all be reopened this way.
You may try: ``` STDIN.reopen("/dev/tty") ```
50,982,990
I'm designing an Application where username will be an `AutoIntegerField` and unique. Here's my model. ``` class ModelA(models.Model): username = models.BigAutoField(primary_key=True, db_index=False) user_id = models.UUIDField(default=uuid.uuid4, unique=True, editable=False) ``...
2018/06/22
[ "https://Stackoverflow.com/questions/50982990", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1162512/" ]
I think the issue is that you still have an old index on your `username` field that clashes with the new type. The `db_index=False` argument has no effect because `primary_key=True` always generates an index. You might be able to solve this by removing `primary_key=True`, creating a migration, and then re-adding it an...
in my case I was connecting django to postgres at localhost pgadmin first deleted all the migrations except default one and also in the pycache then just run python manage.py makemigrations and python manage.py migrate in your terminal
716,386
I was trying to hack up a tool to visualize shaders for my game and I figured I would try using python and cocoa. I have ran into a brick wall of sorts though. Maybe its my somewhat poor understand of objective c but I can not seem to get this code for a view I was trying to write working: ``` from objc import YES, NO...
2009/04/04
[ "https://Stackoverflow.com/questions/716386", "https://Stackoverflow.com", "https://Stackoverflow.com/users/84805/" ]
Depending on what's happening elsewhere in your app, your instance might actually be getting copied. In this case, implement the `copyWithZone` method to ensure that the new copy gets the renderer as well. (Caveat, while I am a Python developer, and an Objective-C cocoa developer, I haven't used PyObjC myself, so I c...
Even if they weren't serialized, the \_\_init\_\_-constructor of python isn't supported by the ObjectiveC-bridge. So one needs to overload e.g. initWithFrame: for self-created Views.
23,894,545
I would like to use ArangoDB in Django, but I don't know which of the following options is better: using the [ArangoDB Python driver](http://blog.klymyshyn.com/2013/02/arangodb-driver-for-python.html) or building a new API with Foxx. I think that the ArangoDB Python driver is not based on Foxx and I don't know the pros...
2014/05/27
[ "https://Stackoverflow.com/questions/23894545", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1960092/" ]
Better option for your case is to use ArangoDB Python driver. Here is couple of reasons: * easy-to-start - just install driver and move on with development * some similarity to Django ORM API * have some documentation * all your business logic will be in place and in Python which should be great advantage And here i...
I made a python ArangoDB driver (<https://github.com/saeschdivara/ArangoPy>) and I created on top of that kind of a bridge for Django (<https://github.com/saeschdivara/ArangoDjango>). So you can use kind of an orm for ArangoDB and still use the Django Restframework to create your API.
4,205,697
My goal is to use to make it easy for non-programmers to execute a Python script with fairly complex options, on a single local machine that I have access to. I'd like to use the browser (specifically Safari on OS X) as a poor man's GUI. A short script would process the form data and then send it on to the main program...
2010/11/17
[ "https://Stackoverflow.com/questions/4205697", "https://Stackoverflow.com", "https://Stackoverflow.com/users/215679/" ]
Use an [AOP framework](http://www.postsharp.com) for this, to inject code when a certain method is hit. You can also do this native via the .NET framework with a [ContextBoundObject](http://msdn.microsoft.com/en-us/library/system.contextboundobject.aspx); which is probably what they've used in the framework.
You are thinking about this wrong. It's not that the attribute has a changing value, it's that its interpretation by the code that uses the attribute is based on runtime state. In the example you gave, it is probably the case that the code which checks for that attribute also does the checking of Thread.CurrentPrincipl...
4,205,697
My goal is to use to make it easy for non-programmers to execute a Python script with fairly complex options, on a single local machine that I have access to. I'd like to use the browser (specifically Safari on OS X) as a poor man's GUI. A short script would process the form data and then send it on to the main program...
2010/11/17
[ "https://Stackoverflow.com/questions/4205697", "https://Stackoverflow.com", "https://Stackoverflow.com/users/215679/" ]
Your understanding of .NET attributes seems to be a little muddy. Attributes are a way of attaching meta-information to classes and assemblies for the purposes of reflection. **Attributes typically do not contain behaviour. They are just data.** What you're seeing with `PrincipalPermissionAttribute` is the .NET Runt...
You are thinking about this wrong. It's not that the attribute has a changing value, it's that its interpretation by the code that uses the attribute is based on runtime state. In the example you gave, it is probably the case that the code which checks for that attribute also does the checking of Thread.CurrentPrincipl...
62,528,247
I've updated the initial script with a modified version of Bryan-Oakley's [answer](https://stackoverflow.com/a/6789351/10364425). It now has 2 canvas, 1 with the draggable rectangle, and 1 with the plot. I would like the rectangle to be dragged along the x-axis on the plot if that is possible? ``` import tkinter as tk...
2020/06/23
[ "https://Stackoverflow.com/questions/62528247", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13796693/" ]
The issue with your code is that you create two canvases, one for the matplotlib figure and one for the draggable rectangle while you want both on the same. To solve this, I merged the current code of the question with the one before the edit, so the whole matplotlib figure is now embedded in the Tkinter window. The k...
I'm not sure how to do it with tkinter or pyQt but I know how to make something like this with PyGame which is another GUI solution for python. I hope this example helps you: ``` import pygame SCREEN_WIDTH = 430 SCREEN_HEIGHT = 410 WHITE = (255, 255, 255) RED = (255, 0, 0) FPS = 30 pygame.init() screen = py...
29,826,430
I want to extract a variable named `value` that is set in a second, arbitrarily chosen, python script. The process works when do it manually in pyhton's interactive mode, but when I run the main script from the command line, `value` is not imported. The main script's input arguments are already successfully forwarded...
2015/04/23
[ "https://Stackoverflow.com/questions/29826430", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1809463/" ]
In my case I am using Handlebars for mandrill templates and I have solved this by sending HTML to the template `<br/>` instead of `\n` by replacing `\n` in my string with `<br/>` something like: `.Description.Replace("\n", "<br/>");` And then on the mandrill template I put the variable inside {{{ variable }}} instead ...
If you want to send more complex content, be it html, or variables with break lines and whatnot, you can first render the template and then send the message, instead of directly using `send-template`. Render the template with a call to [`templates.render`](https://mandrillapp.com/api/docs/templates.JSON.html#method=re...
57,561,119
Using python 3, I'm trying to append a sheet from an existing excel file to another excel file. I have conditional formats in this excel file so I can't just use pandas. ``` from openpyxl import load_workbook final_wb = load_workbook("my_final_workbook_with_lots_of_sheets.xlsx") new_wb = load_workbook("workbook_wit...
2019/08/19
[ "https://Stackoverflow.com/questions/57561119", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11193105/" ]
So another approach, without color ranges. A couple of things are not going right in your code I think. First, you are drawing the contours on `thresh_binary`, but that already has the outer lines of the other cells as well - the lines you are trying to get rid off. I think that is why you use `opening`(?) while in th...
Actually, in your code the 'box' is a legitimate extra contour. And you draw all contours on the final image, so that includes the 'box'. This could cause issues if any of the other colored cells are fully in the image. A better approach is to separate out the color you want. The code below creates a binary mask that ...
27,829,575
I have a python script that calls a system program and reads the output from a file `out.txt`, acts on that output, and loops. However, it doesn't work, and a close investigation showed that the python script just opens `out.txt` once and then keeps on reading from that old copy. How can I make the python script reread...
2015/01/07
[ "https://Stackoverflow.com/questions/27829575", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3154996/" ]
You need to flush `foo` so that the external program can see its latest changes. When you write to a file, the data is buffered in the local process and sent to the system in larger blocks. This is done because updating the system file is relatively expensive. In your case, you need to force a flush of the data so that...
You take your file\_var and end the loop with file\_var.close(). ``` for ... : ga_file = open(out.txt, 'r') ... do stuff ga_file.close() ``` Demo of an implementation below (as simple as possible, this is all of the Jython code needed)... ``` __author__ = '' import time var = 'false' while var == 'fals...
27,829,575
I have a python script that calls a system program and reads the output from a file `out.txt`, acts on that output, and loops. However, it doesn't work, and a close investigation showed that the python script just opens `out.txt` once and then keeps on reading from that old copy. How can I make the python script reread...
2015/01/07
[ "https://Stackoverflow.com/questions/27829575", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3154996/" ]
I rewrote it to hopefully be a bit easier to understand: ``` import os from shutil import copyfile import subprocess import sys TEMP_CNF = "tmp.in" TEMP_SOL = "tmp.out" NULL = open(os.devnull, "wb") def all_solutions(cnf_fname): """ Given a file containing a set of constraints, generate all possible solu...
You take your file\_var and end the loop with file\_var.close(). ``` for ... : ga_file = open(out.txt, 'r') ... do stuff ga_file.close() ``` Demo of an implementation below (as simple as possible, this is all of the Jython code needed)... ``` __author__ = '' import time var = 'false' while var == 'fals...
27,829,575
I have a python script that calls a system program and reads the output from a file `out.txt`, acts on that output, and loops. However, it doesn't work, and a close investigation showed that the python script just opens `out.txt` once and then keeps on reading from that old copy. How can I make the python script reread...
2015/01/07
[ "https://Stackoverflow.com/questions/27829575", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3154996/" ]
You need to flush `foo` so that the external program can see its latest changes. When you write to a file, the data is buffered in the local process and sent to the system in larger blocks. This is done because updating the system file is relatively expensive. In your case, you need to force a flush of the data so that...
I rewrote it to hopefully be a bit easier to understand: ``` import os from shutil import copyfile import subprocess import sys TEMP_CNF = "tmp.in" TEMP_SOL = "tmp.out" NULL = open(os.devnull, "wb") def all_solutions(cnf_fname): """ Given a file containing a set of constraints, generate all possible solu...
74,448,363
I am trying to find out if a hex color is "blue". This might be a very subjective thing when comparing different (lighter/ darker) shades of blue or close to blue colors but in my case it does not have to be very precise. I just want to determine if a color is blue or not. The more generalized question would be, is th...
2022/11/15
[ "https://Stackoverflow.com/questions/74448363", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4644897/" ]
This is a somewhat complicated question, see more discussion here: <https://graphicdesign.stackexchange.com/questions/92984/how-can-i-tell-basic-color-a-hex-code-is-closest-to> I don't know of any library or implementation that already exists for this. If you really need this functionality though and don't need it to ...
I mean you could do: ``` hex = input() if hex == '#0000FF': print('Blue') else: print('Not blue') ``` If that is what you are looking for.
64,532,869
I'm very new to java but i have decent experience with c++ and python. So, I'm doing a question in which im required to implement an airplane booking system, which does the following - 1.initialize all seats to not occupied(false) 2.ask for input(eco or first class) 3.check if seat is not occupied 4.if seat is not ...
2020/10/26
[ "https://Stackoverflow.com/questions/64532869", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7617688/" ]
As Java calls methods by value, Your problem about static is you are passing the value of `current_seat` to the `book_seat` method, so changing the value doesn't affect that variable after returning from the method. To solve it just call the method and do not pass your static vars. It's static, so you have access it ...
1. Checking Inout stream Not sure wether your question is related to "static" variables or more related to "How to handle Input Stream?". Regarding: > > if I press 1 it should book in first class but the program does not await for my input and proceeds to else statement instead. > > > You should think about "fl...
64,532,869
I'm very new to java but i have decent experience with c++ and python. So, I'm doing a question in which im required to implement an airplane booking system, which does the following - 1.initialize all seats to not occupied(false) 2.ask for input(eco or first class) 3.check if seat is not occupied 4.if seat is not ...
2020/10/26
[ "https://Stackoverflow.com/questions/64532869", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7617688/" ]
As Java calls methods by value, Your problem about static is you are passing the value of `current_seat` to the `book_seat` method, so changing the value doesn't affect that variable after returning from the method. To solve it just call the method and do not pass your static vars. It's static, so you have access it ...
you don't need to insist incrementing the exact variable, just do the following : 1. make `book_seat()` to return incremented value ```java public static int book_seat(boolean [] seats, int current_seat) { seats[current_seat] = true; System.out.println(current_seat + 1); return current_sea...
2,284,666
I've been able to do this through the django environment shell, but hasn't worked on my actual site. Here is my model: ``` class ShoeReview(models.Model): def __unicode__(self): return self.title title = models.CharField(max_length=200) slug = models.SlugField(unique=True) ...
2010/02/17
[ "https://Stackoverflow.com/questions/2284666", "https://Stackoverflow.com", "https://Stackoverflow.com/users/200916/" ]
``` ariake = Shoe.objects.get(pk=1) # get the OwnerReviews ariake.ownerreview_set.all() # or the ShoeReviews akiake.shoereview_set.all() ``` Or if you really want to use the OwnerReview class directly ``` OwnerReview.objects.filter(shoe=ariaki) ``` A question for you. Did you mean to use OnoToOneField(Shoe) and n...
The reason why you're getting an empty QuerySet is because on your ShoeReview model, your filter argument is wrong: > > `owner_reviews = OwnerReview.objects.filter(Shoe__name=Shoe)` > > > Change to this: > > `owner_reviews = OwnerReview.objects.filter(Shoe=Shoe) #without __name` > or you can do like this also:...
37,209,213
I am working on a project with some friends and we're facing a bit of a problem with our implementation of `picamera`. We're trying to import `cv2` and `picamera` at the start of the program (working with Python 3) and so far importing `cv2` works just fine. When we're trying to import picamera it tells us this: `Impo...
2016/05/13
[ "https://Stackoverflow.com/questions/37209213", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6140273/" ]
I know this was posted a while ago, but for those who are experiencing the same issue, try this: ``` pip install "picamera[array]" ``` According to [piimagesearch.com](http://www.pyimagesearch.com/2015/03/30/accessing-the-raspberry-pi-camera-with-opencv-and-python/ "pyimagesearch.com") it's necessary to install the ...
This should might help ``` sudo pip3 install picamera ``` I ran this on my desktop and something installed so it should work if pip isn't installed you may have to run ``` sudo apt-get install python3-pip ``` sources: [How to install pip with Python 3?](https://stackoverflow.com/questions/6587507/how-to-instal...
57,524,198
You won´t be able to run the script, sadly I don´t know why. It's about EOL but I'm not that much into python so I need your help, I´ve tried different stuff and didn't work. Also, my friend that actually is into phyton tried and failed. this is just a menu code for running multiple antiviruses whenever I want to chec...
2019/08/16
[ "https://Stackoverflow.com/questions/57524198", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11935868/" ]
You are using backslash characters '\' in your paths. While this is OK on the command line, it is (mostly) not correct in source code. The backslash character is used as escape character to change the meaning of the following character. In your case the trailing apostroph is escaped so that the path string is not close...
You are missing a single quote at the end of the line: ``` if choice == "1": print("Checking Files ... (The process wont take long !") os.chdir 'C:\Users\alexa\Desktop\Core_Files\Projects\S1mpl3 Antivirus\Check\Files\File_Check.vbs\ **<---here** menu() ```
57,524,198
You won´t be able to run the script, sadly I don´t know why. It's about EOL but I'm not that much into python so I need your help, I´ve tried different stuff and didn't work. Also, my friend that actually is into phyton tried and failed. this is just a menu code for running multiple antiviruses whenever I want to chec...
2019/08/16
[ "https://Stackoverflow.com/questions/57524198", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11935868/" ]
You are using backslash characters '\' in your paths. While this is OK on the command line, it is (mostly) not correct in source code. The backslash character is used as escape character to change the meaning of the following character. In your case the trailing apostroph is escaped so that the path string is not close...
I have a similar problem while opening a directory. I used raw string and double backslashes and it works. Example: ```py os.chdir(r"C:\\Users\\alexa\Desktop\\Core_Files\\Projects\\S1mpl3Antivirus\\Check\\Files\\") ```
65,273,118
I am new to deep learning and I have been trying to install tensorflow-gpu version in my pc in vain for the last 2 days. I avoided installing CUDA and cuDNN drivers since several forums online don't recommend it due to numerous compatibility issues. Since I was already using the conda distribution of python before, I w...
2020/12/13
[ "https://Stackoverflow.com/questions/65273118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14372142/" ]
I see that your GPU has **[compute capability 5.0](https://developer.nvidia.com/cuda-gpus)** which is OK, TensorFlow should like it. Thus I assume something went wrong during the environment setup. Please try creating a new environment using: ``` conda create --name tf_gpu tensorflow-gpu ``` Then install all other ...
Using `conda` to install TensorFlow is always a better way to manage the multi versions of TensorFlow itself as well as CUDA and CUDNN. I recently create a new conda environment and prepare to install the newest TensorFlow too. I also encountered the issue you mentioned. I checked the dependency list from `conda instal...
65,273,118
I am new to deep learning and I have been trying to install tensorflow-gpu version in my pc in vain for the last 2 days. I avoided installing CUDA and cuDNN drivers since several forums online don't recommend it due to numerous compatibility issues. Since I was already using the conda distribution of python before, I w...
2020/12/13
[ "https://Stackoverflow.com/questions/65273118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14372142/" ]
I see that your GPU has **[compute capability 5.0](https://developer.nvidia.com/cuda-gpus)** which is OK, TensorFlow should like it. Thus I assume something went wrong during the environment setup. Please try creating a new environment using: ``` conda create --name tf_gpu tensorflow-gpu ``` Then install all other ...
As of August 2021, with TensorFlow 2.4.1, I believe it seems to install CUDA and CuDNN in a conda environment. Here's what I did to create a fresh conda env on an Ubuntu 18.04 machine: ``` conda create --name tftest python=3.7 -y && conda activate tftest conda install ipython tensorflow-gpu==2.4.1 -y ``` The comma...
65,273,118
I am new to deep learning and I have been trying to install tensorflow-gpu version in my pc in vain for the last 2 days. I avoided installing CUDA and cuDNN drivers since several forums online don't recommend it due to numerous compatibility issues. Since I was already using the conda distribution of python before, I w...
2020/12/13
[ "https://Stackoverflow.com/questions/65273118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14372142/" ]
The `tensorflow` build automatically selected by Anaconda on Windows 10 during the installation of `tensorflow-gpu` 2.3 seems to be faulty. Please find a workaround [here](https://github.com/ContinuumIO/anaconda-issues/issues/12194#issuecomment-751700156) (consider upvoting the GitHub answer if you have a GitHub accoun...
You will need to install cuDNN and the CUDA toolkit to use your GPU. First check for the compatible version [here](https://www.tensorflow.org/install/source#gpu). cuDNN can be found [here](https://developer.nvidia.com/cudnn) (requires free account). CUDA toolkit can be found [here](https://developer.nvidia.com/cuda-...
65,273,118
I am new to deep learning and I have been trying to install tensorflow-gpu version in my pc in vain for the last 2 days. I avoided installing CUDA and cuDNN drivers since several forums online don't recommend it due to numerous compatibility issues. Since I was already using the conda distribution of python before, I w...
2020/12/13
[ "https://Stackoverflow.com/questions/65273118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14372142/" ]
@geometrikal solution almost worked for me. But in between installing tensorflow-gpu with conda and installing tensorflow 2.3 with pip, I needed to uninstall the tensorflow parts of the package tensorflow-gpu to avoid conistency warnings by pip. Conda would have uninstalled the whole package. I know [Conda does not rec...
You will need to install cuDNN and the CUDA toolkit to use your GPU. First check for the compatible version [here](https://www.tensorflow.org/install/source#gpu). cuDNN can be found [here](https://developer.nvidia.com/cudnn) (requires free account). CUDA toolkit can be found [here](https://developer.nvidia.com/cuda-...
65,273,118
I am new to deep learning and I have been trying to install tensorflow-gpu version in my pc in vain for the last 2 days. I avoided installing CUDA and cuDNN drivers since several forums online don't recommend it due to numerous compatibility issues. Since I was already using the conda distribution of python before, I w...
2020/12/13
[ "https://Stackoverflow.com/questions/65273118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14372142/" ]
The `tensorflow` build automatically selected by Anaconda on Windows 10 during the installation of `tensorflow-gpu` 2.3 seems to be faulty. Please find a workaround [here](https://github.com/ContinuumIO/anaconda-issues/issues/12194#issuecomment-751700156) (consider upvoting the GitHub answer if you have a GitHub accoun...
I see that your GPU has **[compute capability 5.0](https://developer.nvidia.com/cuda-gpus)** which is OK, TensorFlow should like it. Thus I assume something went wrong during the environment setup. Please try creating a new environment using: ``` conda create --name tf_gpu tensorflow-gpu ``` Then install all other ...
65,273,118
I am new to deep learning and I have been trying to install tensorflow-gpu version in my pc in vain for the last 2 days. I avoided installing CUDA and cuDNN drivers since several forums online don't recommend it due to numerous compatibility issues. Since I was already using the conda distribution of python before, I w...
2020/12/13
[ "https://Stackoverflow.com/questions/65273118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14372142/" ]
You will need to install cuDNN and the CUDA toolkit to use your GPU. First check for the compatible version [here](https://www.tensorflow.org/install/source#gpu). cuDNN can be found [here](https://developer.nvidia.com/cudnn) (requires free account). CUDA toolkit can be found [here](https://developer.nvidia.com/cuda-...
In my case (**In April 2022**): ``` conda install tensorflow-gpu=2.3 tensorflow=2.3=mkl_py38h1fcfbd6_0 cudatoolkit cudnn keras matplotlib ``` Works perfectly!! it installed tensorflow-gpu=2.3 - cudatoolkit 10.1.243 and cudnn 7.6.5
65,273,118
I am new to deep learning and I have been trying to install tensorflow-gpu version in my pc in vain for the last 2 days. I avoided installing CUDA and cuDNN drivers since several forums online don't recommend it due to numerous compatibility issues. Since I was already using the conda distribution of python before, I w...
2020/12/13
[ "https://Stackoverflow.com/questions/65273118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14372142/" ]
I also have been unable (yet) to get TF 2.3.0 to recognize my Nvidia Quadro Pro 620 GPU. Note: I have 2 other 'environments' on this PC (windows Pro) All installed via Anaconda: 1. Python 3.7.8 TF 2.0.0... recognizes (and uses) the Nvidia GPU 2. Python 3.6.9 TF 2.1.0... recognizes (and uses) the Nvidia GPU 3. Python ...
Using `conda` to install TensorFlow is always a better way to manage the multi versions of TensorFlow itself as well as CUDA and CUDNN. I recently create a new conda environment and prepare to install the newest TensorFlow too. I also encountered the issue you mentioned. I checked the dependency list from `conda instal...
65,273,118
I am new to deep learning and I have been trying to install tensorflow-gpu version in my pc in vain for the last 2 days. I avoided installing CUDA and cuDNN drivers since several forums online don't recommend it due to numerous compatibility issues. Since I was already using the conda distribution of python before, I w...
2020/12/13
[ "https://Stackoverflow.com/questions/65273118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14372142/" ]
**August 2021** Conda install may be working now, as according to @ComputerScientist in the comments below, `conda install tensorflow-gpu==2.4.1` will give `cudatoolkit-10.1.243` and `cudnn-7.6.5` **The following was written in Jan 2021 and is out of date** Currently `conda install tensorflow-gpu` installs tensorflow...
Updated April 26, 2022, tensorflow 2.6.0 does the job, Python version 3.8.13 Recap - in Anaconda Jupyter, encountered the same "GPU no show" issue '2.3.0' Followed the procedure in this [link](https://medium.com/analytics-vidhya/solution-to-tensorflow-2-not-using-gpu-119fb3e04daa), again "GPU no show". Trial and er...
65,273,118
I am new to deep learning and I have been trying to install tensorflow-gpu version in my pc in vain for the last 2 days. I avoided installing CUDA and cuDNN drivers since several forums online don't recommend it due to numerous compatibility issues. Since I was already using the conda distribution of python before, I w...
2020/12/13
[ "https://Stackoverflow.com/questions/65273118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14372142/" ]
You will need to install cuDNN and the CUDA toolkit to use your GPU. First check for the compatible version [here](https://www.tensorflow.org/install/source#gpu). cuDNN can be found [here](https://developer.nvidia.com/cudnn) (requires free account). CUDA toolkit can be found [here](https://developer.nvidia.com/cuda-...
As of August 2021, with TensorFlow 2.4.1, I believe it seems to install CUDA and CuDNN in a conda environment. Here's what I did to create a fresh conda env on an Ubuntu 18.04 machine: ``` conda create --name tftest python=3.7 -y && conda activate tftest conda install ipython tensorflow-gpu==2.4.1 -y ``` The comma...
65,273,118
I am new to deep learning and I have been trying to install tensorflow-gpu version in my pc in vain for the last 2 days. I avoided installing CUDA and cuDNN drivers since several forums online don't recommend it due to numerous compatibility issues. Since I was already using the conda distribution of python before, I w...
2020/12/13
[ "https://Stackoverflow.com/questions/65273118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14372142/" ]
The `tensorflow` build automatically selected by Anaconda on Windows 10 during the installation of `tensorflow-gpu` 2.3 seems to be faulty. Please find a workaround [here](https://github.com/ContinuumIO/anaconda-issues/issues/12194#issuecomment-751700156) (consider upvoting the GitHub answer if you have a GitHub accoun...
**Following Steps worked for me:** Do the same as in the video. <https://www.youtube.com/watch?v=r31jnE7pR-g> Also install tensorflow estimator which is missing in the video. In picture you can see my environment which is working for me. [my environment](https://i.stack.imgur.com/dpggv.png) Maybe you have to change...
74,365,103
I have a small code created in python and from an api I would like to go through all the `code = url.json()["data"][0]["name"]` But I do not know how to do it this is my little code: ``` import requests swf = input("write: ") url = requests.get(f"https://apihabbo.com/api/furnis?hotel=es&name={swf}") code = url.js...
2022/11/08
[ "https://Stackoverflow.com/questions/74365103", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20452313/" ]
`data['data'][0]['code']` is not a list. The list is `data['data']`, you need to loop over that. ``` for d in data['data']: print(d['code']) ```
You have to iterate through the list of received data points. ``` response = requests.get("https://apihabbo.com/api/furnis?hotel=es&name=Gorro%20con%20Pomp%C3%B3n") data = response.json() for i in data['data']: print("{}".format(i['code'])) ```
61,235,115
**Mac OS**: when I try to run anything involving pip, I get ``` -bash: pip: command not found ``` This happened after I accidentally deleted the pip Unix file in `usr/local/bin` while trying to solve a different problem with pip. At this point, I've pretty much given up on solving the problem manually. > > Is ther...
2020/04/15
[ "https://Stackoverflow.com/questions/61235115", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13322285/" ]
In recent python versions pip is as module rather than as individual script. Try: ``` python -m pip ```
solution was surprisingly simple: deleted everything python related from my computer: 1. deleted `Python` App in `Applications` Folder 2. deleted all python and pip related files in `usr/local/bin` 3. deleted the `Python.framework` folder in `Libraray/Frameworks` 4. searched for and deleted all folders named `python` ...
11,616,003
I install virtualenv with command `sudo /usr/bin/pip-2.6 install virtualenv` And it says ``` Requirement already satisfied (use --upgrade to upgrade): virtualenv in /usr/local/lib/python2.6/dist-packages Cleaning up... ``` Why pip from /usr/bin looks to /usr/local/lib? I need to install virtualenv scripts direct...
2012/07/23
[ "https://Stackoverflow.com/questions/11616003", "https://Stackoverflow.com", "https://Stackoverflow.com/users/429873/" ]
Starting with iOS 6, you MUST set the audio session category to 'playback' before creating the UIWebView. This is all you have to do. It is not necessary to make the session active. This should be used for html video as well, because if you don't configure the session, your video will be muted when the ringer switch i...
This plugin will make your app ignore the mute switch. It's basically the same code that's in the other answers but it's nicely wrapped into a plugin so that you don't have to do any manual objective c edits. <https://github.com/EddyVerbruggen/cordova-plugin-backgroundaudio> Run this command to add it to your project...
11,616,003
I install virtualenv with command `sudo /usr/bin/pip-2.6 install virtualenv` And it says ``` Requirement already satisfied (use --upgrade to upgrade): virtualenv in /usr/local/lib/python2.6/dist-packages Cleaning up... ``` Why pip from /usr/bin looks to /usr/local/lib? I need to install virtualenv scripts direct...
2012/07/23
[ "https://Stackoverflow.com/questions/11616003", "https://Stackoverflow.com", "https://Stackoverflow.com/users/429873/" ]
Starting with iOS 6, you MUST set the audio session category to 'playback' before creating the UIWebView. This is all you have to do. It is not necessary to make the session active. This should be used for html video as well, because if you don't configure the session, your video will be muted when the ringer switch i...
Swift Syntax: in AppDelegate: ``` import AVFoundation func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { do{ let audio = AVAudioSession.sharedInstance() try audio.setCategory(AVAudioSession.Category.playback) }catch let error as...
11,616,003
I install virtualenv with command `sudo /usr/bin/pip-2.6 install virtualenv` And it says ``` Requirement already satisfied (use --upgrade to upgrade): virtualenv in /usr/local/lib/python2.6/dist-packages Cleaning up... ``` Why pip from /usr/bin looks to /usr/local/lib? I need to install virtualenv scripts direct...
2012/07/23
[ "https://Stackoverflow.com/questions/11616003", "https://Stackoverflow.com", "https://Stackoverflow.com/users/429873/" ]
Starting with iOS 6, you MUST set the audio session category to 'playback' before creating the UIWebView. This is all you have to do. It is not necessary to make the session active. This should be used for html video as well, because if you don't configure the session, your video will be muted when the ringer switch i...
Here the SWIFT 2.0 version to set the audio session category to 'playback' before creating the UIWebView. ``` do { try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback) } catch let error as NSError { print(error) } do { try AVAudioSession.sharedInstance().setActive(true) } catc...
11,616,003
I install virtualenv with command `sudo /usr/bin/pip-2.6 install virtualenv` And it says ``` Requirement already satisfied (use --upgrade to upgrade): virtualenv in /usr/local/lib/python2.6/dist-packages Cleaning up... ``` Why pip from /usr/bin looks to /usr/local/lib? I need to install virtualenv scripts direct...
2012/07/23
[ "https://Stackoverflow.com/questions/11616003", "https://Stackoverflow.com", "https://Stackoverflow.com/users/429873/" ]
Swift Syntax: in AppDelegate: ``` import AVFoundation func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { do{ let audio = AVAudioSession.sharedInstance() try audio.setCategory(AVAudioSession.Category.playback) }catch let error as...
This plugin will make your app ignore the mute switch. It's basically the same code that's in the other answers but it's nicely wrapped into a plugin so that you don't have to do any manual objective c edits. <https://github.com/EddyVerbruggen/cordova-plugin-backgroundaudio> Run this command to add it to your project...
11,616,003
I install virtualenv with command `sudo /usr/bin/pip-2.6 install virtualenv` And it says ``` Requirement already satisfied (use --upgrade to upgrade): virtualenv in /usr/local/lib/python2.6/dist-packages Cleaning up... ``` Why pip from /usr/bin looks to /usr/local/lib? I need to install virtualenv scripts direct...
2012/07/23
[ "https://Stackoverflow.com/questions/11616003", "https://Stackoverflow.com", "https://Stackoverflow.com/users/429873/" ]
This plugin will make your app ignore the mute switch. It's basically the same code that's in the other answers but it's nicely wrapped into a plugin so that you don't have to do any manual objective c edits. <https://github.com/EddyVerbruggen/cordova-plugin-backgroundaudio> Run this command to add it to your project...
Here the SWIFT 2.0 version to set the audio session category to 'playback' before creating the UIWebView. ``` do { try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback) } catch let error as NSError { print(error) } do { try AVAudioSession.sharedInstance().setActive(true) } catc...
11,616,003
I install virtualenv with command `sudo /usr/bin/pip-2.6 install virtualenv` And it says ``` Requirement already satisfied (use --upgrade to upgrade): virtualenv in /usr/local/lib/python2.6/dist-packages Cleaning up... ``` Why pip from /usr/bin looks to /usr/local/lib? I need to install virtualenv scripts direct...
2012/07/23
[ "https://Stackoverflow.com/questions/11616003", "https://Stackoverflow.com", "https://Stackoverflow.com/users/429873/" ]
Swift Syntax: in AppDelegate: ``` import AVFoundation func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { do{ let audio = AVAudioSession.sharedInstance() try audio.setCategory(AVAudioSession.Category.playback) }catch let error as...
Here the SWIFT 2.0 version to set the audio session category to 'playback' before creating the UIWebView. ``` do { try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback) } catch let error as NSError { print(error) } do { try AVAudioSession.sharedInstance().setActive(true) } catc...
15,616,139
I am python beginner struggling to create and save a list containing tuples from csv file in python. The code I got for now is: ``` def load_file(filename): fp = open(filename, 'Ur') data_list = [] for line in fp: data_list.append(line.strip().split(',')) fp.close() return data_list ``` ...
2013/03/25
[ "https://Stackoverflow.com/questions/15616139", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2207588/" ]
`split` returns a list, if you want a tuple, convert it to a tuple: ``` data_list.append(tuple(line.strip().split(','))) ``` Please use the `csv` module.
First question: why is a list of lists bad? In the sense of "duck-typing", this should be fine, so maybe you think about it again. If you really need a list of tuples - only small changes are needed. Change the line ``` data_list.append(line.strip().split(',')) ``` to ``` data_list.append(tuple(l...
15,616,139
I am python beginner struggling to create and save a list containing tuples from csv file in python. The code I got for now is: ``` def load_file(filename): fp = open(filename, 'Ur') data_list = [] for line in fp: data_list.append(line.strip().split(',')) fp.close() return data_list ``` ...
2013/03/25
[ "https://Stackoverflow.com/questions/15616139", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2207588/" ]
`split` returns a list, if you want a tuple, convert it to a tuple: ``` data_list.append(tuple(line.strip().split(','))) ``` Please use the `csv` module.
Just wrap "tuple()" around the `line.strip().split(',')` and you'll get a list of tuples. You can see it in action in [this runnable gist](https://www.pythonanywhere.com/gists/5237115/load_tuples.py/ipython2/?affiliate_id=000003ec).
15,616,139
I am python beginner struggling to create and save a list containing tuples from csv file in python. The code I got for now is: ``` def load_file(filename): fp = open(filename, 'Ur') data_list = [] for line in fp: data_list.append(line.strip().split(',')) fp.close() return data_list ``` ...
2013/03/25
[ "https://Stackoverflow.com/questions/15616139", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2207588/" ]
First question: why is a list of lists bad? In the sense of "duck-typing", this should be fine, so maybe you think about it again. If you really need a list of tuples - only small changes are needed. Change the line ``` data_list.append(line.strip().split(',')) ``` to ``` data_list.append(tuple(l...
Just wrap "tuple()" around the `line.strip().split(',')` and you'll get a list of tuples. You can see it in action in [this runnable gist](https://www.pythonanywhere.com/gists/5237115/load_tuples.py/ipython2/?affiliate_id=000003ec).
21,352,457
I'm trying to create a program that will launch livestreamer.exe with flags (-example), but cannot figure out how to do so. When using the built in "run" function with windows, I type this: `livestreamer.exe twitch.tv/streamer best` And here is my python code so far: ``` import os streamer=input("Streamer (full na...
2014/01/25
[ "https://Stackoverflow.com/questions/21352457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2925095/" ]
``` arr = [["food", "eggs"],["beverage", "milk"],["desert", "cake"]] arr.inject([]) do |hash, (v1, v2)| hash << { category: v1, item: v2 } end ``` I used [`inject`](http://ruby-doc.org/core-2.1.0/Enumerable.html#method-i-inject) to keep the code concise. Next time you may want to show what you have tried in the q...
``` hash = arr.each_with_object({}){|elem, hsh|hsh[elem[0]] = elem[1]} ```
21,352,457
I'm trying to create a program that will launch livestreamer.exe with flags (-example), but cannot figure out how to do so. When using the built in "run" function with windows, I type this: `livestreamer.exe twitch.tv/streamer best` And here is my python code so far: ``` import os streamer=input("Streamer (full na...
2014/01/25
[ "https://Stackoverflow.com/questions/21352457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2925095/" ]
Use [`Array#map`](http://www.ruby-doc.org/core-2.1.0/Array.html#method-i-map): ``` arr = [["food", "eggs"], ["beverage", "milk"], ["desert", "cake"]] arr.map { |category, item| { category: category, item: item } } # => [ # {:category=>"food", :item=>"eggs"}, # {:category=>"beverage", :item=>"milk"}, # ...
``` arr = [["food", "eggs"],["beverage", "milk"],["desert", "cake"]] arr.inject([]) do |hash, (v1, v2)| hash << { category: v1, item: v2 } end ``` I used [`inject`](http://ruby-doc.org/core-2.1.0/Enumerable.html#method-i-inject) to keep the code concise. Next time you may want to show what you have tried in the q...
21,352,457
I'm trying to create a program that will launch livestreamer.exe with flags (-example), but cannot figure out how to do so. When using the built in "run" function with windows, I type this: `livestreamer.exe twitch.tv/streamer best` And here is my python code so far: ``` import os streamer=input("Streamer (full na...
2014/01/25
[ "https://Stackoverflow.com/questions/21352457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2925095/" ]
``` arr = [["food", "eggs"],["beverage", "milk"],["desert", "cake"]] arr.inject([]) do |hash, (v1, v2)| hash << { category: v1, item: v2 } end ``` I used [`inject`](http://ruby-doc.org/core-2.1.0/Enumerable.html#method-i-inject) to keep the code concise. Next time you may want to show what you have tried in the q...
``` hash = array.map {|ary| Hash[[:category, :item].zip ary ]} ```
21,352,457
I'm trying to create a program that will launch livestreamer.exe with flags (-example), but cannot figure out how to do so. When using the built in "run" function with windows, I type this: `livestreamer.exe twitch.tv/streamer best` And here is my python code so far: ``` import os streamer=input("Streamer (full na...
2014/01/25
[ "https://Stackoverflow.com/questions/21352457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2925095/" ]
Use [`Array#map`](http://www.ruby-doc.org/core-2.1.0/Array.html#method-i-map): ``` arr = [["food", "eggs"], ["beverage", "milk"], ["desert", "cake"]] arr.map { |category, item| { category: category, item: item } } # => [ # {:category=>"food", :item=>"eggs"}, # {:category=>"beverage", :item=>"milk"}, # ...
``` hash = arr.each_with_object({}){|elem, hsh|hsh[elem[0]] = elem[1]} ```
21,352,457
I'm trying to create a program that will launch livestreamer.exe with flags (-example), but cannot figure out how to do so. When using the built in "run" function with windows, I type this: `livestreamer.exe twitch.tv/streamer best` And here is my python code so far: ``` import os streamer=input("Streamer (full na...
2014/01/25
[ "https://Stackoverflow.com/questions/21352457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2925095/" ]
Use [`Array#map`](http://www.ruby-doc.org/core-2.1.0/Array.html#method-i-map): ``` arr = [["food", "eggs"], ["beverage", "milk"], ["desert", "cake"]] arr.map { |category, item| { category: category, item: item } } # => [ # {:category=>"food", :item=>"eggs"}, # {:category=>"beverage", :item=>"milk"}, # ...
``` hash = array.map {|ary| Hash[[:category, :item].zip ary ]} ```
47,810,110
I have a text file which has 30 multiple choice questions in the following pattern 1. question one goes here ? A. Option 1 B. Option 2 C. Option 3 D. Option 4 and so on to 30 Number of options is variable; there are minimum two and maximum six options. I want to practice these questions in a interface like html...
2017/12/14
[ "https://Stackoverflow.com/questions/47810110", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3986321/" ]
You just need to change your JS to: ``` $(document).ready(function(){ $('section').mouseenter(function(){ var id = $(this).attr('id'); $('a').removeClass('colorAdded'); $("a[href='#"+id+"']").addClass('colorAdded'); }); }); ``` It was an issue with not including quotations in selectin...
I'm actually don't know why your codepen example is not working, I didn't look into your code carefully, but I tried to create simple code like bellow and it worked. the thing you probably should care about is how you import JQuery into your page. `<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery...
17,957,651
For those who need to know, I'm running a 64 bit Ubuntu 12.04, and trying to run the problematic script using a pip-installed python3.2 For a project I was writing I wanted to display an image in a tkinter window. To do this I installed Pillow via pip and installed tkinter for python 3 like so: ``` pip-3.2 install pi...
2013/07/30
[ "https://Stackoverflow.com/questions/17957651", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1543167/" ]
So after posting an issue on [GitHub](https://github.com/python-imaging/Pillow/issues/322#issuecomment-23053260 "GitHub") I was told I was missing some libraries. Specifically I needed to `sudo apt-get install tk8.5-dev tcl8.5-dev` and then `pip install -I pillow` to rebuild pillow. This worked on my raspberry p...
I don't have the rep to comment, so I'll answer instead I too was getting the error `can't from PIL import _imagingtk` using python3 on Linux Mint 17 when trying to do a `tk_im = ImageTk(im)` First I installed the tk8.6-dev and tcl8.6-dev as suggested above Then I tried the `pip3 --upgrade route`, which didn't fix t...
17,957,651
For those who need to know, I'm running a 64 bit Ubuntu 12.04, and trying to run the problematic script using a pip-installed python3.2 For a project I was writing I wanted to display an image in a tkinter window. To do this I installed Pillow via pip and installed tkinter for python 3 like so: ``` pip-3.2 install pi...
2013/07/30
[ "https://Stackoverflow.com/questions/17957651", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1543167/" ]
So after posting an issue on [GitHub](https://github.com/python-imaging/Pillow/issues/322#issuecomment-23053260 "GitHub") I was told I was missing some libraries. Specifically I needed to `sudo apt-get install tk8.5-dev tcl8.5-dev` and then `pip install -I pillow` to rebuild pillow. This worked on my raspberry p...
I struggled with this for a long time. None of these solutions worked for me, other people were hostile claiming the problem had already been solved while pointing to python2.7 instead of python3 or that I must not be following the instructions. But on Ubuntu with more than one computer, I had this problem and here's h...
17,957,651
For those who need to know, I'm running a 64 bit Ubuntu 12.04, and trying to run the problematic script using a pip-installed python3.2 For a project I was writing I wanted to display an image in a tkinter window. To do this I installed Pillow via pip and installed tkinter for python 3 like so: ``` pip-3.2 install pi...
2013/07/30
[ "https://Stackoverflow.com/questions/17957651", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1543167/" ]
I struggled with this for a long time. None of these solutions worked for me, other people were hostile claiming the problem had already been solved while pointing to python2.7 instead of python3 or that I must not be following the instructions. But on Ubuntu with more than one computer, I had this problem and here's h...
I don't have the rep to comment, so I'll answer instead I too was getting the error `can't from PIL import _imagingtk` using python3 on Linux Mint 17 when trying to do a `tk_im = ImageTk(im)` First I installed the tk8.6-dev and tcl8.6-dev as suggested above Then I tried the `pip3 --upgrade route`, which didn't fix t...
414,896
I'm trying to determine what is the fastest way to read in large text files with many rows, do some processing, and write them to a new file. In C#/.net, it appears StreamReader is a seemingly quick way of doing this but when I try to use for this file (reading line by line), it goes about 1/3 the speed of python's I/O...
2009/01/05
[ "https://Stackoverflow.com/questions/414896", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1469014/" ]
Do you have a code sample of what your doing, or the format of the file you are reading? Another good question would be how much of the stream are you keeping in memory at a time?
A general note: 1. High performance streaming isn't complicated. You usually have to modify the logic that uses the streamed data; **that's** complicated. Actually, that's it.
414,896
I'm trying to determine what is the fastest way to read in large text files with many rows, do some processing, and write them to a new file. In C#/.net, it appears StreamReader is a seemingly quick way of doing this but when I try to use for this file (reading line by line), it goes about 1/3 the speed of python's I/O...
2009/01/05
[ "https://Stackoverflow.com/questions/414896", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1469014/" ]
StreamReader is pretty good - how were you reading it in Python? It's possible that if you specify a simpler encoding (e.g. ASCII) then that may speed things up. How much CPU is the process taking? You can increase the buffer size by using the appropriate StreamReader constructor, but I have no idea how much differenc...
Sorry if I'm not a .NET guru, but in C/C++, if you have nice big buffers, you should be able to parse it with an LL1 parser not much slower than you can scan the bytes. I can give more detail if you want.
414,896
I'm trying to determine what is the fastest way to read in large text files with many rows, do some processing, and write them to a new file. In C#/.net, it appears StreamReader is a seemingly quick way of doing this but when I try to use for this file (reading line by line), it goes about 1/3 the speed of python's I/O...
2009/01/05
[ "https://Stackoverflow.com/questions/414896", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1469014/" ]
If your own code is examining one character at a time, you want to use a *sentinel* to mark the end of a buffer or the end of file, so that you have **just one test in your inner loop**. In your case that one test will be for end of line, so you'll want to temporarily stick a newline at the end of each buffer, for exam...
A general note: 1. High performance streaming isn't complicated. You usually have to modify the logic that uses the streamed data; **that's** complicated. Actually, that's it.
414,896
I'm trying to determine what is the fastest way to read in large text files with many rows, do some processing, and write them to a new file. In C#/.net, it appears StreamReader is a seemingly quick way of doing this but when I try to use for this file (reading line by line), it goes about 1/3 the speed of python's I/O...
2009/01/05
[ "https://Stackoverflow.com/questions/414896", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1469014/" ]
Do you have a code sample of what your doing, or the format of the file you are reading? Another good question would be how much of the stream are you keeping in memory at a time?
Sorry if I'm not a .NET guru, but in C/C++, if you have nice big buffers, you should be able to parse it with an LL1 parser not much slower than you can scan the bytes. I can give more detail if you want.
414,896
I'm trying to determine what is the fastest way to read in large text files with many rows, do some processing, and write them to a new file. In C#/.net, it appears StreamReader is a seemingly quick way of doing this but when I try to use for this file (reading line by line), it goes about 1/3 the speed of python's I/O...
2009/01/05
[ "https://Stackoverflow.com/questions/414896", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1469014/" ]
StreamReader is pretty good - how were you reading it in Python? It's possible that if you specify a simpler encoding (e.g. ASCII) then that may speed things up. How much CPU is the process taking? You can increase the buffer size by using the appropriate StreamReader constructor, but I have no idea how much differenc...
A general note: 1. High performance streaming isn't complicated. You usually have to modify the logic that uses the streamed data; **that's** complicated. Actually, that's it.
414,896
I'm trying to determine what is the fastest way to read in large text files with many rows, do some processing, and write them to a new file. In C#/.net, it appears StreamReader is a seemingly quick way of doing this but when I try to use for this file (reading line by line), it goes about 1/3 the speed of python's I/O...
2009/01/05
[ "https://Stackoverflow.com/questions/414896", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1469014/" ]
If your own code is examining one character at a time, you want to use a *sentinel* to mark the end of a buffer or the end of file, so that you have **just one test in your inner loop**. In your case that one test will be for end of line, so you'll want to temporarily stick a newline at the end of each buffer, for exam...
Sorry if I'm not a .NET guru, but in C/C++, if you have nice big buffers, you should be able to parse it with an LL1 parser not much slower than you can scan the bytes. I can give more detail if you want.
414,896
I'm trying to determine what is the fastest way to read in large text files with many rows, do some processing, and write them to a new file. In C#/.net, it appears StreamReader is a seemingly quick way of doing this but when I try to use for this file (reading line by line), it goes about 1/3 the speed of python's I/O...
2009/01/05
[ "https://Stackoverflow.com/questions/414896", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1469014/" ]
StreamReader is pretty good - how were you reading it in Python? It's possible that if you specify a simpler encoding (e.g. ASCII) then that may speed things up. How much CPU is the process taking? You can increase the buffer size by using the appropriate StreamReader constructor, but I have no idea how much differenc...
Try BufferedReader and BufferedWriter to speed up processing.
414,896
I'm trying to determine what is the fastest way to read in large text files with many rows, do some processing, and write them to a new file. In C#/.net, it appears StreamReader is a seemingly quick way of doing this but when I try to use for this file (reading line by line), it goes about 1/3 the speed of python's I/O...
2009/01/05
[ "https://Stackoverflow.com/questions/414896", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1469014/" ]
Do you have a code sample of what your doing, or the format of the file you are reading? Another good question would be how much of the stream are you keeping in memory at a time?
The default buffer sizes used by StreamReader/FileStream may not be optimal for the record lengths in your data, so you can try tweaking them. You can override the default buffer lengths in the constructors to both FileStream and the StreamReader which wraps it. You should probably make them the same size.
414,896
I'm trying to determine what is the fastest way to read in large text files with many rows, do some processing, and write them to a new file. In C#/.net, it appears StreamReader is a seemingly quick way of doing this but when I try to use for this file (reading line by line), it goes about 1/3 the speed of python's I/O...
2009/01/05
[ "https://Stackoverflow.com/questions/414896", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1469014/" ]
If your own code is examining one character at a time, you want to use a *sentinel* to mark the end of a buffer or the end of file, so that you have **just one test in your inner loop**. In your case that one test will be for end of line, so you'll want to temporarily stick a newline at the end of each buffer, for exam...
Try BufferedReader and BufferedWriter to speed up processing.
414,896
I'm trying to determine what is the fastest way to read in large text files with many rows, do some processing, and write them to a new file. In C#/.net, it appears StreamReader is a seemingly quick way of doing this but when I try to use for this file (reading line by line), it goes about 1/3 the speed of python's I/O...
2009/01/05
[ "https://Stackoverflow.com/questions/414896", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1469014/" ]
Do you have a code sample of what your doing, or the format of the file you are reading? Another good question would be how much of the stream are you keeping in memory at a time?
Try BufferedReader and BufferedWriter to speed up processing.
55,459,783
I am currently trying to code Uno in python for my Computer science principles class in school and I created a definition to draw cards from the deck into the player's hand and whenever I run the code I keep getting this error. I was just wondering how to fix it because I have tried a couple of things and have gotten n...
2019/04/01
[ "https://Stackoverflow.com/questions/55459783", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11293669/" ]
Lists in Python are mutable. So when you manipulate a list (even within the scope of a function) it will reflect everywhere that list is referenced. ``` x = x.insert(0,draw) z = z.remove(draw) ``` These lines of code are assigning the return of the method calls on the list. Both of these method calls don't return an...
The problem comes from these two lines, because remove does not return the list : ``` x = x.insert(0, draw) z = z.remove(draw) ``` `insert` and `remove` do not return anything. Do not reassign `x` and `z` and it should work: ``` x.insert(0, draw) z.remove(draw) ``` In addition, you should return `z` to save the r...
64,657,061
I'm trying to create a simple python calculator to calculate dose of a medication. For a sample weighing 60kg. The dose should be (60\*15) divide by 80. The supposed output should be 11.25 vials. However, Im getting 7.575757575757576e+27. Please help me out to diagnose the problem here. Thanks Here is the sample cod...
2020/11/03
[ "https://Stackoverflow.com/questions/64657061", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11362617/" ]
You're multiplying the string Try this: ``` print ('Number of vial is ' + str(int(ptWeight)*15 / 80)+ ' vials.') ```
You are multiplying as a sting. Try this instead ``` print('Hello Doctor!') print('What is your name?') myName= input() print('It is good to meet you, ' 'Dr.' +myName) print('What is the weight of patient?') # Patient weight ptWeight = int(input()) vitals = round(int((ptWeight)*15) / 80,2) print ('Number of vial i...
10,137,026
So I have the directory struture like this ``` Execute_directory--> execute.py | Algorithm ---> algorithm.py | |--> data.txt ``` So I am inside execute directory and have included the following path to my python path. ``` sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/....
2012/04/13
[ "https://Stackoverflow.com/questions/10137026", "https://Stackoverflow.com", "https://Stackoverflow.com/users/902885/" ]
Are you reading `data.txt` in `algorithm.py` like this: ``` open('data.txt') ``` Because that is relative to the *working directory* and not relative to the scripts directory. In `algorithm.py` you could try this: ``` open(os.path.join(os.path.dirname(__file__), 'data.txt')) ```
This would usually be an issue with relative filenames not being relative to where you expect. Print the contents of `os.path.abspath(filename)` to check this. If it gives you something strange, specifying the absolute path in the first place (when you initialise `filename`) should fix it.
10,137,026
So I have the directory struture like this ``` Execute_directory--> execute.py | Algorithm ---> algorithm.py | |--> data.txt ``` So I am inside execute directory and have included the following path to my python path. ``` sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/....
2012/04/13
[ "https://Stackoverflow.com/questions/10137026", "https://Stackoverflow.com", "https://Stackoverflow.com/users/902885/" ]
Are you reading `data.txt` in `algorithm.py` like this: ``` open('data.txt') ``` Because that is relative to the *working directory* and not relative to the scripts directory. In `algorithm.py` you could try this: ``` open(os.path.join(os.path.dirname(__file__), 'data.txt')) ```
`sys.path` is used to tell Python where to look for modules when you use `import`. It does not affect looking for files with `open`. When you open a file, relative paths are relative to the "current working directory", which you can check with `os.getcwd` and change with `os.chdir`. Bonus: if you check the value of `s...
10,137,026
So I have the directory struture like this ``` Execute_directory--> execute.py | Algorithm ---> algorithm.py | |--> data.txt ``` So I am inside execute directory and have included the following path to my python path. ``` sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/....
2012/04/13
[ "https://Stackoverflow.com/questions/10137026", "https://Stackoverflow.com", "https://Stackoverflow.com/users/902885/" ]
This would usually be an issue with relative filenames not being relative to where you expect. Print the contents of `os.path.abspath(filename)` to check this. If it gives you something strange, specifying the absolute path in the first place (when you initialise `filename`) should fix it.
`sys.path` is used to tell Python where to look for modules when you use `import`. It does not affect looking for files with `open`. When you open a file, relative paths are relative to the "current working directory", which you can check with `os.getcwd` and change with `os.chdir`. Bonus: if you check the value of `s...
38,060,383
I have the following sql query: ``` SELECT pc.patente, cs.cpc_group_codigo_cpc_group FROM patente_pc pc , patente_cpc cpc, cpc_subgroup cs, cpc_group cg WHERE pc.codigo_patente_pc = cpc.patente_pc_codigo_patente_pc AND cpc.cpc = cs.codigo_cpc_subgroup AND cs.cpc_group_codigo_c...
2016/06/27
[ "https://Stackoverflow.com/questions/38060383", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5691244/" ]
> > Does Google allow third party access? > > > Yes. If you're going to be doing interactive programming using mainstream services, learn to use APIs. The Google API collection allows users to register their applications and sites for a *huge* variety of their services...including `Gmail`. Look [here](https://con...
I agree with the others its fairly well documented, particularly here would be relevant for you if you intend to get started using the Java API: [Google docs](https://developers.google.com/gmail/api/quickstart/java#step_3_set_up_the_sample) > > To run this quickstart, you'll need: > > > Java 1.7 or greater. Gradle ...
16,136,341
I need to optimize a function call that is in a loop, for a time-critical robotics application. My script is in python, which interfaces via ctypes with a C++ library I wrote, which then calls a microcontroller library. The bottleneck is adding position-velocity-time points to the microcontroller buffer. According to ...
2013/04/21
[ "https://Stackoverflow.com/questions/16136341", "https://Stackoverflow.com", "https://Stackoverflow.com/users/901553/" ]
The round-trip between Python and C++ can be expensive, especially when using *ctypes* (which is like an interpreted version of a normal C/Python wrapper). Your goal should be to minimize the number of trips and do the most work possible per trip. It looks to me like your code has too fine of a granularity (i.e. doin...
You can just use `data_np.data.tobytes()`: ``` data_np = np.vstack([nodes, positions, velocities, times]).transpose().astype(np.long) timer = time() clibrary.addPvtAll(N, data_np.data.tobytes()) print("clibrary.addPvtAll() call: %f" % (time() - timer)) ```
16,136,341
I need to optimize a function call that is in a loop, for a time-critical robotics application. My script is in python, which interfaces via ctypes with a C++ library I wrote, which then calls a microcontroller library. The bottleneck is adding position-velocity-time points to the microcontroller buffer. According to ...
2013/04/21
[ "https://Stackoverflow.com/questions/16136341", "https://Stackoverflow.com", "https://Stackoverflow.com/users/901553/" ]
Here is my solution, which effectively eliminates the measured time difference between Python and C. Credit to kirbyfan64sos for suggesting SWIG and Raymond Hettinger for C-arrays in numpy. I use a numpy array in Python which is sent to C purely as a pointer - the same memory block is accessed in both languages. The C...
You can just use `data_np.data.tobytes()`: ``` data_np = np.vstack([nodes, positions, velocities, times]).transpose().astype(np.long) timer = time() clibrary.addPvtAll(N, data_np.data.tobytes()) print("clibrary.addPvtAll() call: %f" % (time() - timer)) ```
71,987,704
So here is the code in question. The error I get when I run the code is File "D:\obj\windows-release\37amd64\_Release\msi\_python\zip\_amd64\random.py", line 259, in choice TypeError: object of type 'type' has no len() ``` import random import tkinter as tk from tkinter import messagebox root=tk.Tk() root.title("Tra...
2022/04/24
[ "https://Stackoverflow.com/questions/71987704", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18834663/" ]
This is verging on an opinion-based question, but I think it is on-topic, since it helps to clarify the syntax and structure of ggplot calls. In a sense you have already answered the question yourself: > > it does not seem to be documented anywhere in the ggplot2 help > > > This, and the near absence of examples...
### TL;DR I cannot see any strong reasons why not to use this pattern, but other patterns are recommended in the documentation, without elaboration. ### What does `+ aes()` do? A ggplot has two types of aesthetics: * the default one (typically supplied inside `ggplot()`), and * `geom_*()` specific aesthetics If `i...
39,086,368
I'm trying to read beyond the EOF in Python, but so far I'm failing (also tried to work with seek to position and read fixed size). I've found a workaround which only works on Linux (and is quite slow, too) by working with debugfs and subprocess, but this is to slow and does not work on windows. My Question: is it po...
2016/08/22
[ "https://Stackoverflow.com/questions/39086368", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5691944/" ]
You can't read more bytes than is in the file. "End of file" literally means exactly that.
You can only move to the end using: ``` file.seek(0, 2) ``` Is that you're trying to do?
35,118,312
I am trying to install a python package that needs a Windos C++ compiler The install procedure sent me to this link: <https://wiki.python.org/moin/WindowsCompilers> I am using Python 2.7 x86 on Win 7 x64 The version indicated on that page is not available anymore (Microsoft Visual C++ 9.0 standalone: Visual C++ Compil...
2016/01/31
[ "https://Stackoverflow.com/questions/35118312", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2059078/" ]
Not sure what is happening with Microsoft today or these days but here is the direct link <http://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28-B59FBF6D907B/VCForPython27.msi> Alternatively you can search github, for "VCForPython27.msi site:github.com" That will give you either the above link or links...
The [express versions of visual studio](https://www.visualstudio.com/products/visual-studio-express-vs) are free, I assume the command line compiler would work. You might also need to read [Microsoft Visual C++ Compiler for Python 2.7](https://stackoverflow.com/questions/26140192/microsoft-visual-c-compiler-for-python...
35,118,312
I am trying to install a python package that needs a Windos C++ compiler The install procedure sent me to this link: <https://wiki.python.org/moin/WindowsCompilers> I am using Python 2.7 x86 on Win 7 x64 The version indicated on that page is not available anymore (Microsoft Visual C++ 9.0 standalone: Visual C++ Compil...
2016/01/31
[ "https://Stackoverflow.com/questions/35118312", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2059078/" ]
The "Microsoft Visual C++ Compiler for Python 2.7" download has now been completely removed by Microsoft. (Which BTW, means the Chocolatey install won't work either as it was relying on the Microsoft website as a source.) As a last resort, the file is available from the Internet Archive. Prefer any other source though...
The [express versions of visual studio](https://www.visualstudio.com/products/visual-studio-express-vs) are free, I assume the command line compiler would work. You might also need to read [Microsoft Visual C++ Compiler for Python 2.7](https://stackoverflow.com/questions/26140192/microsoft-visual-c-compiler-for-python...
58,862,894
I'm working in python using pandas and ultimately wanting to run a random forest. Python bugs out because I can't get this numeric column with spaces as nulls to be converted to a float. I tried fillna with zero and astype(float) but no success. Thanks all! ``` sm['PopHalfMile'] Out[64]: 0 2072 1 4392 2...
2019/11/14
[ "https://Stackoverflow.com/questions/58862894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12374239/" ]
Unfortunately, I don't think there is any way to do regex matching on `if` conditional expressions yet. One option is to use filtering on `push` events. ``` on: push: tags: - 'v*.*.*' ``` Another option is to do the regex check in a separate step where it [creates a step output](https://help.github.com/...
As per [docs](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet), you can do this: ``` on: create: tags: - "v[0-9]+.[0-9]+" ``` I tried the above and can confirm it works. This is not full regex capability but should suffice for your needs.
58,862,894
I'm working in python using pandas and ultimately wanting to run a random forest. Python bugs out because I can't get this numeric column with spaces as nulls to be converted to a float. I tried fillna with zero and astype(float) but no success. Thanks all! ``` sm['PopHalfMile'] Out[64]: 0 2072 1 4392 2...
2019/11/14
[ "https://Stackoverflow.com/questions/58862894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12374239/" ]
Unfortunately, I don't think there is any way to do regex matching on `if` conditional expressions yet. One option is to use filtering on `push` events. ``` on: push: tags: - 'v*.*.*' ``` Another option is to do the regex check in a separate step where it [creates a step output](https://help.github.com/...
I have managed to achieve this with a two part approach. The first part consists of filtering the tags that you want to run on. The second part is to create a condition on your `deploy` job. A cut down version of my workflow looks like the following: ```yaml name: CI-CD on: push: branches: - stable tag...
5,072,630
I am trying to create a simple form/script combination that will allow someone to replace the contents of a certain div in an html file with the text they input in an html form on a separate page. The script works fine if everything is local : the script is local, i set the working directory to where my html file is,...
2011/02/21
[ "https://Stackoverflow.com/questions/5072630", "https://Stackoverflow.com", "https://Stackoverflow.com/users/627466/" ]
Yes, use: ``` range(1,7) ``` that should do it.
Use the [`range`](http://docs.python.org/library/functions.html#range) builtin. ``` range(1, 7) ```
59,141,776
Follow the script below to convert a JSON file to parquet format. I am using the pandas library to perform the conversion. However the following error is occurring: AttributeError: 'DataFrame' object has no attribute 'schema' I am still new to python. Here's the original json file I'm using: [ { "a": "01", "b": "te...
2019/12/02
[ "https://Stackoverflow.com/questions/59141776", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10515027/" ]
If your motive is to just convert json to parquet, you can probably use pyspark API: ``` >>> data = [ { "a": "01", "b": "teste01" }, { "a": "02", "b": "teste02" } ] >>> df = spark.createDataFrame(data) >>> df.write.parquet("data.parquet") ``` Now, this DF is a spark dataframe, which can be saved in parquet.
Welcome to Stackoverflow, the library you are using shows that in example that you need to write the column names in the data frame. Try using column names of your data frame and it will work. ``` # Given PyArrow schema import pyarrow as pa schema = pa.schema([ pa.field('my_column', pa.string), pa.field('my_in...
59,141,776
Follow the script below to convert a JSON file to parquet format. I am using the pandas library to perform the conversion. However the following error is occurring: AttributeError: 'DataFrame' object has no attribute 'schema' I am still new to python. Here's the original json file I'm using: [ { "a": "01", "b": "te...
2019/12/02
[ "https://Stackoverflow.com/questions/59141776", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10515027/" ]
You can also directly read JSON files utilizing `pyarrow` as in the following example: ``` from pyarrow import json import pyarrow.parquet as pq table = json.read_json('C:/python/json_teste') pq.write_table(table, 'C:/python/result.parquet') # save json/table as parquet ``` Reference: [reading and writing with py...
Welcome to Stackoverflow, the library you are using shows that in example that you need to write the column names in the data frame. Try using column names of your data frame and it will work. ``` # Given PyArrow schema import pyarrow as pa schema = pa.schema([ pa.field('my_column', pa.string), pa.field('my_in...
59,141,776
Follow the script below to convert a JSON file to parquet format. I am using the pandas library to perform the conversion. However the following error is occurring: AttributeError: 'DataFrame' object has no attribute 'schema' I am still new to python. Here's the original json file I'm using: [ { "a": "01", "b": "te...
2019/12/02
[ "https://Stackoverflow.com/questions/59141776", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10515027/" ]
Here's how to convert a JSON file to Apache Parquet format, using Pandas in Python. This is an easy method with a well-known library you may already be familiar with. Firstly, make sure to install `pandas` and `pyarrow`. If you're using [Python with Anaconda](https://www.anaconda.com/products/individual#Downloads): `...
Welcome to Stackoverflow, the library you are using shows that in example that you need to write the column names in the data frame. Try using column names of your data frame and it will work. ``` # Given PyArrow schema import pyarrow as pa schema = pa.schema([ pa.field('my_column', pa.string), pa.field('my_in...
59,141,776
Follow the script below to convert a JSON file to parquet format. I am using the pandas library to perform the conversion. However the following error is occurring: AttributeError: 'DataFrame' object has no attribute 'schema' I am still new to python. Here's the original json file I'm using: [ { "a": "01", "b": "te...
2019/12/02
[ "https://Stackoverflow.com/questions/59141776", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10515027/" ]
You can achieve what you are looking for by pyspark as follows: ``` from pyspark.sql import SparkSession spark = SparkSession \ .builder \ .appName("JsonToParquetPysparkExample") \ .getOrCreate() json_df = spark.read.json("C://python/test.json", multiLine=True,) json_df.printSchema() json_df.write.parqu...
Welcome to Stackoverflow, the library you are using shows that in example that you need to write the column names in the data frame. Try using column names of your data frame and it will work. ``` # Given PyArrow schema import pyarrow as pa schema = pa.schema([ pa.field('my_column', pa.string), pa.field('my_in...
59,141,776
Follow the script below to convert a JSON file to parquet format. I am using the pandas library to perform the conversion. However the following error is occurring: AttributeError: 'DataFrame' object has no attribute 'schema' I am still new to python. Here's the original json file I'm using: [ { "a": "01", "b": "te...
2019/12/02
[ "https://Stackoverflow.com/questions/59141776", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10515027/" ]
If your motive is to just convert json to parquet, you can probably use pyspark API: ``` >>> data = [ { "a": "01", "b": "teste01" }, { "a": "02", "b": "teste02" } ] >>> df = spark.createDataFrame(data) >>> df.write.parquet("data.parquet") ``` Now, this DF is a spark dataframe, which can be saved in parquet.
You can also directly read JSON files utilizing `pyarrow` as in the following example: ``` from pyarrow import json import pyarrow.parquet as pq table = json.read_json('C:/python/json_teste') pq.write_table(table, 'C:/python/result.parquet') # save json/table as parquet ``` Reference: [reading and writing with py...
59,141,776
Follow the script below to convert a JSON file to parquet format. I am using the pandas library to perform the conversion. However the following error is occurring: AttributeError: 'DataFrame' object has no attribute 'schema' I am still new to python. Here's the original json file I'm using: [ { "a": "01", "b": "te...
2019/12/02
[ "https://Stackoverflow.com/questions/59141776", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10515027/" ]
If your motive is to just convert json to parquet, you can probably use pyspark API: ``` >>> data = [ { "a": "01", "b": "teste01" }, { "a": "02", "b": "teste02" } ] >>> df = spark.createDataFrame(data) >>> df.write.parquet("data.parquet") ``` Now, this DF is a spark dataframe, which can be saved in parquet.
Here's how to convert a JSON file to Apache Parquet format, using Pandas in Python. This is an easy method with a well-known library you may already be familiar with. Firstly, make sure to install `pandas` and `pyarrow`. If you're using [Python with Anaconda](https://www.anaconda.com/products/individual#Downloads): `...
59,141,776
Follow the script below to convert a JSON file to parquet format. I am using the pandas library to perform the conversion. However the following error is occurring: AttributeError: 'DataFrame' object has no attribute 'schema' I am still new to python. Here's the original json file I'm using: [ { "a": "01", "b": "te...
2019/12/02
[ "https://Stackoverflow.com/questions/59141776", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10515027/" ]
If your motive is to just convert json to parquet, you can probably use pyspark API: ``` >>> data = [ { "a": "01", "b": "teste01" }, { "a": "02", "b": "teste02" } ] >>> df = spark.createDataFrame(data) >>> df.write.parquet("data.parquet") ``` Now, this DF is a spark dataframe, which can be saved in parquet.
You can achieve what you are looking for by pyspark as follows: ``` from pyspark.sql import SparkSession spark = SparkSession \ .builder \ .appName("JsonToParquetPysparkExample") \ .getOrCreate() json_df = spark.read.json("C://python/test.json", multiLine=True,) json_df.printSchema() json_df.write.parqu...
61,619,201
While adding groups with permission from Django Admin Panel and adding other M2M relationships too. I got this error!! It says : **TypeError: \_bulk\_create() got an unexpected keyword argument 'ignore\_conflicts'** I can't find the error, Probably a noob mistake. ``` class GroupSerializer(serializers.ModelSerialize...
2020/05/05
[ "https://Stackoverflow.com/questions/61619201", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8944012/" ]
You should use: ``` @EventBusSubscriber public static class Class { @SubscribeEvent public static void onEvent(EntityJoinWorldEvent event) { if ((event.getEntity() instanceof PlayerEntity)) { LogManager.getLogger().info("Joined!"); } } } ``` I thought maybe you'd need the instance of the pl...
```java ... @Mod( modid = Kubecraft.MOD_ID, name = Kubecraft.MOD_NAME, version = Kubecraft.VERSION ) public class Kubecraft { ... @SubscribeEvent public static void onEvent(EntityJoinWorldEvent event) { Timer timer = new Timer(3000, new ActionListener() { ...
48,579,232
[enter image description here](https://i.stack.imgur.com/g89q0.jpg)i was trying to run the following command:: ``` python populate_book.py ``` and stuck with this error:: ``` raise AppRegistryNotReady("Apps aren't loaded yet.") django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. ``` The Whole Tra...
2018/02/02
[ "https://Stackoverflow.com/questions/48579232", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9298418/" ]
Three things that you should make sure, * are all the apps you have in your `INSTALLED_APPS` setting installed on your system? * Have you perhaps forgotten to activate the virtualenv where everything was installed in the first place? * If you have both of the things above on your system then maybe you forgot to insta...
<https://www.dangtrinh.com/2014/11/how-to-avoid-models-arent-loaded-yet.html> My advice would strongly be to perform this sort of operation within a Custom Management Command though <https://docs.djangoproject.com/en/2.0/howto/custom-management-commands/>.
927,150
I've made a python script which should modify the profile of the phone based on the phone position. Runned under ScriptShell it works great. The problem is that it hangs, both with the "sis" script runned upon "boot up", as well as without it. So my question is what is wrong with the code, and also whether I need to ...
2009/05/29
[ "https://Stackoverflow.com/questions/927150", "https://Stackoverflow.com", "https://Stackoverflow.com/users/88054/" ]
I often use something like that at the top of my scripts: ``` import os.path, sys PY_PATH = None for p in ['c:\\Data\\Python', 'e:\\Data\\Python','c:\\Python','e:\\Python']: if os.path.exists(p): PY_PATH = p break if PY_PATH and PY_PATH not in sys.path: sys.path.append(PY_PATH) ```
xprofile is not a standard library, make sure you add path to it. My guess is that when run as SIS, it doesn't find xprofile and hangs up. When releasing your SIS, either instruct that users install that separately or include inside your SIS. Where would you have it installed, use that path. Here's python default dire...
61,082,945
So, I'm learning python in school and as a part of my current project I want to be able to make small "popups" on the screen. I've chosen to do this with wxpython but I've run into a problem. Right now I can't find a way to add a variable so I can print anything I want. I tried adding an extra variable both to the clas...
2020/04/07
[ "https://Stackoverflow.com/questions/61082945", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13250047/" ]
You almost have it. You just need to straighten out a few details. First, if the input fails, you want an empty input: ``` try: move = [int(s) for s in input("Select a cell (row,col) > ").split(",")] except: move = [] ``` Now you want to repeat the input until it is valid. You first need the syntax for a whi...
You could do this with a nested function and a recursive call if the input doesn't conform to expectations. ```py import re def main(): def prompt(): digits = input("Select a cell (row,col) > ") if not re.match(r'\d+,\d+', digits): print('Error message') prompt() r...
61,082,945
So, I'm learning python in school and as a part of my current project I want to be able to make small "popups" on the screen. I've chosen to do this with wxpython but I've run into a problem. Right now I can't find a way to add a variable so I can print anything I want. I tried adding an extra variable both to the clas...
2020/04/07
[ "https://Stackoverflow.com/questions/61082945", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13250047/" ]
You almost have it. You just need to straighten out a few details. First, if the input fails, you want an empty input: ``` try: move = [int(s) for s in input("Select a cell (row,col) > ").split(",")] except: move = [] ``` Now you want to repeat the input until it is valid. You first need the syntax for a whi...
You can do it by this way: ``` def main(): print('Enter the two points as comma seperated, e.g. 3,4') while True: try: x, y = map(int, input().split(',')) except ValueError: print('Enter the two points as comma seperated, e.g. 3,4') continue else: break main() ```
2,622,866
How can I serialize a python Dictionary to JSON and pass back to javascript, which contains a string key, while the value is a List (i.e. []) ``` if request.is_ajax() and request.method == 'GET': groupSet = GroupSet.objects.get(id=int(request.GET["groupSetId"])) groups = groupSet.groups.all() group_items = ...
2010/04/12
[ "https://Stackoverflow.com/questions/2622866", "https://Stackoverflow.com", "https://Stackoverflow.com/users/314614/" ]
Your 'groups' variable is a QuerySet object, not a dict. You will want to be more explicit with the data that you want to return. ``` import json groups_and_items = {} for group in groups: group_items = [] for item in group.group_items.all(): group_items.append( {'id': item.id, 'name': item.name} ) ...
You should use Python's [json](http://docs.python.org/library/json.html) module to encode your JSON. Also, what indentation level do you have `data = serializers` at? It looks like it could be inside the for loop?
46,366,139
Hi i have a simplified example of my problem. i would like to get an output of ``` 1 a b 2 c 3 d e f 4 g 5 h ``` I have tried different variations but can figure out the logic. My code is below. Thanks for your help in advance. I am trying to do it without using numpy or panda. I am using python3.4 ``` num = ["1"...
2017/09/22
[ "https://Stackoverflow.com/questions/46366139", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7680853/" ]
Note that you are trying to print the contents of two lists. This is a linear operation in time. Two loops just won't cut it - that's quadratic in time complexity. Furthermore, your second solution doesn't flatten `y`. --- Define a helper function using `yield` and `yield from`. ``` def foo(l1, l2): for x, y i...
just `zip` the lists and flatten twice applying `itertools.chain` ``` num = ["1" , "2" ,"3" , "4" , "5" ] let = [["a","b"],["c"],["d","e","f"],["g"],["h"]] import itertools result = list(itertools.chain.from_iterable(itertools.chain.from_iterable(zip(num,let)))) ``` now `result` yields: ``` ['1', 'a', 'b', '2', '...
46,366,139
Hi i have a simplified example of my problem. i would like to get an output of ``` 1 a b 2 c 3 d e f 4 g 5 h ``` I have tried different variations but can figure out the logic. My code is below. Thanks for your help in advance. I am trying to do it without using numpy or panda. I am using python3.4 ``` num = ["1"...
2017/09/22
[ "https://Stackoverflow.com/questions/46366139", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7680853/" ]
Note that you are trying to print the contents of two lists. This is a linear operation in time. Two loops just won't cut it - that's quadratic in time complexity. Furthermore, your second solution doesn't flatten `y`. --- Define a helper function using `yield` and `yield from`. ``` def foo(l1, l2): for x, y i...
Flatten the list `let` using `pydash`. [pydash](http://pydash.readthedocs.io/en/latest/) is a utility library. Print each element from the concatenated list (`num + pydash.flatten(let)`) ``` >>> import pydash as pyd >>> num = ["1" , "2" ,"3" , "4" , "5" ] >>> let = [["a","b"],["c"],["d","e","f"],["g"],["h"]] >>> for ...
46,366,139
Hi i have a simplified example of my problem. i would like to get an output of ``` 1 a b 2 c 3 d e f 4 g 5 h ``` I have tried different variations but can figure out the logic. My code is below. Thanks for your help in advance. I am trying to do it without using numpy or panda. I am using python3.4 ``` num = ["1"...
2017/09/22
[ "https://Stackoverflow.com/questions/46366139", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7680853/" ]
Note that you are trying to print the contents of two lists. This is a linear operation in time. Two loops just won't cut it - that's quadratic in time complexity. Furthermore, your second solution doesn't flatten `y`. --- Define a helper function using `yield` and `yield from`. ``` def foo(l1, l2): for x, y i...
``` numlet = [c for n, l in zip(num,let) for c in [n] + l] for c in numlet: print(c) ```
46,366,139
Hi i have a simplified example of my problem. i would like to get an output of ``` 1 a b 2 c 3 d e f 4 g 5 h ``` I have tried different variations but can figure out the logic. My code is below. Thanks for your help in advance. I am trying to do it without using numpy or panda. I am using python3.4 ``` num = ["1"...
2017/09/22
[ "https://Stackoverflow.com/questions/46366139", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7680853/" ]
Note that you are trying to print the contents of two lists. This is a linear operation in time. Two loops just won't cut it - that's quadratic in time complexity. Furthermore, your second solution doesn't flatten `y`. --- Define a helper function using `yield` and `yield from`. ``` def foo(l1, l2): for x, y i...
this solution assumes that "num" and "let" have the same number of elements ``` num = ["1" , "2" ,"3" , "4" , "5" ] let = [["a","b"],["c"],["d","e","f"],["g"],["h"]] for i in range(len(num)): print num[i] print '\n'.join(let[i]) ```
46,366,139
Hi i have a simplified example of my problem. i would like to get an output of ``` 1 a b 2 c 3 d e f 4 g 5 h ``` I have tried different variations but can figure out the logic. My code is below. Thanks for your help in advance. I am trying to do it without using numpy or panda. I am using python3.4 ``` num = ["1"...
2017/09/22
[ "https://Stackoverflow.com/questions/46366139", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7680853/" ]
just `zip` the lists and flatten twice applying `itertools.chain` ``` num = ["1" , "2" ,"3" , "4" , "5" ] let = [["a","b"],["c"],["d","e","f"],["g"],["h"]] import itertools result = list(itertools.chain.from_iterable(itertools.chain.from_iterable(zip(num,let)))) ``` now `result` yields: ``` ['1', 'a', 'b', '2', '...
Flatten the list `let` using `pydash`. [pydash](http://pydash.readthedocs.io/en/latest/) is a utility library. Print each element from the concatenated list (`num + pydash.flatten(let)`) ``` >>> import pydash as pyd >>> num = ["1" , "2" ,"3" , "4" , "5" ] >>> let = [["a","b"],["c"],["d","e","f"],["g"],["h"]] >>> for ...
46,366,139
Hi i have a simplified example of my problem. i would like to get an output of ``` 1 a b 2 c 3 d e f 4 g 5 h ``` I have tried different variations but can figure out the logic. My code is below. Thanks for your help in advance. I am trying to do it without using numpy or panda. I am using python3.4 ``` num = ["1"...
2017/09/22
[ "https://Stackoverflow.com/questions/46366139", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7680853/" ]
just `zip` the lists and flatten twice applying `itertools.chain` ``` num = ["1" , "2" ,"3" , "4" , "5" ] let = [["a","b"],["c"],["d","e","f"],["g"],["h"]] import itertools result = list(itertools.chain.from_iterable(itertools.chain.from_iterable(zip(num,let)))) ``` now `result` yields: ``` ['1', 'a', 'b', '2', '...
this solution assumes that "num" and "let" have the same number of elements ``` num = ["1" , "2" ,"3" , "4" , "5" ] let = [["a","b"],["c"],["d","e","f"],["g"],["h"]] for i in range(len(num)): print num[i] print '\n'.join(let[i]) ```
46,366,139
Hi i have a simplified example of my problem. i would like to get an output of ``` 1 a b 2 c 3 d e f 4 g 5 h ``` I have tried different variations but can figure out the logic. My code is below. Thanks for your help in advance. I am trying to do it without using numpy or panda. I am using python3.4 ``` num = ["1"...
2017/09/22
[ "https://Stackoverflow.com/questions/46366139", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7680853/" ]
``` numlet = [c for n, l in zip(num,let) for c in [n] + l] for c in numlet: print(c) ```
Flatten the list `let` using `pydash`. [pydash](http://pydash.readthedocs.io/en/latest/) is a utility library. Print each element from the concatenated list (`num + pydash.flatten(let)`) ``` >>> import pydash as pyd >>> num = ["1" , "2" ,"3" , "4" , "5" ] >>> let = [["a","b"],["c"],["d","e","f"],["g"],["h"]] >>> for ...
46,366,139
Hi i have a simplified example of my problem. i would like to get an output of ``` 1 a b 2 c 3 d e f 4 g 5 h ``` I have tried different variations but can figure out the logic. My code is below. Thanks for your help in advance. I am trying to do it without using numpy or panda. I am using python3.4 ``` num = ["1"...
2017/09/22
[ "https://Stackoverflow.com/questions/46366139", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7680853/" ]
``` numlet = [c for n, l in zip(num,let) for c in [n] + l] for c in numlet: print(c) ```
this solution assumes that "num" and "let" have the same number of elements ``` num = ["1" , "2" ,"3" , "4" , "5" ] let = [["a","b"],["c"],["d","e","f"],["g"],["h"]] for i in range(len(num)): print num[i] print '\n'.join(let[i]) ```
3,248,194
Whats wrong in this code? Here is my HTML: ``` <html><body> <form action="iindex.py" method="POST" enctype="multipart/form-data"> <p>File: <input type="file" name="ssfilename"></p> <p><input type="submit" value="Upload" name="submit"></p> </form> </body></html> ``` This is my Python script: ``` #! /usr/bin/env pyt...
2010/07/14
[ "https://Stackoverflow.com/questions/3248194", "https://Stackoverflow.com", "https://Stackoverflow.com/users/392373/" ]
Edit: Totally missed the part where you are `doing keep_blank_values = 1`; sorry, no idea what is wrong. From <http://docs.python.org/library/cgi.html>: > > Form fields containing empty strings are ignored and do not appear in the dictionary; to keep such values, provide a true value for the optional keep\_blank\_va...
Check if you have no GET parameters in your form action URL. If you need to pass on any data put it as form elements inside the form to be POSTed along with your upload file. Then you find all your POSTed vars in `cgi.FieldStorage`.
3,248,194
Whats wrong in this code? Here is my HTML: ``` <html><body> <form action="iindex.py" method="POST" enctype="multipart/form-data"> <p>File: <input type="file" name="ssfilename"></p> <p><input type="submit" value="Upload" name="submit"></p> </form> </body></html> ``` This is my Python script: ``` #! /usr/bin/env pyt...
2010/07/14
[ "https://Stackoverflow.com/questions/3248194", "https://Stackoverflow.com", "https://Stackoverflow.com/users/392373/" ]
I had the exact same problem, make sure you have the "enctype" set to "multipart/form-data" and use a default value in your field. So your form should look like this: ``` <form enctype="multipart/form-data" id="addFile" action="AddFile.py"> <input type="file" name="file" id="file" value=""/><br/> <input type="submit"...
Check if you have no GET parameters in your form action URL. If you need to pass on any data put it as form elements inside the form to be POSTed along with your upload file. Then you find all your POSTed vars in `cgi.FieldStorage`.
59,432,477
I am working through an issue with scraping a webtable using python. I have been scraping what I would call 'standard' tables for a while and I feel like I understand that reasonably well. I define a standard table as having a structure like: ``` <table> <tr class="row-class"> <th>Bill</th> <td>1</td> <td>2</td>...
2019/12/20
[ "https://Stackoverflow.com/questions/59432477", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10862305/" ]
Here I use 3 methods how to pair the two `<tr>` tags together: * 1st method is using `zip()` and CSS selector * 2nd method is using BeautifulSoup's method `find_next_sibling()` * 3rd method is using `zip()` and simple slicing with custom step --- ``` from bs4 import BeautifulSoup t_obj = """<tr class="row-class"> ...
You can use indexing: ``` from bs4 import BeautifulSoup as soup d = soup(html, 'html.parser').find_all('tr') result = [[d[i].text]+[c.text for c in d[i+1].find_all('td')] for i in range(0, len(d), 2)] ``` To print your result: ``` print('\n'.join(f'{a[1:]},{",".join(b)}' for a, *b in result)) ``` Output: ``` Bil...
59,432,477
I am working through an issue with scraping a webtable using python. I have been scraping what I would call 'standard' tables for a while and I feel like I understand that reasonably well. I define a standard table as having a structure like: ``` <table> <tr class="row-class"> <th>Bill</th> <td>1</td> <td>2</td>...
2019/12/20
[ "https://Stackoverflow.com/questions/59432477", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10862305/" ]
Here I use 3 methods how to pair the two `<tr>` tags together: * 1st method is using `zip()` and CSS selector * 2nd method is using BeautifulSoup's method `find_next_sibling()` * 3rd method is using `zip()` and simple slicing with custom step --- ``` from bs4 import BeautifulSoup t_obj = """<tr class="row-class"> ...
Process HTML to fit ``` from simplified_scrapy.simplified_doc import SimplifiedDoc t_obj = """<tr class="row-class"> <th>Bill</th></tr> <tr><td>1</td> <td>2</td> <td>3</td> <td>4</td> </tr> <tr class="row-class"> <th>Ben</th></tr> <tr> <td>2</td> <td>3</td> <td>4</td> <td>1</td> </tr> <tr class=...
10,061,124
I once read this entry in mailing list <http://archives.postgresql.org/pgsql-hackers/2005-06/msg01481.php> ``` SELECT * FROM foo_func( c => current_timestamp::timestamp with time zone, a => 2, b => 5 ); ``` Now I need this kindof solution where I can pass associative array argument to a function. Do I ne...
2012/04/08
[ "https://Stackoverflow.com/questions/10061124", "https://Stackoverflow.com", "https://Stackoverflow.com/users/256007/" ]
If you have `a` as your clustering key, then that column is included in all non-clustered indices on that table. So your index on `c` also includes `a`, so the condition ``` where c= 3 and a = 3 ``` can be found in that index using an index seek. Most likely, the query optimizer decided that doing a index seek to...
> > *This is fine, because the non clustered index doesn't have b as the key value. Hence it does an index scan from column a.* > > > This assumption is not right. index seek and scan has to deal with WHERE clause and not the select clause. Now your question - Where clause is optimised by sql optimizer and as th...