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
3,330,280
I'm weaving my c code in python to speed up the loop: ``` from scipy import weave from numpy import * #1) create the array a=zeros((200,300,400),int) for i in range(200): for j in range(300): for k in range(400): a[i,j,k]=i*300*400+j*400+k #2) test on c code to access the array code=""" fo...
2010/07/25
[ "https://Stackoverflow.com/questions/3330280", "https://Stackoverflow.com", "https://Stackoverflow.com/users/389799/" ]
You could replace the 3 for-loops with ``` grid=np.ogrid[0:200,0:300,0:400] a=grid[0]*300*400+grid[1]*400+grid[2] ``` The following suggests this may result in a ~68x (or better? see below) speedup: ``` % python -mtimeit -s"import test" "test.m1()" 100 loops, best of 3: 17.5 msec per loop % python -mtimeit -s"impor...
I really hope, you didn't run the loop with all the print statements, as Justin already noted. Besides that: ``` from scipy import weave n1, n2, n3 = 200, 300, 400 def m1(): a = np.zeros((n1,n2,n3), int) for i in xrange(n1): for j in xrange(n2): for k in xrange(n3): a[i,j,k...
3,330,280
I'm weaving my c code in python to speed up the loop: ``` from scipy import weave from numpy import * #1) create the array a=zeros((200,300,400),int) for i in range(200): for j in range(300): for k in range(400): a[i,j,k]=i*300*400+j*400+k #2) test on c code to access the array code=""" fo...
2010/07/25
[ "https://Stackoverflow.com/questions/3330280", "https://Stackoverflow.com", "https://Stackoverflow.com/users/389799/" ]
The problem is that you are printing out 2.4 million numbers to the screen in your C code. This is of course going to take a while because the numbers have to be converted into strings and then printed to the screen. Do you really need to print them all to the screen? What is your end goal here? For a comparison, I tr...
There is no way to speed up accessing a multidimensional array in C. You have to calculate the array index and you have to dereference it, this is as simple as it gets.
3,330,280
I'm weaving my c code in python to speed up the loop: ``` from scipy import weave from numpy import * #1) create the array a=zeros((200,300,400),int) for i in range(200): for j in range(300): for k in range(400): a[i,j,k]=i*300*400+j*400+k #2) test on c code to access the array code=""" fo...
2010/07/25
[ "https://Stackoverflow.com/questions/3330280", "https://Stackoverflow.com", "https://Stackoverflow.com/users/389799/" ]
The problem is that you are printing out 2.4 million numbers to the screen in your C code. This is of course going to take a while because the numbers have to be converted into strings and then printed to the screen. Do you really need to print them all to the screen? What is your end goal here? For a comparison, I tr...
I really hope, you didn't run the loop with all the print statements, as Justin already noted. Besides that: ``` from scipy import weave n1, n2, n3 = 200, 300, 400 def m1(): a = np.zeros((n1,n2,n3), int) for i in xrange(n1): for j in xrange(n2): for k in xrange(n3): a[i,j,k...
74,091,484
I am trying to complete a project with javascript for which I need to import a library, however, npm is giving me errors whenever I try to use it. the error: ``` npm WARN deprecated har-validator@5.1.5: this library is no longer supported npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older ...
2022/10/17
[ "https://Stackoverflow.com/questions/74091484", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17289555/" ]
You wrote that you need a *"function that sorts a List of integers"*, but in your code you pass a list **of lists** to `binsort`. This only makes sense if those sublists represent digits of a number. It makes no more sense when these digits are no single digits anymore. Either: * You sort a list of integers like `[142...
``` def bucketsort(a): # Create empty buckets buckets = [[] for _ in range(10)] # Sort into buckets for i in a: buckets[i].append(i) # Flatten buckets a.clear() for bucket in buckets: a.extend(bucket) return a ```
26,709,731
I'm writing a Google App Engine project in Python with Flask. Here's my directory structure for a Hello, World! app (contents of third party libraries ommitted for brevity's sake): ``` project_root/ flask/ jinja2/ markupsafe/ myapp/ __init__.py simplejson/ werkzeug/ app.yaml its...
2014/11/03
[ "https://Stackoverflow.com/questions/26709731", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2752467/" ]
try to add the full path to your lib, like here `sys.path[0:0] = ['/home/user/project_root/lib']`
I've actually run into this problem a number of time when writing my own Google App Engine® products before. My solution was to cat the files together to form one large python file. The command to do this is: ``` cat *.py ``` Of course, you may need to fix up the import statements inside the individual files. This c...
26,709,731
I'm writing a Google App Engine project in Python with Flask. Here's my directory structure for a Hello, World! app (contents of third party libraries ommitted for brevity's sake): ``` project_root/ flask/ jinja2/ markupsafe/ myapp/ __init__.py simplejson/ werkzeug/ app.yaml its...
2014/11/03
[ "https://Stackoverflow.com/questions/26709731", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2752467/" ]
Look at defining your path manipulation in appengine\_config.py This means any path manipulation only has to be performed once. Then move your third party files in to a lib as per your suggestion. Use a relative path 'lib' either by specifying sys.path ``` sys.path.insert(0,'./lib') ``` or use ``` import site sit...
I've actually run into this problem a number of time when writing my own Google App Engine® products before. My solution was to cat the files together to form one large python file. The command to do this is: ``` cat *.py ``` Of course, you may need to fix up the import statements inside the individual files. This c...
26,709,731
I'm writing a Google App Engine project in Python with Flask. Here's my directory structure for a Hello, World! app (contents of third party libraries ommitted for brevity's sake): ``` project_root/ flask/ jinja2/ markupsafe/ myapp/ __init__.py simplejson/ werkzeug/ app.yaml its...
2014/11/03
[ "https://Stackoverflow.com/questions/26709731", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2752467/" ]
Add a python file called appengine\_config.py with the following content. ``` import sys import os.path sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'lib')) ``` As Tim Hoffman has mentioned the appengine\_config.py is called once when a new instance is started. Now you can do what you intended. addin...
I've actually run into this problem a number of time when writing my own Google App Engine® products before. My solution was to cat the files together to form one large python file. The command to do this is: ``` cat *.py ``` Of course, you may need to fix up the import statements inside the individual files. This c...
26,709,731
I'm writing a Google App Engine project in Python with Flask. Here's my directory structure for a Hello, World! app (contents of third party libraries ommitted for brevity's sake): ``` project_root/ flask/ jinja2/ markupsafe/ myapp/ __init__.py simplejson/ werkzeug/ app.yaml its...
2014/11/03
[ "https://Stackoverflow.com/questions/26709731", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2752467/" ]
Look at defining your path manipulation in appengine\_config.py This means any path manipulation only has to be performed once. Then move your third party files in to a lib as per your suggestion. Use a relative path 'lib' either by specifying sys.path ``` sys.path.insert(0,'./lib') ``` or use ``` import site sit...
try to add the full path to your lib, like here `sys.path[0:0] = ['/home/user/project_root/lib']`
26,709,731
I'm writing a Google App Engine project in Python with Flask. Here's my directory structure for a Hello, World! app (contents of third party libraries ommitted for brevity's sake): ``` project_root/ flask/ jinja2/ markupsafe/ myapp/ __init__.py simplejson/ werkzeug/ app.yaml its...
2014/11/03
[ "https://Stackoverflow.com/questions/26709731", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2752467/" ]
Add a python file called appengine\_config.py with the following content. ``` import sys import os.path sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'lib')) ``` As Tim Hoffman has mentioned the appengine\_config.py is called once when a new instance is started. Now you can do what you intended. addin...
try to add the full path to your lib, like here `sys.path[0:0] = ['/home/user/project_root/lib']`
22,752,521
I'm trying to setup an application webserver using uWSGI + Nginx, which runs a Flask application using SQLAlchemy to communicate to a Postgres database. When I make requests to the webserver, every other response will be a 500 error. The error is: ``` Traceback (most recent call last): File "/var/env/argos/lib/pyt...
2014/03/31
[ "https://Stackoverflow.com/questions/22752521", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1097920/" ]
The issue ended up being uwsgi's forking. When working with multiple processes with a master process, uwsgi initializes the application in the master process and then copies the application over to each worker process. The problem is if you open a database connection when initializing your application, you then have m...
As an alternative you might dispose the engine. This is how I solved the problem. Such issues may happen if there is a query during the creation of the app, that is, in the module that creates the app itself. If that states, the engine allocates a pool of connections and then uwsgi forks. By invoking 'engine.dispose(...
22,752,521
I'm trying to setup an application webserver using uWSGI + Nginx, which runs a Flask application using SQLAlchemy to communicate to a Postgres database. When I make requests to the webserver, every other response will be a 500 error. The error is: ``` Traceback (most recent call last): File "/var/env/argos/lib/pyt...
2014/03/31
[ "https://Stackoverflow.com/questions/22752521", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1097920/" ]
The issue ended up being uwsgi's forking. When working with multiple processes with a master process, uwsgi initializes the application in the master process and then copies the application over to each worker process. The problem is if you open a database connection when initializing your application, you then have m...
I am running a flask app using gunicorn on Heroku. My application started exhibiting this problem when I added the `--preload` option to my Procfile. When I removed that option, my application resumed functioning as normal.
22,752,521
I'm trying to setup an application webserver using uWSGI + Nginx, which runs a Flask application using SQLAlchemy to communicate to a Postgres database. When I make requests to the webserver, every other response will be a 500 error. The error is: ``` Traceback (most recent call last): File "/var/env/argos/lib/pyt...
2014/03/31
[ "https://Stackoverflow.com/questions/22752521", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1097920/" ]
The issue ended up being uwsgi's forking. When working with multiple processes with a master process, uwsgi initializes the application in the master process and then copies the application over to each worker process. The problem is if you open a database connection when initializing your application, you then have m...
Not sure whether to add this as an answer to this question or ask a separate question and put this as an answer there. I was getting this exact same error for reasons that are slightly different from the people who have posted and answered. In my setup, I using gunicorn as a wsgi for a Flask application. In this applic...
22,752,521
I'm trying to setup an application webserver using uWSGI + Nginx, which runs a Flask application using SQLAlchemy to communicate to a Postgres database. When I make requests to the webserver, every other response will be a 500 error. The error is: ``` Traceback (most recent call last): File "/var/env/argos/lib/pyt...
2014/03/31
[ "https://Stackoverflow.com/questions/22752521", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1097920/" ]
As an alternative you might dispose the engine. This is how I solved the problem. Such issues may happen if there is a query during the creation of the app, that is, in the module that creates the app itself. If that states, the engine allocates a pool of connections and then uwsgi forks. By invoking 'engine.dispose(...
I am running a flask app using gunicorn on Heroku. My application started exhibiting this problem when I added the `--preload` option to my Procfile. When I removed that option, my application resumed functioning as normal.
22,752,521
I'm trying to setup an application webserver using uWSGI + Nginx, which runs a Flask application using SQLAlchemy to communicate to a Postgres database. When I make requests to the webserver, every other response will be a 500 error. The error is: ``` Traceback (most recent call last): File "/var/env/argos/lib/pyt...
2014/03/31
[ "https://Stackoverflow.com/questions/22752521", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1097920/" ]
As an alternative you might dispose the engine. This is how I solved the problem. Such issues may happen if there is a query during the creation of the app, that is, in the module that creates the app itself. If that states, the engine allocates a pool of connections and then uwsgi forks. By invoking 'engine.dispose(...
Not sure whether to add this as an answer to this question or ask a separate question and put this as an answer there. I was getting this exact same error for reasons that are slightly different from the people who have posted and answered. In my setup, I using gunicorn as a wsgi for a Flask application. In this applic...
22,752,521
I'm trying to setup an application webserver using uWSGI + Nginx, which runs a Flask application using SQLAlchemy to communicate to a Postgres database. When I make requests to the webserver, every other response will be a 500 error. The error is: ``` Traceback (most recent call last): File "/var/env/argos/lib/pyt...
2014/03/31
[ "https://Stackoverflow.com/questions/22752521", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1097920/" ]
I am running a flask app using gunicorn on Heroku. My application started exhibiting this problem when I added the `--preload` option to my Procfile. When I removed that option, my application resumed functioning as normal.
Not sure whether to add this as an answer to this question or ask a separate question and put this as an answer there. I was getting this exact same error for reasons that are slightly different from the people who have posted and answered. In my setup, I using gunicorn as a wsgi for a Flask application. In this applic...
28,511,485
I am not super experienced in writing code. Could someone help me out? I am trying to write some simple python to work with some GPS coordinates. Basically I want it to check if the gps is +or- ten feet to my a point then print if it is true. Think I got that part figured out but I am not sure about this part. After t...
2015/02/14
[ "https://Stackoverflow.com/questions/28511485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2798178/" ]
Just wrap it in a condition check within the if. Not language specific, but the general idea ``` if <in coord condition> if <not printed condition> print set print condition else clear print condition ```
If your syntax &c were corrected (those strings are definitely wrong) you'd be checking for a square, not a circle. Assuming `point_lat`, `gps_lat`, &c, are all numbers (not strings), and expressed in feet (and assuming `_log` is a typo for `_lon`, standing for "longitude"), you'd need: ``` import math if math.hypot...
28,511,485
I am not super experienced in writing code. Could someone help me out? I am trying to write some simple python to work with some GPS coordinates. Basically I want it to check if the gps is +or- ten feet to my a point then print if it is true. Think I got that part figured out but I am not sure about this part. After t...
2015/02/14
[ "https://Stackoverflow.com/questions/28511485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2798178/" ]
First, you need to revise your check. If you want to check if you are within a 10-foot radius bubble, you need to use Pythagoras, otherwise you are checking if you are within a 20x20-foot square. For example, if you are 9 feet away from the point in both latitude and longitude, that means you are actually 12.73 feet aw...
Just wrap it in a condition check within the if. Not language specific, but the general idea ``` if <in coord condition> if <not printed condition> print set print condition else clear print condition ```
28,511,485
I am not super experienced in writing code. Could someone help me out? I am trying to write some simple python to work with some GPS coordinates. Basically I want it to check if the gps is +or- ten feet to my a point then print if it is true. Think I got that part figured out but I am not sure about this part. After t...
2015/02/14
[ "https://Stackoverflow.com/questions/28511485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2798178/" ]
Just wrap it in a condition check within the if. Not language specific, but the general idea ``` if <in coord condition> if <not printed condition> print set print condition else clear print condition ```
A pragmatic solution would be to have a starting point and calculate individual instances to see if it meets the condition. For expediency let's import **pyproj** to calculate distance on a WGS-84 geoid. ``` #!/usr/bin/env python """ banana """ from pyproj import Geod def do_distance(lat1, lon1, lat2, lon2): "...
28,511,485
I am not super experienced in writing code. Could someone help me out? I am trying to write some simple python to work with some GPS coordinates. Basically I want it to check if the gps is +or- ten feet to my a point then print if it is true. Think I got that part figured out but I am not sure about this part. After t...
2015/02/14
[ "https://Stackoverflow.com/questions/28511485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2798178/" ]
First, you need to revise your check. If you want to check if you are within a 10-foot radius bubble, you need to use Pythagoras, otherwise you are checking if you are within a 20x20-foot square. For example, if you are 9 feet away from the point in both latitude and longitude, that means you are actually 12.73 feet aw...
If your syntax &c were corrected (those strings are definitely wrong) you'd be checking for a square, not a circle. Assuming `point_lat`, `gps_lat`, &c, are all numbers (not strings), and expressed in feet (and assuming `_log` is a typo for `_lon`, standing for "longitude"), you'd need: ``` import math if math.hypot...
28,511,485
I am not super experienced in writing code. Could someone help me out? I am trying to write some simple python to work with some GPS coordinates. Basically I want it to check if the gps is +or- ten feet to my a point then print if it is true. Think I got that part figured out but I am not sure about this part. After t...
2015/02/14
[ "https://Stackoverflow.com/questions/28511485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2798178/" ]
First, you need to revise your check. If you want to check if you are within a 10-foot radius bubble, you need to use Pythagoras, otherwise you are checking if you are within a 20x20-foot square. For example, if you are 9 feet away from the point in both latitude and longitude, that means you are actually 12.73 feet aw...
A pragmatic solution would be to have a starting point and calculate individual instances to see if it meets the condition. For expediency let's import **pyproj** to calculate distance on a WGS-84 geoid. ``` #!/usr/bin/env python """ banana """ from pyproj import Geod def do_distance(lat1, lon1, lat2, lon2): "...
32,884,277
The code is: ``` import sys execfile('test.py') ``` In test.py I have: ``` import zipfile with zipfile.ZipFile('test.jar', 'r') as z: z.extractall("C:\testfolder") ``` This code produces: ``` AttributeError ( ZipFile instance has no attribute '__exit__' ) # edited ``` The code from "test.py" works when ru...
2015/10/01
[ "https://Stackoverflow.com/questions/32884277", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3438538/" ]
I made my code on python 2.7 but when I put it on my server which use 2.6 I have this error : `AttributeError: ZipFile instance has no attribute '__exit__'` For solve this problems I use Sebastian's answer on this post : [Making Python 2.7 code run with Python 2.6](https://stackoverflow.com/questions/21268470/making-...
According to the Python documentation, [`ZipFile.extractall()`](https://docs.python.org/2/library/zipfile.html#zipfile.ZipFile.extractall) was added in version 2.6. I expect that you'll find that you are running a different, older (pre 2.6), version of Python than that which idle is using. You can find out which versio...
41,991,602
I have been trying to make a program that runs over a dictionary which makes anagrams from an inputted string. I found most of the code to this problem here [Algorithm to generate anagrams](https://stackoverflow.com/questions/55210/algorithm-to-generate-anagrams) but i need to have the program only output a line of max...
2017/02/01
[ "https://Stackoverflow.com/questions/41991602", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7503133/" ]
This is a slight work around, however if you only want to *filter* out words that have a length shorter than a specified argument, then you could make a change in your programs main. Your program currently says: ``` for word in words.anagram(letters): print word ``` You could change your program to say: ``` for...
I don't like to make programs `for` programmers, usually. To the best of my understanding: ``` import random word = "scramble" scramble = list(word) for i in range(len(scramble)): char = scramble.pop(i) scramble.insert(random.randint(0,len(word)),char) print(''.join(scramble)) ``` This will scramble the `...
4,145,331
I am tring to call the cmd command "move" from python. ``` cmd1 = ["move", spath , npath] startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW p = subprocess.Popen(cmd1, startupinfo=startupinfo) ``` While the comammand works in the cmd. I can move files. With this py...
2010/11/10
[ "https://Stackoverflow.com/questions/4145331", "https://Stackoverflow.com", "https://Stackoverflow.com/users/354399/" ]
`move` is built-in into the `cmd` shell, so it's not a file command that you can call this way. You could use [`shutil.move()`](http://docs.python.org/library/shutil.html#shutil.move), but this "forgets" all alternate data stream, ACLs etc.
try to use `cmd1 = ["cmd", "/c", "move", spath, npath]`
74,053,822
I want to calculate QTD values from different columns based on months in a pandas dataframe. Code: ``` data = {'month': ['April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December', 'January', 'February', 'March'], 'kpi': ['sales', 'sales quantity', 'sales', 'sales', 'sales', 'sales',...
2022/10/13
[ "https://Stackoverflow.com/questions/74053822", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16134366/" ]
Use [`numpy.select`](https://numpy.org/doc/stable/reference/generated/numpy.select.html) for new column and then use [`GroupBy.cumsum`](http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.cumsum.html): ``` g = pd.to_datetime(df['month'], format='%B').dt.to_period('Q') m1 = df['month'...
You can use a dictionary to map the quarter to your columns, then [indexing lookup](https://pandas.pydata.org/docs/user_guide/indexing.html#indexing-lookup) and [`groupby.cumsum`](https://pandas.pydata.org/docs/reference/api/pandas.core.groupby.DataFrameGroupBy.cumsum.html): ``` quarters = {1: 're9+3', 2: 're', 3: 're...
46,756,555
I made a dictionary using python ``` dictionary = {'key':'a', 'key':'b'}) print(dictionary) print (dictionary.get("key")) ``` When run this code then shows the last value of dictionary, Is there any way to access the first value of dictionary if keys of both elements of dictionary are same.
2017/10/15
[ "https://Stackoverflow.com/questions/46756555", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4450400/" ]
It seems I ran into existing [issue](https://github.com/spring-projects/spring-boot/issues/10647) So I used the solution provided by [@wilkinsona](https://github.com/wilkinsona) to resolve it. I added `configuration` with `mainClass` and project was successfully built. ``` <build> <plugins> <plugin> ...
You can use this way . You add a configuration to pom but this way only works in the compiler. It doesnt work real world. If you want to use .jar or .war . It will not work. **You must add com.lapots.breed.hero.journey file under java file.** Then It always works
46,756,555
I made a dictionary using python ``` dictionary = {'key':'a', 'key':'b'}) print(dictionary) print (dictionary.get("key")) ``` When run this code then shows the last value of dictionary, Is there any way to access the first value of dictionary if keys of both elements of dictionary are same.
2017/10/15
[ "https://Stackoverflow.com/questions/46756555", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4450400/" ]
It seems I ran into existing [issue](https://github.com/spring-projects/spring-boot/issues/10647) So I used the solution provided by [@wilkinsona](https://github.com/wilkinsona) to resolve it. I added `configuration` with `mainClass` and project was successfully built. ``` <build> <plugins> <plugin> ...
I had a similar problem. ``` [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary for springboot-kafka 0.0.1-SNAPSHOT: [INFO] [INFO] springboot-kafka ................................... SUCCESS [ 1.016 s] [INFO] springboot-kafka.model ............................. FA...
46,756,555
I made a dictionary using python ``` dictionary = {'key':'a', 'key':'b'}) print(dictionary) print (dictionary.get("key")) ``` When run this code then shows the last value of dictionary, Is there any way to access the first value of dictionary if keys of both elements of dictionary are same.
2017/10/15
[ "https://Stackoverflow.com/questions/46756555", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4450400/" ]
It seems I ran into existing [issue](https://github.com/spring-projects/spring-boot/issues/10647) So I used the solution provided by [@wilkinsona](https://github.com/wilkinsona) to resolve it. I added `configuration` with `mainClass` and project was successfully built. ``` <build> <plugins> <plugin> ...
I put a configuration (tag) to pom.xml with Reference to main class. That solves the problem. ```html <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>c...
46,756,555
I made a dictionary using python ``` dictionary = {'key':'a', 'key':'b'}) print(dictionary) print (dictionary.get("key")) ``` When run this code then shows the last value of dictionary, Is there any way to access the first value of dictionary if keys of both elements of dictionary are same.
2017/10/15
[ "https://Stackoverflow.com/questions/46756555", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4450400/" ]
I had a similar problem. ``` [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary for springboot-kafka 0.0.1-SNAPSHOT: [INFO] [INFO] springboot-kafka ................................... SUCCESS [ 1.016 s] [INFO] springboot-kafka.model ............................. FA...
You can use this way . You add a configuration to pom but this way only works in the compiler. It doesnt work real world. If you want to use .jar or .war . It will not work. **You must add com.lapots.breed.hero.journey file under java file.** Then It always works
46,756,555
I made a dictionary using python ``` dictionary = {'key':'a', 'key':'b'}) print(dictionary) print (dictionary.get("key")) ``` When run this code then shows the last value of dictionary, Is there any way to access the first value of dictionary if keys of both elements of dictionary are same.
2017/10/15
[ "https://Stackoverflow.com/questions/46756555", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4450400/" ]
I put a configuration (tag) to pom.xml with Reference to main class. That solves the problem. ```html <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>c...
You can use this way . You add a configuration to pom but this way only works in the compiler. It doesnt work real world. If you want to use .jar or .war . It will not work. **You must add com.lapots.breed.hero.journey file under java file.** Then It always works
46,756,555
I made a dictionary using python ``` dictionary = {'key':'a', 'key':'b'}) print(dictionary) print (dictionary.get("key")) ``` When run this code then shows the last value of dictionary, Is there any way to access the first value of dictionary if keys of both elements of dictionary are same.
2017/10/15
[ "https://Stackoverflow.com/questions/46756555", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4450400/" ]
I had a similar problem. ``` [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary for springboot-kafka 0.0.1-SNAPSHOT: [INFO] [INFO] springboot-kafka ................................... SUCCESS [ 1.016 s] [INFO] springboot-kafka.model ............................. FA...
I put a configuration (tag) to pom.xml with Reference to main class. That solves the problem. ```html <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>c...
60,927,188
Having recently upgraded a Django project from 2.x to 3.x, I noticed that the `mysql.connector.django` backend (from `mysql-connector-python`) no longer works. The last version of Django that it works with is 2.2.11. It breaks with 3.0. I am using `mysql-connector-python==8.0.19`. When running `manage.py runserver`, t...
2020/03/30
[ "https://Stackoverflow.com/questions/60927188", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6619548/" ]
For `Django 3.0` and `Django 3.1` I managed to have it working with `mysql-connector-python 8.0.22`. See this <https://dev.mysql.com/doc/relnotes/connector-python/en/news-8-0-22.html>.
Connector/Python still supports Python 2.7, which was dropped by Django 3. We are currently working on adding support for Django 3, stay tunned.
60,927,188
Having recently upgraded a Django project from 2.x to 3.x, I noticed that the `mysql.connector.django` backend (from `mysql-connector-python`) no longer works. The last version of Django that it works with is 2.2.11. It breaks with 3.0. I am using `mysql-connector-python==8.0.19`. When running `manage.py runserver`, t...
2020/03/30
[ "https://Stackoverflow.com/questions/60927188", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6619548/" ]
Connector/Python still supports Python 2.7, which was dropped by Django 3. We are currently working on adding support for Django 3, stay tunned.
in settings.py change database engine this way 'ENGINE': 'django.db.backends.mysql'
60,927,188
Having recently upgraded a Django project from 2.x to 3.x, I noticed that the `mysql.connector.django` backend (from `mysql-connector-python`) no longer works. The last version of Django that it works with is 2.2.11. It breaks with 3.0. I am using `mysql-connector-python==8.0.19`. When running `manage.py runserver`, t...
2020/03/30
[ "https://Stackoverflow.com/questions/60927188", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6619548/" ]
For `Django 3.0` and `Django 3.1` I managed to have it working with `mysql-connector-python 8.0.22`. See this <https://dev.mysql.com/doc/relnotes/connector-python/en/news-8-0-22.html>.
in settings.py change database engine this way 'ENGINE': 'django.db.backends.mysql'
11,144,245
I realize that this is a known [problem](http://python.6.n6.nabble.com/Internationalization-and-caching-not-working-td84364.html), [problem](http://www.mail-archive.com/django-users@googlegroups.com/msg63780.html) but I still have not found and adequate solution. I want to use the @cache\_page for a some views in my D...
2012/06/21
[ "https://Stackoverflow.com/questions/11144245", "https://Stackoverflow.com", "https://Stackoverflow.com/users/791335/" ]
1. How long is a string? It depends on how the server is configured. And "application" could be a single form or hundreds. Only a test can tell. In general: build a [high performance server](http://www.wissel.net/blog/d6plinks/SHWL-7RB3P5) preferably with 64Bit architecture and lots of RAM. Make that RAM [available for...
1. It depends on the server setup, I have i.e XPage extranet with 12000 registered users spanning over aprox 20 XPage applications. That runs on 1 Windows 2003 server with 4GB Ram and quad core cpu. Data aount is about 60GB over these 20 applications. No Daos, no beans just SSJS. Performance is excellent. So when I upg...
62,552,693
I'm a newbie when it comes to Python. I have some python code in an azure sql notebook which gets run by a scheduled job. The job notebook runs a couple of sql notebooks. If the 1st notebook errors I want an exception to be thrown so that the scheduled job shows as failed and I don't want the subsequent sql notebook to...
2020/06/24
[ "https://Stackoverflow.com/questions/62552693", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11989075/" ]
**Option 1**: Simply don't catch the exception. Just run the first command without the `try` ... `except`, and let the exception bubble up in the normal way. If it is raised (i.e. thrown), then the second command (or anything after it) will not be run. You would then only catch exceptions with the second command. ``` ...
Sorry - I did not read the question carefully enough. My original answer is not what you are looking for. I wrote: > > Add a `return` statement: > > > > ``` > try: > # ... > except Exception as error: > print f'Failure in STA_1S ({error})' > return > > ``` > > But you not only want to leave the ...
62,552,693
I'm a newbie when it comes to Python. I have some python code in an azure sql notebook which gets run by a scheduled job. The job notebook runs a couple of sql notebooks. If the 1st notebook errors I want an exception to be thrown so that the scheduled job shows as failed and I don't want the subsequent sql notebook to...
2020/06/24
[ "https://Stackoverflow.com/questions/62552693", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11989075/" ]
Set a flag that shows whether the first notebook succeeded or not: ``` first_notebook_succeeded = False # assume failure try: dbutils.notebook.run("/01. SMETS1Mig/" + dbutils.widgets.get("env_parent_directory") + "/02 Processing Curated Staging/02 Build - Parameterised/STA_1A - CS note Issued", 6000, { "en...
Sorry - I did not read the question carefully enough. My original answer is not what you are looking for. I wrote: > > Add a `return` statement: > > > > ``` > try: > # ... > except Exception as error: > print f'Failure in STA_1S ({error})' > return > > ``` > > But you not only want to leave the ...
62,552,693
I'm a newbie when it comes to Python. I have some python code in an azure sql notebook which gets run by a scheduled job. The job notebook runs a couple of sql notebooks. If the 1st notebook errors I want an exception to be thrown so that the scheduled job shows as failed and I don't want the subsequent sql notebook to...
2020/06/24
[ "https://Stackoverflow.com/questions/62552693", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11989075/" ]
**Option 1**: Simply don't catch the exception. Just run the first command without the `try` ... `except`, and let the exception bubble up in the normal way. If it is raised (i.e. thrown), then the second command (or anything after it) will not be run. You would then only catch exceptions with the second command. ``` ...
Set a flag that shows whether the first notebook succeeded or not: ``` first_notebook_succeeded = False # assume failure try: dbutils.notebook.run("/01. SMETS1Mig/" + dbutils.widgets.get("env_parent_directory") + "/02 Processing Curated Staging/02 Build - Parameterised/STA_1A - CS note Issued", 6000, { "en...
11,026,205
I'm currently concatenating adjacent cells in excel to repeat common HTML elements and divs - it feels like I've gone down a strange excel path in developing my webpage, and I was wondering if an experienced web designer could let me know how I might accomplish my goals for the site with a more conventional method (aim...
2012/06/14
[ "https://Stackoverflow.com/questions/11026205", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1152532/" ]
Wow, that sounds really painful. If all you have is 40 images that you want to generate HTML for, and the rest of your site is static, it may be simplest just to have a single text file with each line containing an image file path. Then, use Python to look at each line, generate the appropriate HTML, and concatenate i...
You could keep these and only these images in their own directory and then use simple shell scripts to generate that section of static html. Assuming you already put the files in place maybe like this: ``` cp <all_teh_kitteh_images> images/grid ``` This command will generate html ``` for file in images/grid/*.jpg ...
24,294,015
I tried to install psycopg2 for python2.6 but my system also has 2.7 installed. I did ``` >sudo -E pip install psycopg2 Downloading/unpacking psycopg2 Downloading psycopg2-2.5.3.tar.gz (690kB): 690kB downloaded Running setup.py (path:/private/var/folders/yw/qn50zv_151bfq2vxhc60l8s5vkymm3/T/pip_build_root/psycopg2...
2014/06/18
[ "https://Stackoverflow.com/questions/24294015", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1312080/" ]
You can use [shoryuken](https://github.com/phstc/shoryuken/). It will consume your messages continuously until your queue has messages. ``` shoryuken -r your_worker.rb -C shoryuken.yml \ -l log/shoryuken.log -p shoryuken.pid -d ```
As you've probably already discovered, there isn't one obvious **right way™** to handle this kind of thing. It depends a lot on what work you do for each job, the size of your app and infrastrucure, and your personal preferences on APIs, message queuing philosophies, and architecture. That said, I'd probably lean towa...
46,582,577
I need help. I'm trying to filter out and write to another csv file that consists of data which collected after 10769s in the column elapsed\_seconds together with the acceleration magnitude. However, I'm getting KeyError: 0... ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt data = pd.read_...
2017/10/05
[ "https://Stackoverflow.com/questions/46582577", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2995019/" ]
change this line ``` csv.write( str(data[data.elapsed_seconds > 10769][i]) + ", " + str(data[data.m][i]) + "\n" ) ``` To this: ``` csv.write( str(data[data.elapsed_seconds > 10769].iloc[i]) + ", " + str(data[data.m].iloc[i]) +"\n" ) ``` Also, notice that you are not increasing `i`, like this `i += 1...
I had the same issue, which was resolved by following this [recommendation](https://github.com/influxdata/influxdb-python/issues/497). In short, instead of `df[0]`, do an explicit `df['columnname']`
72,429,361
Hello I am beginner programmer in python and I am having trouble with this code. It is a rock paper scissors game I am not finished yet but it is supposed to print "I win" if the user does not pick rock when the program picks scissors. But when the program picks paper and the user picks rock it does not print "I win". ...
2022/05/30
[ "https://Stackoverflow.com/questions/72429361", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19223648/" ]
I had same issue with "testImplementation 'io.cucumber:cucumber-java8:7.3.3'" (gradle). I changed to "testImplementation 'io.cucumber:cucumber-java8:7.0.0'" and when I changed it and ran again test then I got a correct error message about the real problem that was "Unrecognized field 'programId'" (for example) and the...
I installed Jackson JDK8 repository in my pom.xml file and it fixed this problem: <https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jdk8>
71,979,765
If I have python list like ```py pyList=[‘x@x.x’,’y@y.y’] ``` And I want it to convert it to json array and add `{}` around every object, it should be like that : ```py arrayJson=[{“email”:”x@x.x”},{“ email”:”y@y.y”}] ``` any idea how to do that ?
2022/04/23
[ "https://Stackoverflow.com/questions/71979765", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18918903/" ]
You can achieve this by using built-in [json](https://docs.python.org/3/library/json.html#json.dumps) module ``` import json arrayJson = json.dumps([{"email": item} for item in pyList]) ```
Try to Google this kind of stuff first. :) ``` import json array = [1, 2, 3] jsonArray = json.dumps(array) ``` By the way, the result you asked for can not be achieved with the list you provided. You need to use python dictionaries to get json objects. The conversion is like below ``` Python -> JSON list -> array...
71,979,765
If I have python list like ```py pyList=[‘x@x.x’,’y@y.y’] ``` And I want it to convert it to json array and add `{}` around every object, it should be like that : ```py arrayJson=[{“email”:”x@x.x”},{“ email”:”y@y.y”}] ``` any idea how to do that ?
2022/04/23
[ "https://Stackoverflow.com/questions/71979765", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18918903/" ]
You can achieve this by using built-in [json](https://docs.python.org/3/library/json.html#json.dumps) module ``` import json arrayJson = json.dumps([{"email": item} for item in pyList]) ```
pip install jsonwhatever. You should try it, you can put anything on it ``` from jsonwhatever import jsonwhatever as jw pyList=['x@x.x','y@y.y'] jsonwe = jw.JsonWhatEver() mytr = jsonwe.jsonwhatever('my_custom_list', pyList) print(mytr) ```
34,328,759
I'd like to put together a command that will print out a string of 32 hexadecimal digits. I've got a Python script that works: ``` python -c 'import random ; print "".join(map(lambda t: format(t, "02X"), [random.randrange(256) for x in range(16)]))' ``` This generates output like: ``` 6EF6B30F9E557F948C402C89002C7C...
2015/12/17
[ "https://Stackoverflow.com/questions/34328759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1002430/" ]
If you are looking for a single command and have openssl installed, see below. Generate random 16 bytes (32 hex symbols) and encode in hex (also -base64 is supported). ``` openssl rand -hex 16 ```
If you want to generate output of **arbitrary length, including even/odd number of characters**: ```sh cat /dev/urandom | hexdump --no-squeezing -e '/1 "%x"' | head -c 31 ``` Or to maximize efficiency over readability/composeability: ``` hexdump --no-squeezing -e '/1 "%x"' -n 15 /dev/urandom ```
34,328,759
I'd like to put together a command that will print out a string of 32 hexadecimal digits. I've got a Python script that works: ``` python -c 'import random ; print "".join(map(lambda t: format(t, "02X"), [random.randrange(256) for x in range(16)]))' ``` This generates output like: ``` 6EF6B30F9E557F948C402C89002C7C...
2015/12/17
[ "https://Stackoverflow.com/questions/34328759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1002430/" ]
If you have `hexdump` then: ``` hexdump -vn16 -e'4/4 "%08X" 1 "\n"' /dev/urandom ``` should do the job. **Explanation:** * `-v` to print all data (by default `hexdump` replaces repetition by `*`). * `-n16` to consume 16 bytes of input (32 hex digits = 16 bytes). * `4/4 "%08X"` to iterate four times, consume 4 byte...
If you want to generate output of **arbitrary length, including even/odd number of characters**: ```sh cat /dev/urandom | hexdump --no-squeezing -e '/1 "%x"' | head -c 31 ``` Or to maximize efficiency over readability/composeability: ``` hexdump --no-squeezing -e '/1 "%x"' -n 15 /dev/urandom ```
34,328,759
I'd like to put together a command that will print out a string of 32 hexadecimal digits. I've got a Python script that works: ``` python -c 'import random ; print "".join(map(lambda t: format(t, "02X"), [random.randrange(256) for x in range(16)]))' ``` This generates output like: ``` 6EF6B30F9E557F948C402C89002C7C...
2015/12/17
[ "https://Stackoverflow.com/questions/34328759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1002430/" ]
If you have `hexdump` then: ``` hexdump -vn16 -e'4/4 "%08X" 1 "\n"' /dev/urandom ``` should do the job. **Explanation:** * `-v` to print all data (by default `hexdump` replaces repetition by `*`). * `-n16` to consume 16 bytes of input (32 hex digits = 16 bytes). * `4/4 "%08X"` to iterate four times, consume 4 byte...
Here is a version not using `dev/random`: ``` awk -v len=32 'BEGIN { srand('$RANDOM'); while(len--) { n=int(rand()*16); printf("%c", n+(n>9 ? 55 : 48)); };}' ```
34,328,759
I'd like to put together a command that will print out a string of 32 hexadecimal digits. I've got a Python script that works: ``` python -c 'import random ; print "".join(map(lambda t: format(t, "02X"), [random.randrange(256) for x in range(16)]))' ``` This generates output like: ``` 6EF6B30F9E557F948C402C89002C7C...
2015/12/17
[ "https://Stackoverflow.com/questions/34328759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1002430/" ]
Here are a few more options, all of which have the nice property of providing an obvious and easy way to directly select the length of the output string. In all the cases below, changing the '32' to your desired string length is all you need to do. ``` #works in bash and busybox, but not in ksh tr -dc 'A-F0-9' < /dev/...
If you want to generate output of **arbitrary length, including even/odd number of characters**: ```sh cat /dev/urandom | hexdump --no-squeezing -e '/1 "%x"' | head -c 31 ``` Or to maximize efficiency over readability/composeability: ``` hexdump --no-squeezing -e '/1 "%x"' -n 15 /dev/urandom ```
34,328,759
I'd like to put together a command that will print out a string of 32 hexadecimal digits. I've got a Python script that works: ``` python -c 'import random ; print "".join(map(lambda t: format(t, "02X"), [random.randrange(256) for x in range(16)]))' ``` This generates output like: ``` 6EF6B30F9E557F948C402C89002C7C...
2015/12/17
[ "https://Stackoverflow.com/questions/34328759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1002430/" ]
If you have `hexdump` then: ``` hexdump -vn16 -e'4/4 "%08X" 1 "\n"' /dev/urandom ``` should do the job. **Explanation:** * `-v` to print all data (by default `hexdump` replaces repetition by `*`). * `-n16` to consume 16 bytes of input (32 hex digits = 16 bytes). * `4/4 "%08X"` to iterate four times, consume 4 byte...
Here are a few more options, all of which have the nice property of providing an obvious and easy way to directly select the length of the output string. In all the cases below, changing the '32' to your desired string length is all you need to do. ``` #works in bash and busybox, but not in ksh tr -dc 'A-F0-9' < /dev/...
34,328,759
I'd like to put together a command that will print out a string of 32 hexadecimal digits. I've got a Python script that works: ``` python -c 'import random ; print "".join(map(lambda t: format(t, "02X"), [random.randrange(256) for x in range(16)]))' ``` This generates output like: ``` 6EF6B30F9E557F948C402C89002C7C...
2015/12/17
[ "https://Stackoverflow.com/questions/34328759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1002430/" ]
If you are looking for a single command and have openssl installed, see below. Generate random 16 bytes (32 hex symbols) and encode in hex (also -base64 is supported). ``` openssl rand -hex 16 ```
Try: ``` xxd -u -l 16 -p /dev/urandom ``` Example output: ``` C298212CD8B55F2E193FFA16165E95E3 ``` And to convert it back to binary: ``` echo -n C298212CD8B55F2E193FFA16165E95E3 | xxd -r -p ```
34,328,759
I'd like to put together a command that will print out a string of 32 hexadecimal digits. I've got a Python script that works: ``` python -c 'import random ; print "".join(map(lambda t: format(t, "02X"), [random.randrange(256) for x in range(16)]))' ``` This generates output like: ``` 6EF6B30F9E557F948C402C89002C7C...
2015/12/17
[ "https://Stackoverflow.com/questions/34328759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1002430/" ]
If you are looking for a single command and have openssl installed, see below. Generate random 16 bytes (32 hex symbols) and encode in hex (also -base64 is supported). ``` openssl rand -hex 16 ```
Here are a few more options, all of which have the nice property of providing an obvious and easy way to directly select the length of the output string. In all the cases below, changing the '32' to your desired string length is all you need to do. ``` #works in bash and busybox, but not in ksh tr -dc 'A-F0-9' < /dev/...
34,328,759
I'd like to put together a command that will print out a string of 32 hexadecimal digits. I've got a Python script that works: ``` python -c 'import random ; print "".join(map(lambda t: format(t, "02X"), [random.randrange(256) for x in range(16)]))' ``` This generates output like: ``` 6EF6B30F9E557F948C402C89002C7C...
2015/12/17
[ "https://Stackoverflow.com/questions/34328759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1002430/" ]
If you have `hexdump` then: ``` hexdump -vn16 -e'4/4 "%08X" 1 "\n"' /dev/urandom ``` should do the job. **Explanation:** * `-v` to print all data (by default `hexdump` replaces repetition by `*`). * `-n16` to consume 16 bytes of input (32 hex digits = 16 bytes). * `4/4 "%08X"` to iterate four times, consume 4 byte...
Try: ``` xxd -u -l 16 -p /dev/urandom ``` Example output: ``` C298212CD8B55F2E193FFA16165E95E3 ``` And to convert it back to binary: ``` echo -n C298212CD8B55F2E193FFA16165E95E3 | xxd -r -p ```
34,328,759
I'd like to put together a command that will print out a string of 32 hexadecimal digits. I've got a Python script that works: ``` python -c 'import random ; print "".join(map(lambda t: format(t, "02X"), [random.randrange(256) for x in range(16)]))' ``` This generates output like: ``` 6EF6B30F9E557F948C402C89002C7C...
2015/12/17
[ "https://Stackoverflow.com/questions/34328759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1002430/" ]
If you are looking for a single command and have openssl installed, see below. Generate random 16 bytes (32 hex symbols) and encode in hex (also -base64 is supported). ``` openssl rand -hex 16 ```
you can also use `od` command like this ``` od -N32 -x < /dev/urandom | head -n1 | cut -b9- | sed 's/ //gi' ``` good luck
34,328,759
I'd like to put together a command that will print out a string of 32 hexadecimal digits. I've got a Python script that works: ``` python -c 'import random ; print "".join(map(lambda t: format(t, "02X"), [random.randrange(256) for x in range(16)]))' ``` This generates output like: ``` 6EF6B30F9E557F948C402C89002C7C...
2015/12/17
[ "https://Stackoverflow.com/questions/34328759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1002430/" ]
Here are a few more options, all of which have the nice property of providing an obvious and easy way to directly select the length of the output string. In all the cases below, changing the '32' to your desired string length is all you need to do. ``` #works in bash and busybox, but not in ksh tr -dc 'A-F0-9' < /dev/...
you can also use `od` command like this ``` od -N32 -x < /dev/urandom | head -n1 | cut -b9- | sed 's/ //gi' ``` good luck
62,175,053
I'm working on Windows 7 64bits with Anaconda 3. On my environment Nifti, I have installed Tensorflow 2.1.0, Keras 2.3.1 and Python 3.7.7. On Visual Studio Code there is a problem with all of these imports: ``` from tensorflow.python.keras.models import Model from tensorflow.keras.layers import Input, Dense, Conv2D, ...
2020/06/03
[ "https://Stackoverflow.com/questions/62175053", "https://Stackoverflow.com", "https://Stackoverflow.com/users/68571/" ]
I had tried your code, and my suggestion is to switch from pylint to other lintings. Keep away from that stupid linting. Maybe you can take a try of flake8: "python.linting.pylintEnabled": false, "python.linting.flake8Enabled": true, This problem occurs because the pylint can't search the path of Anaconda, as 'tensorf...
**If you're using Anaconda Virtual Environment** 1. Close all **Open Terminals** in VS Code 2. Open a new terminal 3. Write the path to your activate folder of Anaconda in Terminal > > Example: `E:/Softwares/AnacondaFolder/Scripts/activate` > > > This should now show **(base)** written at the start of your folde...
14,737,499
I followed the top solution to Flattening an irregular list of lists in python ([Flatten (an irregular) list of lists](https://stackoverflow.com/questions/2158395/flatten-an-irregular-list-of-lists-in-python)) using the following code: ``` def flatten(l): for el in l: if isinstance(el, collections.Iterable...
2013/02/06
[ "https://Stackoverflow.com/questions/14737499", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1009215/" ]
Add a `data-select` attribute to those links: ``` <a href="#contact" data-select="mother@mail.com">Send a mail to mother!</a> <a href="#contact" data-select="father@mail.com">Send a mail to father!</a> <a href="#contact" data-select="sister@mail.com">Send a mail to sister!</a> <a href="#contact" data-select="brother@m...
If the order is allways the same you can do this ``` $("a").click(function(){ $("#recipient").prop("selectedIndex", $(this).index()); }); ``` Otherwise do this by defining the index on the link: ``` <a href="#contact" data-index="0">Send a mail to mother!</a> <a href="#contact" data-index="1">Send a mail to fat...
14,737,499
I followed the top solution to Flattening an irregular list of lists in python ([Flatten (an irregular) list of lists](https://stackoverflow.com/questions/2158395/flatten-an-irregular-list-of-lists-in-python)) using the following code: ``` def flatten(l): for el in l: if isinstance(el, collections.Iterable...
2013/02/06
[ "https://Stackoverflow.com/questions/14737499", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1009215/" ]
If the order is allways the same you can do this ``` $("a").click(function(){ $("#recipient").prop("selectedIndex", $(this).index()); }); ``` Otherwise do this by defining the index on the link: ``` <a href="#contact" data-index="0">Send a mail to mother!</a> <a href="#contact" data-index="1">Send a mail to fat...
Also [there is another way](http://fiddle.jshell.net/FWgan/) using `label` option, which is sure that works also without html5 `data`.
14,737,499
I followed the top solution to Flattening an irregular list of lists in python ([Flatten (an irregular) list of lists](https://stackoverflow.com/questions/2158395/flatten-an-irregular-list-of-lists-in-python)) using the following code: ``` def flatten(l): for el in l: if isinstance(el, collections.Iterable...
2013/02/06
[ "https://Stackoverflow.com/questions/14737499", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1009215/" ]
Add a `data-select` attribute to those links: ``` <a href="#contact" data-select="mother@mail.com">Send a mail to mother!</a> <a href="#contact" data-select="father@mail.com">Send a mail to father!</a> <a href="#contact" data-select="sister@mail.com">Send a mail to sister!</a> <a href="#contact" data-select="brother@m...
Also [there is another way](http://fiddle.jshell.net/FWgan/) using `label` option, which is sure that works also without html5 `data`.
50,925,488
so I have some problems with my dictionaries in python. For example I have dictionary like below: ``` d1 = {123456:xyz, 892019:kjl, 102930491:{[plm,kop]} d2= {xyz:987, kjl: 0902, plm: 019240, kop:09829} ``` And I would like to have nested dictionary that looks something like that. ``` d={123456 :{xyz:987}, 892019:{...
2018/06/19
[ "https://Stackoverflow.com/questions/50925488", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9961204/" ]
If you have two DNS names that can be used as a active/active or active/passive for your API endpoints, you can add them to a Traffic Manager profile and set the routing method you want to use. As indicated in an earlier answer, use only the DNS name and not the protocol identifier (http/https) when you add an endpoint...
Traffic manager only wants the DNS name (FQDN) for external endpoints not the protocol. So drop the http: or https: from your API management address and it will accept that as an external endpoint. Or is your problem not with adding the endpoint, but with the health endpoint monitoring? That can happen as the endpoin...
45,199,083
I am new to python and I had no difficulty with one example of learning try and except blocks: ``` try: 2 + "s" except TypeError: print "There was a type error!" ``` Which outputs what one would expect: ``` There was a type error! ``` However, when trying to catch a syntax error like this: ``` try: p...
2017/07/19
[ "https://Stackoverflow.com/questions/45199083", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5941556/" ]
The reason you can not use a try/except block to capture SyntaxErrors is that these errors happen before your code executes. High level steps of Python code execution 1. Python interpreter translates the Python code into executable instructions. (Syntax Error Raised) 2. Instructions are executed. (Try/Except block ex...
The answer is easy cake: The `SyntaxError` nullifies the `except` and `finally` statement because they are inside of a string.
44,503,913
This is literally day 1 of python for me. I've coded in VBA, Java, and Swift in the past, but I am having a particularly hard time following guides online for coding a pdf scraper. Since I have no idea what I am doing, I keep running into a wall every time I want to test out some of the code I've found online. **Basi...
2017/06/12
[ "https://Stackoverflow.com/questions/44503913", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8149767/" ]
It seems that the tutorials you are following make use of python 2. There are usually few noticable differences, the the biggest is that in python 3, print became a funtion so ``` print() ``` I would recomment either changing you version of python or finding a tutorial for python 3. Hope this helps
Here [Pdfminer python 3.5](https://stackoverflow.com/questions/39854841/pdfminer-python-3-5/40877143#40877143) an example, how to extract informations from a PDF. But it does not solve the problem with tables you want to export to Excel. Commercial products are probably better in doing that...
44,503,913
This is literally day 1 of python for me. I've coded in VBA, Java, and Swift in the past, but I am having a particularly hard time following guides online for coding a pdf scraper. Since I have no idea what I am doing, I keep running into a wall every time I want to test out some of the code I've found online. **Basi...
2017/06/12
[ "https://Stackoverflow.com/questions/44503913", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8149767/" ]
It seems that the tutorials you are following make use of python 2. There are usually few noticable differences, the the biggest is that in python 3, print became a funtion so ``` print() ``` I would recomment either changing you version of python or finding a tutorial for python 3. Hope this helps
I am trying to do this exact same thing! I have been able to convert my pdf to text however the formatting is extremely random and messy and I need the tables to stay in tact to be able to write them into excel data sheets. I am now attempting to convert to XML to see if it will be easier to extract from. If I get anyw...
61,365,111
friends. Yesterday I used the below python piece of code to retrieve some comments on youtube videos sucessfully: ``` !pip install --upgrade google-api-python-client import os import googleapiclient.discovery DEVELOPER_KEY = "my_key" YOUTUBE_API_SERVICE_NAME = "youtube" YOUTUBE_API_VERSION = "v3" youtube = googleap...
2020/04/22
[ "https://Stackoverflow.com/questions/61365111", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13380927/" ]
The problem is on the server side as discussed [here](https://github.com/googleapis/google-api-python-client/issues/882). Until the server problem is fixed, this solution may help (as suggested by [@busunkim96](https://github.com/googleapis/google-api-python-client/issues/882#issuecomment-618514530)): First, download ...
I was able to resolve this issue by putting making putting `static_discovery=False` into the build command Examples: **Previous Code** `self.youtube = googleapiclient.discovery.build(API_SERVICE_NAME, API_VERSION, credentials=creds` **New Code** `self.youtube = googleapiclient.discovery.build(API_SERVICE_NAME, API_V...
47,043,606
I created and saved simple nn in tensorflow: ``` import tensorflow as tf import numpy as np x = tf.placeholder(tf.float32, [1, 1],name='input_placeholder') y = tf.placeholder(tf.float32, [1, 1],name='input_placeholder') W = tf.get_variable('W', [1, 1]) layer = tf.matmul(x, W, name='layer') loss = tf.subtract(y,layer)...
2017/10/31
[ "https://Stackoverflow.com/questions/47043606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1700890/" ]
Just add `save_relative_paths=True` when creating `tf.train.Saver()`: ``` # original code: all_saver = tf.train.Saver() all_saver = tf.train.Saver(save_relative_paths=True) ``` Please refer to [official doc](https://www.tensorflow.org/api_docs/python/tf/train/Saver) for more details.
You could try to restore by: ``` with tf.Session() as sess: saver = tf.train.import_meta_graph(/path/to/test.meta) saver.restore(sess, "path/to/checkpoints/test") ``` In this case, because you put the name of the checkpoint is "test" so you got 3 files: ``` test.data-00000-of-00001 test.index test.meta ```...
47,043,606
I created and saved simple nn in tensorflow: ``` import tensorflow as tf import numpy as np x = tf.placeholder(tf.float32, [1, 1],name='input_placeholder') y = tf.placeholder(tf.float32, [1, 1],name='input_placeholder') W = tf.get_variable('W', [1, 1]) layer = tf.matmul(x, W, name='layer') loss = tf.subtract(y,layer)...
2017/10/31
[ "https://Stackoverflow.com/questions/47043606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1700890/" ]
Just add `save_relative_paths=True` when creating `tf.train.Saver()`: ``` # original code: all_saver = tf.train.Saver() all_saver = tf.train.Saver(save_relative_paths=True) ``` Please refer to [official doc](https://www.tensorflow.org/api_docs/python/tf/train/Saver) for more details.
You could try to open the checkpoint file on notepad and edit it: ``` model_checkpoint_path: "Name-of-saver" all_model_checkpoint_paths: "Name-of-saver" ```
45,385,832
I downloaded nitroshare.tar.gz file as i want to install it on my Kali Linux. I followed up instructions as said on there github page to install it & downloaded all the packages that are required for the installation. When i use cmake command it is showing me this error: ``` Unknown cmake command qt5_wrap_ui ``` H...
2017/07/29
[ "https://Stackoverflow.com/questions/45385832", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8282220/" ]
CMake doesn't know the function `qt5_wrap_ui` because you did not import Qt5 or any of the functions it defines. Before calling `qt5_wrap_ui`, add this: ``` find_package(Qt5 COMPONENTS Widgets REQUIRED) ```
I used this line find\_package(Qt5Widgets) In my Cmakelist.txt file I found this on their Document Page of Qt5
16,300,464
I have two classes in a python source file. ``` class A: def func(self): pass class B: def func(self): pass def run(self): self.func() ``` When my cursor is in class B's `'self.func()'` line, if press `CTRL`+`]`, it goes to class A's func method. But instead I would like it to go B's ...
2013/04/30
[ "https://Stackoverflow.com/questions/16300464", "https://Stackoverflow.com", "https://Stackoverflow.com/users/323000/" ]
The `<C-]>` command jumps to the *first* tag match, but it also takes a `[count]` to jump to another one. Alternatively, you can use the `g<C-]>` command, which (like the `:tjump` Ex command) will list all matches and query you for where you want to jump to (when there are multiple matches).
Have a look at [Jedi-Vim](https://github.com/davidhalter/jedi-vim). It defines a new “go to definition” command, that will properly handle those situations.
3,040,716
I have a list of regexes in python, and a string. Is there an elegant way to check if the at least one regex in the list matches the string? By elegant, I mean something better than simply looping through all of the regexes and checking them against the string and stopping if a match is found. Basically, I had this co...
2010/06/14
[ "https://Stackoverflow.com/questions/3040716", "https://Stackoverflow.com", "https://Stackoverflow.com/users/363078/" ]
``` import re regexes = [ "foo.*", "bar.*", "qu*x" ] # Make a regex that matches if any of our regexes match. combined = "(" + ")|(".join(regexes) + ")" if re.match(combined, mystring): print "Some regex matched!" ```
``` import re regexes = [ # your regexes here re.compile('hi'), # re.compile(...), # re.compile(...), # re.compile(...), ] mystring = 'hi' if any(regex.match(mystring) for regex in regexes): print 'Some regex matched!' ```
3,040,716
I have a list of regexes in python, and a string. Is there an elegant way to check if the at least one regex in the list matches the string? By elegant, I mean something better than simply looping through all of the regexes and checking them against the string and stopping if a match is found. Basically, I had this co...
2010/06/14
[ "https://Stackoverflow.com/questions/3040716", "https://Stackoverflow.com", "https://Stackoverflow.com/users/363078/" ]
``` import re regexes = [ # your regexes here re.compile('hi'), # re.compile(...), # re.compile(...), # re.compile(...), ] mystring = 'hi' if any(regex.match(mystring) for regex in regexes): print 'Some regex matched!' ```
A mix of both Ned's and Nosklo's answers. Works guaranteed for any length of list... hope you enjoy ``` import re raw_lst = ["foo.*", "bar.*", "(Spam.{0,3}){1,3}"] reg_lst = [] for raw_regex in raw_lst: reg_lst.append(re.compile(raw_regex)) mystring = "Spam, Spam, Spam!" if any(compiled_re...
3,040,716
I have a list of regexes in python, and a string. Is there an elegant way to check if the at least one regex in the list matches the string? By elegant, I mean something better than simply looping through all of the regexes and checking them against the string and stopping if a match is found. Basically, I had this co...
2010/06/14
[ "https://Stackoverflow.com/questions/3040716", "https://Stackoverflow.com", "https://Stackoverflow.com/users/363078/" ]
``` import re regexes = [ # your regexes here re.compile('hi'), # re.compile(...), # re.compile(...), # re.compile(...), ] mystring = 'hi' if any(regex.match(mystring) for regex in regexes): print 'Some regex matched!' ```
If you loop over the strings, the time complexity would be O(n). A better approach would be combine those regexes as a regex-trie.
3,040,716
I have a list of regexes in python, and a string. Is there an elegant way to check if the at least one regex in the list matches the string? By elegant, I mean something better than simply looping through all of the regexes and checking them against the string and stopping if a match is found. Basically, I had this co...
2010/06/14
[ "https://Stackoverflow.com/questions/3040716", "https://Stackoverflow.com", "https://Stackoverflow.com/users/363078/" ]
``` import re regexes = [ # your regexes here re.compile('hi'), # re.compile(...), # re.compile(...), # re.compile(...), ] mystring = 'hi' if any(regex.match(mystring) for regex in regexes): print 'Some regex matched!' ```
Here's what I went for based on the other answers: ``` raw_list = ["some_regex","some_regex","some_regex","some_regex"] reg_list = map(re.compile, raw_list) mystring = "some_string" if any(regex.match(mystring) for regex in reg_list): print("matched") ```
3,040,716
I have a list of regexes in python, and a string. Is there an elegant way to check if the at least one regex in the list matches the string? By elegant, I mean something better than simply looping through all of the regexes and checking them against the string and stopping if a match is found. Basically, I had this co...
2010/06/14
[ "https://Stackoverflow.com/questions/3040716", "https://Stackoverflow.com", "https://Stackoverflow.com/users/363078/" ]
``` import re regexes = [ "foo.*", "bar.*", "qu*x" ] # Make a regex that matches if any of our regexes match. combined = "(" + ")|(".join(regexes) + ")" if re.match(combined, mystring): print "Some regex matched!" ```
A mix of both Ned's and Nosklo's answers. Works guaranteed for any length of list... hope you enjoy ``` import re raw_lst = ["foo.*", "bar.*", "(Spam.{0,3}){1,3}"] reg_lst = [] for raw_regex in raw_lst: reg_lst.append(re.compile(raw_regex)) mystring = "Spam, Spam, Spam!" if any(compiled_re...
3,040,716
I have a list of regexes in python, and a string. Is there an elegant way to check if the at least one regex in the list matches the string? By elegant, I mean something better than simply looping through all of the regexes and checking them against the string and stopping if a match is found. Basically, I had this co...
2010/06/14
[ "https://Stackoverflow.com/questions/3040716", "https://Stackoverflow.com", "https://Stackoverflow.com/users/363078/" ]
``` import re regexes = [ "foo.*", "bar.*", "qu*x" ] # Make a regex that matches if any of our regexes match. combined = "(" + ")|(".join(regexes) + ")" if re.match(combined, mystring): print "Some regex matched!" ```
If you loop over the strings, the time complexity would be O(n). A better approach would be combine those regexes as a regex-trie.
3,040,716
I have a list of regexes in python, and a string. Is there an elegant way to check if the at least one regex in the list matches the string? By elegant, I mean something better than simply looping through all of the regexes and checking them against the string and stopping if a match is found. Basically, I had this co...
2010/06/14
[ "https://Stackoverflow.com/questions/3040716", "https://Stackoverflow.com", "https://Stackoverflow.com/users/363078/" ]
``` import re regexes = [ "foo.*", "bar.*", "qu*x" ] # Make a regex that matches if any of our regexes match. combined = "(" + ")|(".join(regexes) + ")" if re.match(combined, mystring): print "Some regex matched!" ```
Here's what I went for based on the other answers: ``` raw_list = ["some_regex","some_regex","some_regex","some_regex"] reg_list = map(re.compile, raw_list) mystring = "some_string" if any(regex.match(mystring) for regex in reg_list): print("matched") ```
3,040,716
I have a list of regexes in python, and a string. Is there an elegant way to check if the at least one regex in the list matches the string? By elegant, I mean something better than simply looping through all of the regexes and checking them against the string and stopping if a match is found. Basically, I had this co...
2010/06/14
[ "https://Stackoverflow.com/questions/3040716", "https://Stackoverflow.com", "https://Stackoverflow.com/users/363078/" ]
A mix of both Ned's and Nosklo's answers. Works guaranteed for any length of list... hope you enjoy ``` import re raw_lst = ["foo.*", "bar.*", "(Spam.{0,3}){1,3}"] reg_lst = [] for raw_regex in raw_lst: reg_lst.append(re.compile(raw_regex)) mystring = "Spam, Spam, Spam!" if any(compiled_re...
If you loop over the strings, the time complexity would be O(n). A better approach would be combine those regexes as a regex-trie.
3,040,716
I have a list of regexes in python, and a string. Is there an elegant way to check if the at least one regex in the list matches the string? By elegant, I mean something better than simply looping through all of the regexes and checking them against the string and stopping if a match is found. Basically, I had this co...
2010/06/14
[ "https://Stackoverflow.com/questions/3040716", "https://Stackoverflow.com", "https://Stackoverflow.com/users/363078/" ]
Here's what I went for based on the other answers: ``` raw_list = ["some_regex","some_regex","some_regex","some_regex"] reg_list = map(re.compile, raw_list) mystring = "some_string" if any(regex.match(mystring) for regex in reg_list): print("matched") ```
A mix of both Ned's and Nosklo's answers. Works guaranteed for any length of list... hope you enjoy ``` import re raw_lst = ["foo.*", "bar.*", "(Spam.{0,3}){1,3}"] reg_lst = [] for raw_regex in raw_lst: reg_lst.append(re.compile(raw_regex)) mystring = "Spam, Spam, Spam!" if any(compiled_re...
3,040,716
I have a list of regexes in python, and a string. Is there an elegant way to check if the at least one regex in the list matches the string? By elegant, I mean something better than simply looping through all of the regexes and checking them against the string and stopping if a match is found. Basically, I had this co...
2010/06/14
[ "https://Stackoverflow.com/questions/3040716", "https://Stackoverflow.com", "https://Stackoverflow.com/users/363078/" ]
Here's what I went for based on the other answers: ``` raw_list = ["some_regex","some_regex","some_regex","some_regex"] reg_list = map(re.compile, raw_list) mystring = "some_string" if any(regex.match(mystring) for regex in reg_list): print("matched") ```
If you loop over the strings, the time complexity would be O(n). A better approach would be combine those regexes as a regex-trie.
71,649,019
I've went through multiple excamples of data classification however either I didn't get it or those are not applicable in my case. I have a list of values: ``` values = [-130,-110,-90,-80,-60,-40] ``` All I need to do is to classify `input` integer value to appropriate "bin". E.g., `input=-97` should get `index 1`...
2022/03/28
[ "https://Stackoverflow.com/questions/71649019", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11191256/" ]
One of your `classes`-props is a `boolean`. You cannot push a `boolean` (true/false) to `className`. You could `console.log(classes)`, then you will see, which prop causes the warning.
It means at least one of the className values is boolean instead of string. we can not say anything more with this piece of code.
71,649,019
I've went through multiple excamples of data classification however either I didn't get it or those are not applicable in my case. I have a list of values: ``` values = [-130,-110,-90,-80,-60,-40] ``` All I need to do is to classify `input` integer value to appropriate "bin". E.g., `input=-97` should get `index 1`...
2022/03/28
[ "https://Stackoverflow.com/questions/71649019", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11191256/" ]
One of your `classes`-props is a `boolean`. You cannot push a `boolean` (true/false) to `className`. You could `console.log(classes)`, then you will see, which prop causes the warning.
I got the same error when i didn't give a value to className attribute like below, probably one of your variable is null or boolean etc. ``` <img className src={...} .../> ```
71,649,019
I've went through multiple excamples of data classification however either I didn't get it or those are not applicable in my case. I have a list of values: ``` values = [-130,-110,-90,-80,-60,-40] ``` All I need to do is to classify `input` integer value to appropriate "bin". E.g., `input=-97` should get `index 1`...
2022/03/28
[ "https://Stackoverflow.com/questions/71649019", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11191256/" ]
It means at least one of the className values is boolean instead of string. we can not say anything more with this piece of code.
I got the same error when i didn't give a value to className attribute like below, probably one of your variable is null or boolean etc. ``` <img className src={...} .../> ```
47,508,790
I have the following JSON saved in a text file called test.xlsx.txt. The JSON is as follows: ``` {"RECONCILIATION": {0: "Successful"}, "ACCOUNT": {0: u"21599000"}, "DESCRIPTION": {0: u"USD to be accrued. "}, "PRODUCT": {0: "7500.0"}, "VALUE": {0: "7500.0"}, "AMOUNT": {0: "7500.0"}, "FORMULA": {0: "3 * 2500 "}} ``` T...
2017/11/27
[ "https://Stackoverflow.com/questions/47508790", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3163920/" ]
Your txt file does not contain valid JSON. For starters, keys must be strings, not numbers. The `u"..."` notation is not valid either. You should fix your JSON first (maybe run it through a linter such as <https://jsonlint.com/> to make sure it's valid).
As Mike mentioned, your text file is not a valid JSON. It should be like: ``` {"RECONCILIATION": {"0": "Successful"}, "ACCOUNT": {"0": "21599000"}, "DESCRIPTION": {"0": "USD to be accrued. "}, "PRODUCT": {"0": "7500.0"}, "VALUE": {"0": "7500.0"}, "AMOUNT": {"0": "7500.0"}, "FORMULA": {"0": "3 * 2500 "}} ``` Note: k...
31,303,728
Using pandas 0.16.2 on python 2.7, OSX. I read a data-frame from a csv file like this: ``` import pandas as pd data = pd.read_csv("my_csv_file.csv",sep='\t', skiprows=(0), header=(0)) ``` The output of `data.dtypes` is: ``` name object weight float64 ethnicity object dtype: object ``` I was expecting...
2015/07/08
[ "https://Stackoverflow.com/questions/31303728", "https://Stackoverflow.com", "https://Stackoverflow.com/users/228177/" ]
There is probably whitespace in your strings, for example, ``` data = pd.DataFrame({'ethnicity':[' Asian', ' Asian']}) data.loc[data['ethnicity'].str.contains('Asian'), 'ethnicity'].tolist() # [' Asian', ' Asian'] print(data[data['ethnicity'].str.contains('Asian')]) ``` yields ``` ethnicity 0 Asian 1 As...
You might try this: ``` data[data['ethnicity'].str.strip()=='Asian'] ```
56,191,697
What is the `__weakrefoffset__` attribute for? What does the integer value signify? ``` >>> int.__weakrefoffset__ 0 >>> class A: ... pass ... >>> A.__weakrefoffset__ 24 >>> type.__weakrefoffset__ 368 >>> class B: ... __slots__ = () ... >>> B.__weakrefoffset__ 0 ``` All types seem to have this attribu...
2019/05/17
[ "https://Stackoverflow.com/questions/56191697", "https://Stackoverflow.com", "https://Stackoverflow.com/users/674039/" ]
In CPython, the layout of a simple type like `float` is three fields: its type pointer, its reference count, and its value (here, a `double`). For `list`, the value is three variables (the pointer to the separately-allocated array, its capacity, and the used size). These types do not support attributes or weak referenc...
It is referenced in [PEP 205](https://www.python.org/dev/peps/pep-0205/) here: > > Many built-in types will participate in the weak-reference management, and any extension type can elect to do so. **The type structure will contain an additional field which provides an offset into the instance structure which contains...
47,013,083
I am trying to establish a Web-Socket connection to a server and enter into receive mode.Once the client starts receiving the data, it immediately closes the connection with below exception ``` webSoc_Received = await websocket.recv() File "/root/envname/lib/python3.6/site-packages/websockets/protocol.py", line...
2017/10/30
[ "https://Stackoverflow.com/questions/47013083", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3913710/" ]
You can use hidden property or `*ngIf` directive : ```html <app-form></app-form> <app-results *ngIf="isOn"></app-results> <app-contact-primary *ngIf="!isOn"></<app-contact-primary> <app-contact-second *ngIf="!isOn"></app-contact-second> <button pButton label="Contact" (click)="isOn= false">Contact</button> <button pB...
Just make the variable true and false ```html <button pButton label="Contact" (click)="isOn = true">Contact</button> <button pButton label="Results" (click)="isOn = false">Results</button> ```
47,013,083
I am trying to establish a Web-Socket connection to a server and enter into receive mode.Once the client starts receiving the data, it immediately closes the connection with below exception ``` webSoc_Received = await websocket.recv() File "/root/envname/lib/python3.6/site-packages/websockets/protocol.py", line...
2017/10/30
[ "https://Stackoverflow.com/questions/47013083", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3913710/" ]
You can use hidden property or `*ngIf` directive : ```html <app-form></app-form> <app-results *ngIf="isOn"></app-results> <app-contact-primary *ngIf="!isOn"></<app-contact-primary> <app-contact-second *ngIf="!isOn"></app-contact-second> <button pButton label="Contact" (click)="isOn= false">Contact</button> <button pB...
Just using it Typescript: ```typescript public show: boolean = false; public buttonName: any = true; toggle() { this.show = !this.show; if(this.show) this.buttonName = false; else this.buttonName = true; } ``` HTML: ```html <div *ngIf="show"> <textarea #todoitem class="></textarea> </d...
73,003,060
I made a simple example of taking a screenshot. I debugged this, but there was an error. cord ``` import pyautogui import PIL pyautogui.screenshot('screenshot.png') ``` error ``` The Pillow package is required to use this function. ``` I've already set up a pillow and version is 9.2.0(lastest version) I'm using...
2022/07/16
[ "https://Stackoverflow.com/questions/73003060", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19560998/" ]
I've just installed everything new and it's fixed!
Try this, it should work perfectly on my side. ``` import pyautogui myScreenshot = pyautogui.screenshot() myScreenshot.save(r'D:\\image.png') ``` [![enter image description here](https://i.stack.imgur.com/7aGpM.png)](https://i.stack.imgur.com/7aGpM.png)
57,813,557
I would like to multiply every element in a numpy array by a constant raised to the power of the index of the array element without a for loop. I am using python 2.7. I am new to this and can use a for loop by trying to not do that for no real reason. This for loop would solve the problem ```py x = 3 for i in range...
2019/09/05
[ "https://Stackoverflow.com/questions/57813557", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12027672/" ]
What you want is something like this: ``` data = [ [{'Status': 'active', 'id': '0f1fb86da9c7ee380'}], [{'Status': 'active', 'id': '0d6b330e4960c3382'}, {'Status': 'active', 'id': '033cfb634e595ccfa'}], [{'Status': 'active', 'id': '0457f623cbb9f7c95'}], [{'Status': 'active', 'id': '01b69eb6a3048f749...
You can also use list comprehension to achieve this. ``` output = [[item["id"] for item in items] for items in data] ```
57,813,557
I would like to multiply every element in a numpy array by a constant raised to the power of the index of the array element without a for loop. I am using python 2.7. I am new to this and can use a for loop by trying to not do that for no real reason. This for loop would solve the problem ```py x = 3 for i in range...
2019/09/05
[ "https://Stackoverflow.com/questions/57813557", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12027672/" ]
What you want is something like this: ``` data = [ [{'Status': 'active', 'id': '0f1fb86da9c7ee380'}], [{'Status': 'active', 'id': '0d6b330e4960c3382'}, {'Status': 'active', 'id': '033cfb634e595ccfa'}], [{'Status': 'active', 'id': '0457f623cbb9f7c95'}], [{'Status': 'active', 'id': '01b69eb6a3048f749...
``` data =json.loads(v_string) for id in data['DBI']: datalist = id['Groups'] i=0 data_list=[] #<-- This was outside above mann for loop. while i < len(datalist): for dic in datalist[i]: if 'active' not in datalist[i][dic]: data_list.append(datalist[i][dic]) print(data_list) ...
57,813,557
I would like to multiply every element in a numpy array by a constant raised to the power of the index of the array element without a for loop. I am using python 2.7. I am new to this and can use a for loop by trying to not do that for no real reason. This for loop would solve the problem ```py x = 3 for i in range...
2019/09/05
[ "https://Stackoverflow.com/questions/57813557", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12027672/" ]
You can also use list comprehension to achieve this. ``` output = [[item["id"] for item in items] for items in data] ```
``` data =json.loads(v_string) for id in data['DBI']: datalist = id['Groups'] i=0 data_list=[] #<-- This was outside above mann for loop. while i < len(datalist): for dic in datalist[i]: if 'active' not in datalist[i][dic]: data_list.append(datalist[i][dic]) print(data_list) ...
1,653,460
What would be the best way to handle lightweight crash recovery for my program? I have a Python program that runs a number of test cases and the results are stored in a dictionary which serves as a cache. If I could save (and then restore) each item that is added to the dictionary, I could simply run the program agai...
2009/10/31
[ "https://Stackoverflow.com/questions/1653460", "https://Stackoverflow.com", "https://Stackoverflow.com/users/165495/" ]
There's no good way to guard against "your program crashing **while** writing a checkpoint to a file", but why should you worry so much about **that**?! What ELSE is your program doing at that time BESIDES "saving checkpoint to a file", that could easily cause it to crash?! It's hard to beat `pickle` (or `cPickle`) fo...
The pickle module supports serializing objects to a file (and loading from file): <http://docs.python.org/library/pickle.html>
1,653,460
What would be the best way to handle lightweight crash recovery for my program? I have a Python program that runs a number of test cases and the results are stored in a dictionary which serves as a cache. If I could save (and then restore) each item that is added to the dictionary, I could simply run the program agai...
2009/10/31
[ "https://Stackoverflow.com/questions/1653460", "https://Stackoverflow.com", "https://Stackoverflow.com/users/165495/" ]
The pickle module supports serializing objects to a file (and loading from file): <http://docs.python.org/library/pickle.html>
**Solution with severe restrictions** If I don't worry about it crashing while writing out and I only want to allow manual termination, I can use standard output to control this. Unfortunately, this can only terminate the program when a control point is reached. This could be solved by creating a new thread to read st...
1,653,460
What would be the best way to handle lightweight crash recovery for my program? I have a Python program that runs a number of test cases and the results are stored in a dictionary which serves as a cache. If I could save (and then restore) each item that is added to the dictionary, I could simply run the program agai...
2009/10/31
[ "https://Stackoverflow.com/questions/1653460", "https://Stackoverflow.com", "https://Stackoverflow.com/users/165495/" ]
There's no good way to guard against "your program crashing **while** writing a checkpoint to a file", but why should you worry so much about **that**?! What ELSE is your program doing at that time BESIDES "saving checkpoint to a file", that could easily cause it to crash?! It's hard to beat `pickle` (or `cPickle`) fo...
One possibility would be to create a number of smaller files ... each representing a subset of the state that you're trying to preserve and each with a checksum or tag indicating that it's complete as the last line/datum of the file (just before the file is closed). If the checksum/tag is good then the rest of the dat...
1,653,460
What would be the best way to handle lightweight crash recovery for my program? I have a Python program that runs a number of test cases and the results are stored in a dictionary which serves as a cache. If I could save (and then restore) each item that is added to the dictionary, I could simply run the program agai...
2009/10/31
[ "https://Stackoverflow.com/questions/1653460", "https://Stackoverflow.com", "https://Stackoverflow.com/users/165495/" ]
There's no good way to guard against "your program crashing **while** writing a checkpoint to a file", but why should you worry so much about **that**?! What ELSE is your program doing at that time BESIDES "saving checkpoint to a file", that could easily cause it to crash?! It's hard to beat `pickle` (or `cPickle`) fo...
Pickle/cPickle have problems. I use the JSON module to serialize objects out. I like it because not only does it work on any OS, but it will work fine in other programming languages, too; many other languages and platforms have readily-accessible JSON deserialization support, which makes it easy to use the same objec...
1,653,460
What would be the best way to handle lightweight crash recovery for my program? I have a Python program that runs a number of test cases and the results are stored in a dictionary which serves as a cache. If I could save (and then restore) each item that is added to the dictionary, I could simply run the program agai...
2009/10/31
[ "https://Stackoverflow.com/questions/1653460", "https://Stackoverflow.com", "https://Stackoverflow.com/users/165495/" ]
There's no good way to guard against "your program crashing **while** writing a checkpoint to a file", but why should you worry so much about **that**?! What ELSE is your program doing at that time BESIDES "saving checkpoint to a file", that could easily cause it to crash?! It's hard to beat `pickle` (or `cPickle`) fo...
**Solution with severe restrictions** If I don't worry about it crashing while writing out and I only want to allow manual termination, I can use standard output to control this. Unfortunately, this can only terminate the program when a control point is reached. This could be solved by creating a new thread to read st...
1,653,460
What would be the best way to handle lightweight crash recovery for my program? I have a Python program that runs a number of test cases and the results are stored in a dictionary which serves as a cache. If I could save (and then restore) each item that is added to the dictionary, I could simply run the program agai...
2009/10/31
[ "https://Stackoverflow.com/questions/1653460", "https://Stackoverflow.com", "https://Stackoverflow.com/users/165495/" ]
One possibility would be to create a number of smaller files ... each representing a subset of the state that you're trying to preserve and each with a checksum or tag indicating that it's complete as the last line/datum of the file (just before the file is closed). If the checksum/tag is good then the rest of the dat...
**Solution with severe restrictions** If I don't worry about it crashing while writing out and I only want to allow manual termination, I can use standard output to control this. Unfortunately, this can only terminate the program when a control point is reached. This could be solved by creating a new thread to read st...
1,653,460
What would be the best way to handle lightweight crash recovery for my program? I have a Python program that runs a number of test cases and the results are stored in a dictionary which serves as a cache. If I could save (and then restore) each item that is added to the dictionary, I could simply run the program agai...
2009/10/31
[ "https://Stackoverflow.com/questions/1653460", "https://Stackoverflow.com", "https://Stackoverflow.com/users/165495/" ]
Pickle/cPickle have problems. I use the JSON module to serialize objects out. I like it because not only does it work on any OS, but it will work fine in other programming languages, too; many other languages and platforms have readily-accessible JSON deserialization support, which makes it easy to use the same objec...
**Solution with severe restrictions** If I don't worry about it crashing while writing out and I only want to allow manual termination, I can use standard output to control this. Unfortunately, this can only terminate the program when a control point is reached. This could be solved by creating a new thread to read st...
34,460,369
I had a bunch of bash scripts in a directory that I "backed up" doing `$ tail -n +1 -- *.sh` The output of that tail is something like: ``` ==> do_stuff.sh <== #! /bin/bash cd ~/my_dir source ~/my_dir/bin/activate python scripts/do_stuff.py ==> do_more_stuff.sh <== #! /bin/bash cd ~/my_dir python scripts/do_more_stu...
2015/12/25
[ "https://Stackoverflow.com/questions/34460369", "https://Stackoverflow.com", "https://Stackoverflow.com/users/845169/" ]
Presume your backup file is named backup.txt ``` perl -ne "if (/==> (\S+) <==/){open OUT,'>',$1;next}print OUT $_" backup.txt ``` Above version is for Windows fixed version on \*nix: ``` perl -ne 'if (/==> (\S+) <==/){open OUT,">",$1;next}print OUT $_' backup.txt ```
``` #!/bin/bash while read -r line; do if [[ $line =~ ^==\>[[:space:]](.*)[[:space:]]\<==$ ]]; then out="${BASH_REMATCH[1]}" continue fi printf "%s\n" "$line" >> "$out" done < backup.txt ``` Drawback: extra blank line at the end of every created file except the last one.
14,075,337
I have a csv file with date, time., price, mag, signal. 62035 rows; there are 42 times of day associated to each unique date in the file. For each date, when there is an 'S' in the signal column append the corresponding price at the time the 'S' occurred. Below is the attempt. ``` from pandas import * from numpy imp...
2012/12/28
[ "https://Stackoverflow.com/questions/14075337", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1374969/" ]
Try something like this: ``` for i in range(len(idf.index)): value = idf.index[i][0] ``` Same thing for the iteration with the `j` index variable. As has been pointed, you can't reference the iteration index in the expression to be iterated, and besides you need to perform a very specific iteration (traversing ove...
It's because `i` is not yet defined, just like the error message says. In this line: ``` for i in idf.index[i][0]: ``` You are telling the Python interpreter to iterate over all the values yielded by the list returning from the expression `idf.index[i][0]` but you have not yet defined what `i` is (although you are ...
14,075,337
I have a csv file with date, time., price, mag, signal. 62035 rows; there are 42 times of day associated to each unique date in the file. For each date, when there is an 'S' in the signal column append the corresponding price at the time the 'S' occurred. Below is the attempt. ``` from pandas import * from numpy imp...
2012/12/28
[ "https://Stackoverflow.com/questions/14075337", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1374969/" ]
This is what I think you're trying to accomplish based on your edit: for every date in your CSV file, group the date along with a list of prices for each item with a signal of "S". You didn't include any sample data in your question, so I made a test one that I hope matches the format you described: ``` 12/28/2012,1:...
It's because `i` is not yet defined, just like the error message says. In this line: ``` for i in idf.index[i][0]: ``` You are telling the Python interpreter to iterate over all the values yielded by the list returning from the expression `idf.index[i][0]` but you have not yet defined what `i` is (although you are ...
14,075,337
I have a csv file with date, time., price, mag, signal. 62035 rows; there are 42 times of day associated to each unique date in the file. For each date, when there is an 'S' in the signal column append the corresponding price at the time the 'S' occurred. Below is the attempt. ``` from pandas import * from numpy imp...
2012/12/28
[ "https://Stackoverflow.com/questions/14075337", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1374969/" ]
Using @Max Fellows' handy example data, we can have a look at it in `pandas`. [BTW, you should always try to provide a short, self-contained, correct example (see [here](http://sscce.org/) for more details), so that the people trying to help you don't have to spend time coming up with one.] First, `import pandas as pd...
It's because `i` is not yet defined, just like the error message says. In this line: ``` for i in idf.index[i][0]: ``` You are telling the Python interpreter to iterate over all the values yielded by the list returning from the expression `idf.index[i][0]` but you have not yet defined what `i` is (although you are ...
14,075,337
I have a csv file with date, time., price, mag, signal. 62035 rows; there are 42 times of day associated to each unique date in the file. For each date, when there is an 'S' in the signal column append the corresponding price at the time the 'S' occurred. Below is the attempt. ``` from pandas import * from numpy imp...
2012/12/28
[ "https://Stackoverflow.com/questions/14075337", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1374969/" ]
Using @Max Fellows' handy example data, we can have a look at it in `pandas`. [BTW, you should always try to provide a short, self-contained, correct example (see [here](http://sscce.org/) for more details), so that the people trying to help you don't have to spend time coming up with one.] First, `import pandas as pd...
Try something like this: ``` for i in range(len(idf.index)): value = idf.index[i][0] ``` Same thing for the iteration with the `j` index variable. As has been pointed, you can't reference the iteration index in the expression to be iterated, and besides you need to perform a very specific iteration (traversing ove...