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
42,512,141
I have written the following simple program which should print out all events detected by `pygame.event.get()`. ``` import pygame, sys from pygame.locals import * display = pygame.display.set_mode((300, 300)) pygame.init() while True: for event in pygame.event.get(): print(event) if event.type ==...
2017/02/28
[ "https://Stackoverflow.com/questions/42512141", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4191155/" ]
For anyone still struggling with this, the issue is documented here on git and is fixed. <https://github.com/pygame/pygame/issues/203> Just uninstall pygame from your venv, then install below version. ``` pip install -U https://github.com/pygame/pygame/archive/master.zip ``` Just tried this and can finally use key ...
Firstly i doubt you are but pygame only registers inputs when your focused on the pygame screen so there's that. I don't have a direct answer to your question so sorry but i do have my solution or work around to it. Because i dislike the normal event system i use pygame.key.get\_pressed() (<https://www.pygame.org/docs/...
42,512,141
I have written the following simple program which should print out all events detected by `pygame.event.get()`. ``` import pygame, sys from pygame.locals import * display = pygame.display.set_mode((300, 300)) pygame.init() while True: for event in pygame.event.get(): print(event) if event.type ==...
2017/02/28
[ "https://Stackoverflow.com/questions/42512141", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4191155/" ]
For anyone still struggling with this, the issue is documented here on git and is fixed. <https://github.com/pygame/pygame/issues/203> Just uninstall pygame from your venv, then install below version. ``` pip install -U https://github.com/pygame/pygame/archive/master.zip ``` Just tried this and can finally use key ...
If you're working in a virtualenv, don't use the `virtualenv` command. Use `python3 -m venv`. Then install pygame (*e.g.* `pip3 install hg+http://bitbucket.org/pygame/pygame`). See [this thread](https://bitbucket.org/pygame/pygame/issues/203/window-does-not-get-focus-on-os-x-with#comment-32656108) for more details o...
1,206,215
In python I can use os.getpid() and os.name() to get information about the Process ID and OS name. Is there something similar in C++? I tried GetProcessId() but was told that this is undeclared... I am using Cygwin under windows. Thank you
2009/07/30
[ "https://Stackoverflow.com/questions/1206215", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Standard C++ has no such functionality. You need to use OS specific features to get this. In your case, you need to look up POSIX/UNIX functions such as [getpid()](http://www.opengroup.org/onlinepubs/009695399/functions/getpid.html). Note that if you actually do want to call the Windows functions to get process ID etc...
To use [GetProcessId](http://msdn.microsoft.com/en-us/library/ms683215(VS.85).aspx) you need to include Windows.h and link to Kernel32.lib. See [Process and Thread Functions](http://msdn.microsoft.com/en-us/library/ms684847(VS.85).aspx) for more information. I use [MSYS/mingw](http://www.mingw.org/) instead of [cygwin...
1,206,215
In python I can use os.getpid() and os.name() to get information about the Process ID and OS name. Is there something similar in C++? I tried GetProcessId() but was told that this is undeclared... I am using Cygwin under windows. Thank you
2009/07/30
[ "https://Stackoverflow.com/questions/1206215", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Standard C++ has no such functionality. You need to use OS specific features to get this. In your case, you need to look up POSIX/UNIX functions such as [getpid()](http://www.opengroup.org/onlinepubs/009695399/functions/getpid.html). Note that if you actually do want to call the Windows functions to get process ID etc...
I recommend Hart's book "Win32 System Programming". Great discussion about how to manage processes, memory, files etc in Kernel32, if you're just starting to look at Windows programming. You can also get a free version of Visual Studio (<http://www.microsoft.com/express/>).
1,206,215
In python I can use os.getpid() and os.name() to get information about the Process ID and OS name. Is there something similar in C++? I tried GetProcessId() but was told that this is undeclared... I am using Cygwin under windows. Thank you
2009/07/30
[ "https://Stackoverflow.com/questions/1206215", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
To use [GetProcessId](http://msdn.microsoft.com/en-us/library/ms683215(VS.85).aspx) you need to include Windows.h and link to Kernel32.lib. See [Process and Thread Functions](http://msdn.microsoft.com/en-us/library/ms684847(VS.85).aspx) for more information. I use [MSYS/mingw](http://www.mingw.org/) instead of [cygwin...
I recommend Hart's book "Win32 System Programming". Great discussion about how to manage processes, memory, files etc in Kernel32, if you're just starting to look at Windows programming. You can also get a free version of Visual Studio (<http://www.microsoft.com/express/>).
24,435,697
Python 3.4: From reading some other SO questions it seems that if a `moduleName.py` file is outside of your current directory, if you want to import it you must add it to the path with `sys.path.insert(0, '/path/to/application/app/folder')`, otherwise an `import moduelName` statement results in this error: ``` Import...
2014/06/26
[ "https://Stackoverflow.com/questions/24435697", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3462076/" ]
Python adds the directory where the initial script resides as first item to [`sys.path`](https://docs.python.org/3/library/sys.html#sys.path): > > As initialized upon program startup, the first item of this list, `path[0]`, is the directory containing the script that was used to invoke the Python interpreter. If the ...
I have faced same problem when running python script from Intellij Idea. There is a script in a ``` C:\Users\user\IdeaProjects\Meshtastic-python\meshtastic ``` It uses ``` from meshtastic import portnums_pb2, channel_pb2, config_pb2 ``` and fails. I have realized that it looks for ``` C:\Users\user\IdeaProjects\...
29,333,578
From work i got a job to make a python script which will click for testing the product of a "secret application" for windows 8.1. The problem is that i can make it move the cursor but it can't click and i searched for win32 documentation on the internet but with no luck. Anyone who had this problem? This is the click ...
2015/03/29
[ "https://Stackoverflow.com/questions/29333578", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2984950/" ]
`body` is a string. You have to parse it as JSON first: ``` res.json(JSON.parse(body)._links.self); ```
This question is little old, yet, the following also seems more helpful. In request, you can pass `json: true` and request library returns you the json object. replace following line, > > > ``` > request('https://api.twitch.tv/kraken/streams/' + req.params.user, function ( error, response, body) { > > ``` > > w...
12,578,943
I'm writing a program to get a video feed from a web cam and display it in a Tkinter window. I wrote the following code which I ran on Ubuntu 12.04. ``` #!/usr/bin/env python import sys, os, gobject from Tkinter import * import pygst pygst.require("0.10") import gst # Goto GUI Class class Prototype(Frame): def _...
2012/09/25
[ "https://Stackoverflow.com/questions/12578943", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1696565/" ]
It looks like your Prototype class is a Tkinter Frame but you don't seem to have packed/placed it anywhere. ``` ... app = Prototype(root) app.pack(expand=YES, fill=BOTH) root.mainloop() ```
I finally came up with a solution to the question. I realised that the error was in the line imagesink.set\_xwindow\_id(self.movie\_window.window.xid) which I changed to imagesink.set\_xwindow\_id(self.movie\_window.winfo\_id()) The mistake is that I had used window.xid which is an attribute for gtk widgets. In tki...
28,422,787
Using python 3, how would you change this code to print the sum of all numbers from 1 to 20? ``` n = 20 i=0 sum = 0 for i in range (1,n+1): sum =+ i i = i+1 print(sum) ```
2015/02/10
[ "https://Stackoverflow.com/questions/28422787", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4548170/" ]
The simplest way I can think about is: ``` sum(range(1, 21)) # includes 20 ``` You can also use a loop: ``` s = 0 for i in range(21): s += i ```
``` n = 20 # this isn't needed, the for loop sets i: i = 0 sum = 0 for i in range (1, n+1): sum += i # Remove this line: i = i+1 # for i in range already increments i print(sum) ``` You shouldn't use the variable name `sum` because there is already a builtin function `sum` which you can even use instead.
24,213,905
I have account in Openshift. I use Django and Mysql in this account. <https://github.com/ogurchik/pullover/tree/master/wsgi/openshift>. I created models for a new table in the Mysql database. When I execute the command `python manage.py sqlall MY_APP`, it renders this log: ``` BEGIN; CREATE TABLE `books_publisher` ( ...
2014/06/13
[ "https://Stackoverflow.com/questions/24213905", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2966342/" ]
Correct. The timestamp is a UNIX timestamp. That is - the number of whole seconds since Jan 1, 1970 UTC, not accounting for leap seconds. You can verify the timestamp using a site like [epochconverter.com](http://www.epochconverter.com/) ``` 1388613600 = 2014-01-01T22:00:00Z ``` Then you can check the time zone det...
As Marc B mentioned, `date('r', 1388613600)` returned a formatted version of the date including the timezone offset which was set to `+0000`. The output is in fact UTC. Thanks Marc!
32,046,360
I'm using wxpython with wx.Grid... I have a general grid with many columns -created with `SetColumn(self, column)` , I want to be able to show and hide specific columns based on user security permission. I read that `self.SetColMinimalAcceptableWidth(0)` might be useful? How do I use it on specific column? How do I re...
2015/08/17
[ "https://Stackoverflow.com/questions/32046360", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2131325/" ]
The Grid manual has the following entry: HideCol(self, col) ``` Hides the specified column. To show the column later you need to call SetColSize with non-0 width or ShowCol to restore the previous column width. If the column is already hidden, this method doesn’t do anything. Parameters: col (int) – The column ind...
Under wxPython 2.8: ``` grid.SetColMinimalAcceptableWidth(0) grid.SetColSize(col, 0) grid.ForceRefresh() ```
15,904,973
Say i store a password in plain text in a variable called `passWd` as a string. How does python release this variable once i discard of it (for instance, with `del passWd` or `passWd= 'new random data'`)? Is the string stored as a byte-array meaning it can be overwritten in the memoryplace that it originally existed o...
2013/04/09
[ "https://Stackoverflow.com/questions/15904973", "https://Stackoverflow.com", "https://Stackoverflow.com/users/929999/" ]
Unless you use custom coded input methods to get the password, it will be in many more places then just your immutable string. So don't worry too much. The OS should take care that any data from your process is cleared before the memory is allocated to another process. This may of course fail if the page is copied to ...
I finally whent with two solutions. ld\_preload to replace the functionality of the string handling of Python on a lower level. One other option which is a bit easier was to develop my own C library that has more functionality then what Python offers through the standard string handling. Mainly the C code has a shread...
3,422,775
I have written a small Django App, that executes an interactive program based on user input and returns the output as the result. But for some reason, the subprocess hangs. On verification of the logs I found that a place where a '\n' has to be given as response to a challenge, the response seems to have never been mad...
2010/08/06
[ "https://Stackoverflow.com/questions/3422775", "https://Stackoverflow.com", "https://Stackoverflow.com/users/412888/" ]
This is because code is JITted on a per-method basis, so when you first try to invoke `CheckCrystal()`, .NET first tries to compile it, subsequently loading all required and not-yet-loaded assemblies. .NET allows you to intercept a moment when assembly resolution fails. To do so, subscribe to `AppDomain.AssemblyResolv...
You would probably want to handle the `AppDomain.AssemblyResolve` event. More information [here](http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve(VS.71).aspx). A quick and dirty example: ``` AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; private static Assembly Cu...
3,422,775
I have written a small Django App, that executes an interactive program based on user input and returns the output as the result. But for some reason, the subprocess hangs. On verification of the logs I found that a place where a '\n' has to be given as response to a challenge, the response seems to have never been mad...
2010/08/06
[ "https://Stackoverflow.com/questions/3422775", "https://Stackoverflow.com", "https://Stackoverflow.com/users/412888/" ]
This is because code is JITted on a per-method basis, so when you first try to invoke `CheckCrystal()`, .NET first tries to compile it, subsequently loading all required and not-yet-loaded assemblies. .NET allows you to intercept a moment when assembly resolution fails. To do so, subscribe to `AppDomain.AssemblyResolv...
> > Is like .Net knows that it will need the assembly before needing it. Is this true? > > > To improve startup performance the CLR lazily loads assemblies. Either manually load or handle [`AppDomain.AssemblyResolve`](http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx) event.
65,942,206
![My code](https://i.stack.imgur.com/QMrBx.png) ![the output](https://i.stack.imgur.com/r5kqL.png) can anyone help me? im pretty new to python and im trying to generate 10 files, each with increasingly harder questions. this code is for difficult 2. I dont want the answers in dif. 2 to be negative so whenever i get a...
2021/01/28
[ "https://Stackoverflow.com/questions/65942206", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15100687/" ]
Your issue is that you're casting your random numbers to a string **before** comparing their mathematical values. You need to compare them as integers then cast them to strings.
I believe this is because you are checking for comparison between 2 strings not 2 integers. This will give bad results for this type of program num1 = str(r.choice(numbers)) num2 = str(r.choice(numbers)) Here you are storing strings and not integers. and then below this you are checking if num1 <= num2. Convert them...
38,657,109
I am using *Python 3.4*. I have a Python script `myscript.py` : ``` import sys def returnvalue(str) : if str == "hi" : return "yes" else : return "no" print("calling python function with parameters:") print(sys.argv[1]) str = sys.argv[1] res = returnvalue(str) target = open("file.txt", 'w') ta...
2016/07/29
[ "https://Stackoverflow.com/questions/38657109", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6013429/" ]
Have you looked at these? They suggest different ways of doing this: [Call Python code from Java by passing parameters and results](https://stackoverflow.com/questions/27235286/call-python-code-from-java-by-passing-parameters-and-results) [How to call a python method from a java class?](https://stackoverflow.com/ques...
calling python from java with Argument and print python output in java console can be done with below simple method: ``` String pathPython = "pathtopython\\script.py"; String [] cmd = new String[3]; cmd[0] = "python"; cmd[1] = pathPython; cmd[2] = arg1; Runtime r = Runtime.getRuntime(); Process p = r.exec(cmd); Buffer...
38,657,109
I am using *Python 3.4*. I have a Python script `myscript.py` : ``` import sys def returnvalue(str) : if str == "hi" : return "yes" else : return "no" print("calling python function with parameters:") print(sys.argv[1]) str = sys.argv[1] res = returnvalue(str) target = open("file.txt", 'w') ta...
2016/07/29
[ "https://Stackoverflow.com/questions/38657109", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6013429/" ]
Have you looked at these? They suggest different ways of doing this: [Call Python code from Java by passing parameters and results](https://stackoverflow.com/questions/27235286/call-python-code-from-java-by-passing-parameters-and-results) [How to call a python method from a java class?](https://stackoverflow.com/ques...
Below is the python method with three sample arguments which can later be called through java. ``` #Sample python method with arguments import sys def getDataFromJava(arg1,arg2,arg3): arg1_val="Hi"+arg1 arg2_val=arg2 arg3_val=arg3 print(arg1_val) print(arg2_val) print(arg3_val) return a...
50,268,691
I am trying to train my binary classifier over a huge data. Previously, I could accomplish training via using fit method of sklearn. But now, I have more data and I cannot cope with them. I am trying to fitting them partially but couldn't get rid of errors. How can I train my huge data incrementally? With applying my p...
2018/05/10
[ "https://Stackoverflow.com/questions/50268691", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9079119/" ]
A `Pipeline` object from scikit-learn does not have the `partial_fit`, as seen in [the docs](http://scikit-learn.org/stable/modules/generated/sklearn.pipeline.Pipeline.html). The reason for this is that you can add any estimator you want to that `Pipeline` object, and not all of them implement the `partial_fit`. [Here...
I was going through the same problem as `SGDClassifier` inside pipeline doesn't support the incremental learning (i.e. partial\_fit param). There is a way we could do incremental learning using sklearn but it is not with `partial_fit`, it is with `warm_start`. There are two algorithms in sklearn `LogisticRegression` an...
50,268,691
I am trying to train my binary classifier over a huge data. Previously, I could accomplish training via using fit method of sklearn. But now, I have more data and I cannot cope with them. I am trying to fitting them partially but couldn't get rid of errors. How can I train my huge data incrementally? With applying my p...
2018/05/10
[ "https://Stackoverflow.com/questions/50268691", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9079119/" ]
A `Pipeline` object from scikit-learn does not have the `partial_fit`, as seen in [the docs](http://scikit-learn.org/stable/modules/generated/sklearn.pipeline.Pipeline.html). The reason for this is that you can add any estimator you want to that `Pipeline` object, and not all of them implement the `partial_fit`. [Here...
pipeline has no attribute partial\_fit as there are many models with no partial\_fit which can be assigned to the pipeline. My solution for this is to make a dictionary rather than pipeline and save it as joblib. ``` from sklearn.feature_extraction.text import CountVectorizer count_vect = CountVectorizer() from sklea...
50,268,691
I am trying to train my binary classifier over a huge data. Previously, I could accomplish training via using fit method of sklearn. But now, I have more data and I cannot cope with them. I am trying to fitting them partially but couldn't get rid of errors. How can I train my huge data incrementally? With applying my p...
2018/05/10
[ "https://Stackoverflow.com/questions/50268691", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9079119/" ]
I was going through the same problem as `SGDClassifier` inside pipeline doesn't support the incremental learning (i.e. partial\_fit param). There is a way we could do incremental learning using sklearn but it is not with `partial_fit`, it is with `warm_start`. There are two algorithms in sklearn `LogisticRegression` an...
pipeline has no attribute partial\_fit as there are many models with no partial\_fit which can be assigned to the pipeline. My solution for this is to make a dictionary rather than pipeline and save it as joblib. ``` from sklearn.feature_extraction.text import CountVectorizer count_vect = CountVectorizer() from sklea...
15,930,203
I am using **zbarimg** to scan bar codes, I want to redirect the output to a python script. How can I redirect the output of the following command: ``` zbarimg code.png ``` to a python script, and what should be the script like? I tried the following script: ``` #!/usr/local/bin/python s = raw_input() print s ```...
2013/04/10
[ "https://Stackoverflow.com/questions/15930203", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1251851/" ]
Using the pipe operator `|` from the command is correct, actually. Did it not work? You might need to explicitly specify the path for the python script as in ``` zbarimg code.png | ./in.py ``` and as @dogbane says, reading from stdin like `sys.stdin.readlines()` is better than using `raw_input`
Use [`sys.stdin`](http://docs.python.org/2/library/sys.html#sys.stdin) to read from stdin in your python script. For example: ``` import sys data = sys.stdin.readlines() ```
15,930,203
I am using **zbarimg** to scan bar codes, I want to redirect the output to a python script. How can I redirect the output of the following command: ``` zbarimg code.png ``` to a python script, and what should be the script like? I tried the following script: ``` #!/usr/local/bin/python s = raw_input() print s ```...
2013/04/10
[ "https://Stackoverflow.com/questions/15930203", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1251851/" ]
Using the pipe operator `|` from the command is correct, actually. Did it not work? You might need to explicitly specify the path for the python script as in ``` zbarimg code.png | ./in.py ``` and as @dogbane says, reading from stdin like `sys.stdin.readlines()` is better than using `raw_input`
I had to invoke the python program command as `somecommand | python mypythonscript.py` instead of `somecommand | ./mypythonscript.py`. This worked for me. The latter produced errors. My purpose: Sum up the durations of all mp3 files by piping output of `soxi -D *mp3` into python: `soxi -D *mp3 | python sum_durations....
45,430,966
why are function considered data type in lua? you can assign functions to variables and pass them as arguments in python too but there is no function data type in python.
2017/08/01
[ "https://Stackoverflow.com/questions/45430966", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4931135/" ]
I think you are mistaken. If you take a look into <https://docs.python.org/2/reference/datamodel.html#types> You'll find that Python even has multiple function types. Callable types: * user defined function * user defined methods * generator functions * built-in functions * built-in methods * ... There are further...
Python does actually have a function type, its just called `lambda`. In both of these programming languages, functions are first-class values which is just a fancy way of saying you can pass them around to functions just like numbers or strings. It makes it possible to use [functional programming](https://en.wikipedia....
53,863,318
First, I was able to fix the ImportError. I figured out that it was because the Django version of pythonanywhere is not updated, So I upgraded Django on pythonanywhere from 1.x.x to 2.0.9. The error came out like this: > > ImportError at / > cannot import name 'path' > > > ``` django version: 1.x.x python versi...
2018/12/20
[ "https://Stackoverflow.com/questions/53863318", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10665552/" ]
The problem as I see has to be with the database and django migrations. The `Post` object inside the blog has the attribute that django's trying to find. The migrations haven't been correctly applied to the database. Now considering the history of migrations, I do not know what's going wrong unless I can look aroun...
Don't forget to refresh your production server after every migration if you want the changes to take effect
11,226,252
Is there a way to loop in `while` if you start the script with `python -c`? This doesn't seem to be related to platform or python version... **Linux** ``` [mpenning@Hotcoffee ~]$ python -c "import os;while (True): os.system('ls')" File "<string>", line 1 import os;while (True): os.system('ls') ...
2012/06/27
[ "https://Stackoverflow.com/questions/11226252", "https://Stackoverflow.com", "https://Stackoverflow.com/users/667301/" ]
Multiline statements may not start after a statement-separating `;` in Python – otherwise, there might be ambiguities about the code blocks. Simply use line breaks in stead of `;`. This "works" on Linux: ``` $ python -c "import os while True: os.system('ls')" ``` Not sure how to enter this on Windows, but why not si...
Don't know about windows, if all you want is to be able to type in one-liners, you could consider line breaks inside quotes: ``` % python -c "import os; while (True): os.system('ls')" ```
11,226,252
Is there a way to loop in `while` if you start the script with `python -c`? This doesn't seem to be related to platform or python version... **Linux** ``` [mpenning@Hotcoffee ~]$ python -c "import os;while (True): os.system('ls')" File "<string>", line 1 import os;while (True): os.system('ls') ...
2012/06/27
[ "https://Stackoverflow.com/questions/11226252", "https://Stackoverflow.com", "https://Stackoverflow.com/users/667301/" ]
``` python -c $'import subprocess\nwhile True: subprocess.call(["ls"])' ``` would work (note the `$'...'` and the `\n`). But it could be that it only works under [bash](/questions/tagged/bash "show questions tagged 'bash'") - I am not sure...
Multiline statements may not start after a statement-separating `;` in Python – otherwise, there might be ambiguities about the code blocks. Simply use line breaks in stead of `;`. This "works" on Linux: ``` $ python -c "import os while True: os.system('ls')" ``` Not sure how to enter this on Windows, but why not si...
11,226,252
Is there a way to loop in `while` if you start the script with `python -c`? This doesn't seem to be related to platform or python version... **Linux** ``` [mpenning@Hotcoffee ~]$ python -c "import os;while (True): os.system('ls')" File "<string>", line 1 import os;while (True): os.system('ls') ...
2012/06/27
[ "https://Stackoverflow.com/questions/11226252", "https://Stackoverflow.com", "https://Stackoverflow.com/users/667301/" ]
Multiline statements may not start after a statement-separating `;` in Python – otherwise, there might be ambiguities about the code blocks. Simply use line breaks in stead of `;`. This "works" on Linux: ``` $ python -c "import os while True: os.system('ls')" ``` Not sure how to enter this on Windows, but why not si...
If you really must do this in windows, you could use exec: ``` python -c "exec \"import os;\rwhile True:\r os.system('dir')\"" ``` (I substituted `dir` so it works on my windows system)
11,226,252
Is there a way to loop in `while` if you start the script with `python -c`? This doesn't seem to be related to platform or python version... **Linux** ``` [mpenning@Hotcoffee ~]$ python -c "import os;while (True): os.system('ls')" File "<string>", line 1 import os;while (True): os.system('ls') ...
2012/06/27
[ "https://Stackoverflow.com/questions/11226252", "https://Stackoverflow.com", "https://Stackoverflow.com/users/667301/" ]
``` python -c $'import subprocess\nwhile True: subprocess.call(["ls"])' ``` would work (note the `$'...'` and the `\n`). But it could be that it only works under [bash](/questions/tagged/bash "show questions tagged 'bash'") - I am not sure...
Don't know about windows, if all you want is to be able to type in one-liners, you could consider line breaks inside quotes: ``` % python -c "import os; while (True): os.system('ls')" ```
11,226,252
Is there a way to loop in `while` if you start the script with `python -c`? This doesn't seem to be related to platform or python version... **Linux** ``` [mpenning@Hotcoffee ~]$ python -c "import os;while (True): os.system('ls')" File "<string>", line 1 import os;while (True): os.system('ls') ...
2012/06/27
[ "https://Stackoverflow.com/questions/11226252", "https://Stackoverflow.com", "https://Stackoverflow.com/users/667301/" ]
``` python -c $'import subprocess\nwhile True: subprocess.call(["ls"])' ``` would work (note the `$'...'` and the `\n`). But it could be that it only works under [bash](/questions/tagged/bash "show questions tagged 'bash'") - I am not sure...
If you really must do this in windows, you could use exec: ``` python -c "exec \"import os;\rwhile True:\r os.system('dir')\"" ``` (I substituted `dir` so it works on my windows system)
52,119,496
I am trying to write code to solve this python exercise: **I must use** the 'math' library, sqrt and possibly pow functions. > > "The distance between two points x and y is the square root of the sum > of squared differences along each dimension of x and y. > > > "Create a function that takes two vectors and out...
2018/08/31
[ "https://Stackoverflow.com/questions/52119496", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10265759/" ]
``` import math def distance (x,y): value= math.sqrt ((x[0]-y[0])**2 + (x[1] - y[1])**2) print (value) distance((0,0), (1,1)) ```
Thanks so much for those ideas! I figured it out. So happy. ``` for (a,b) in x,y: dis = math.sqrt((y[0] - x[0])**2 + (y[1] - x[1])**2) print(dis) ```
52,119,496
I am trying to write code to solve this python exercise: **I must use** the 'math' library, sqrt and possibly pow functions. > > "The distance between two points x and y is the square root of the sum > of squared differences along each dimension of x and y. > > > "Create a function that takes two vectors and out...
2018/08/31
[ "https://Stackoverflow.com/questions/52119496", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10265759/" ]
``` import math def distance (x,y): value= math.sqrt ((x[0]-y[0])**2 + (x[1] - y[1])**2) print (value) distance((0,0), (1,1)) ```
``` import math def distance(x1,x2,y1,y2): x=(x1,x2) y=(y1,y2) dis = math.sqrt((x[1]-x[0])**2 + (y[1] - y[0])**2) return dis print(dis(0,0,1,1)) ``` this works very well to answer your quest
64,260,105
I want to read all parquet files from an S3 bucket, including all those in the subdirectories (these are actually prefixes). Using wildcards (\*) in the S3 url only works for the files in the specified folder. For example using this code will only read the parquet files below the `target/` folder. ``` df = spark.read...
2020/10/08
[ "https://Stackoverflow.com/questions/64260105", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1771155/" ]
If you want to read all parquet files below the target folder ``` "s3://bucket/target/2020/01/01/some-file.parquet" "s3://bucket/target/2020/01/02/some-file.parquet" ``` you can do ``` df = spark.read.parquet("bucket/target/*/*/*/*.parquet") ``` The downside is that you need to know the depth of your parquet file...
This worked for me: ``` df = spark.read.parquet("s3://your/path/here/some*wildcard") ```
40,446,084
Running Selenium locally on flask. Im using the PhantomJS driver. I previously had a path error: ``` selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH. ``` But after finding out from another StackOverflow question, I learned that I have to pass the environment path a...
2016/11/06
[ "https://Stackoverflow.com/questions/40446084", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7121239/" ]
I think the true reason for you problem is that: **The phantomjs which webdrive needs is not the one under `selenium/webdriver` fold**. When you use anaconda to install this package, it's really confusing (at least for me). * First install it with `conda install -c conda-forge phantomjs`, test it with `phantomjs --ver...
Strangely, for me it was fixed by putting phantomjs in `/usr/local/share` and adding some symbolic links. I followed [these steps](https://stackoverflow.com/questions/8778513/how-can-i-setup-run-phantomjs-on-ubuntu): * move the phantomjs folder to `/usr/local/share/`: + `sudo mv phantomjs-2.1.1-linux-x86_64.tar.bz2 /...
40,446,084
Running Selenium locally on flask. Im using the PhantomJS driver. I previously had a path error: ``` selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH. ``` But after finding out from another StackOverflow question, I learned that I have to pass the environment path a...
2016/11/06
[ "https://Stackoverflow.com/questions/40446084", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7121239/" ]
Well I got this solved by the following CODE: ``` browser = webdriver.PhantomJS(executable_path = "/usr/local/Cellar/phantomjs/2.1.1/bin/phantomjs") ```
Strangely, for me it was fixed by putting phantomjs in `/usr/local/share` and adding some symbolic links. I followed [these steps](https://stackoverflow.com/questions/8778513/how-can-i-setup-run-phantomjs-on-ubuntu): * move the phantomjs folder to `/usr/local/share/`: + `sudo mv phantomjs-2.1.1-linux-x86_64.tar.bz2 /...
40,446,084
Running Selenium locally on flask. Im using the PhantomJS driver. I previously had a path error: ``` selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH. ``` But after finding out from another StackOverflow question, I learned that I have to pass the environment path a...
2016/11/06
[ "https://Stackoverflow.com/questions/40446084", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7121239/" ]
I placed the phantomjs file into `/usr/local/bin` and it worked fine.
I think the true reason for you problem is that: **The phantomjs which webdrive needs is not the one under `selenium/webdriver` fold**. When you use anaconda to install this package, it's really confusing (at least for me). * First install it with `conda install -c conda-forge phantomjs`, test it with `phantomjs --ver...
40,446,084
Running Selenium locally on flask. Im using the PhantomJS driver. I previously had a path error: ``` selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH. ``` But after finding out from another StackOverflow question, I learned that I have to pass the environment path a...
2016/11/06
[ "https://Stackoverflow.com/questions/40446084", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7121239/" ]
> > selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable may have wrong permissions. > > > This error is because phantomjs didn't execute permission, as long as for phantomjs - 2.1.1 - Linux - x86\_64 / bin/phantomjs add execute permissions, chmod u + x phantomjs
Strangely, for me it was fixed by putting phantomjs in `/usr/local/share` and adding some symbolic links. I followed [these steps](https://stackoverflow.com/questions/8778513/how-can-i-setup-run-phantomjs-on-ubuntu): * move the phantomjs folder to `/usr/local/share/`: + `sudo mv phantomjs-2.1.1-linux-x86_64.tar.bz2 /...
40,446,084
Running Selenium locally on flask. Im using the PhantomJS driver. I previously had a path error: ``` selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH. ``` But after finding out from another StackOverflow question, I learned that I have to pass the environment path a...
2016/11/06
[ "https://Stackoverflow.com/questions/40446084", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7121239/" ]
I placed the phantomjs file into `/usr/local/bin` and it worked fine.
I met this problem before about python+phanomjs. solution: **Linux** putting phantomjs in `/usr/local/share` **Windows** putting phantomjs in `/python/scripts`
40,446,084
Running Selenium locally on flask. Im using the PhantomJS driver. I previously had a path error: ``` selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH. ``` But after finding out from another StackOverflow question, I learned that I have to pass the environment path a...
2016/11/06
[ "https://Stackoverflow.com/questions/40446084", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7121239/" ]
I placed the phantomjs file into `/usr/local/bin` and it worked fine.
``` executable_path = './phantomjs-2.1.1-linux-x86_64/bin/phantomjs' service_log_path = './log/ghostdriver.log' driver = webdriver.PhantomJS(executable_path=executable_path, service_log_path=service_log_path) ``` You can use both the relative path and absolute paths.
40,446,084
Running Selenium locally on flask. Im using the PhantomJS driver. I previously had a path error: ``` selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH. ``` But after finding out from another StackOverflow question, I learned that I have to pass the environment path a...
2016/11/06
[ "https://Stackoverflow.com/questions/40446084", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7121239/" ]
I met this problem before about python+phanomjs. solution: **Linux** putting phantomjs in `/usr/local/share` **Windows** putting phantomjs in `/python/scripts`
Strangely, for me it was fixed by putting phantomjs in `/usr/local/share` and adding some symbolic links. I followed [these steps](https://stackoverflow.com/questions/8778513/how-can-i-setup-run-phantomjs-on-ubuntu): * move the phantomjs folder to `/usr/local/share/`: + `sudo mv phantomjs-2.1.1-linux-x86_64.tar.bz2 /...
40,446,084
Running Selenium locally on flask. Im using the PhantomJS driver. I previously had a path error: ``` selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH. ``` But after finding out from another StackOverflow question, I learned that I have to pass the environment path a...
2016/11/06
[ "https://Stackoverflow.com/questions/40446084", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7121239/" ]
I met this problem before about python+phanomjs. solution: **Linux** putting phantomjs in `/usr/local/share` **Windows** putting phantomjs in `/python/scripts`
> > selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable may have wrong permissions. > > > This error is because phantomjs didn't execute permission, as long as for phantomjs - 2.1.1 - Linux - x86\_64 / bin/phantomjs add execute permissions, chmod u + x phantomjs
40,446,084
Running Selenium locally on flask. Im using the PhantomJS driver. I previously had a path error: ``` selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH. ``` But after finding out from another StackOverflow question, I learned that I have to pass the environment path a...
2016/11/06
[ "https://Stackoverflow.com/questions/40446084", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7121239/" ]
I met this problem before about python+phanomjs. solution: **Linux** putting phantomjs in `/usr/local/share` **Windows** putting phantomjs in `/python/scripts`
``` executable_path = './phantomjs-2.1.1-linux-x86_64/bin/phantomjs' service_log_path = './log/ghostdriver.log' driver = webdriver.PhantomJS(executable_path=executable_path, service_log_path=service_log_path) ``` You can use both the relative path and absolute paths.
40,446,084
Running Selenium locally on flask. Im using the PhantomJS driver. I previously had a path error: ``` selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH. ``` But after finding out from another StackOverflow question, I learned that I have to pass the environment path a...
2016/11/06
[ "https://Stackoverflow.com/questions/40446084", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7121239/" ]
Well I got this solved by the following CODE: ``` browser = webdriver.PhantomJS(executable_path = "/usr/local/Cellar/phantomjs/2.1.1/bin/phantomjs") ```
I think the true reason for you problem is that: **The phantomjs which webdrive needs is not the one under `selenium/webdriver` fold**. When you use anaconda to install this package, it's really confusing (at least for me). * First install it with `conda install -c conda-forge phantomjs`, test it with `phantomjs --ver...
58,460,780
**using python 3.7** Hi. I am trying to get the the selected treeview item and want to print it once i click left menu item. This is my treeview list. When I right click a menu appeas with stop process command. I am trying to get the selected item and print it but its giving me error ``` AttributeError: 'str' object...
2019/10/19
[ "https://Stackoverflow.com/questions/58460780", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12241800/" ]
No, there is nothing like that, but there are tools, that try to mimic this behavior, for example lombok. Using `@Data` annotation we're getting default constructor, getters, setters, `toString`, `equals`, `hashCode`. We can fine-tune it by using annotations like `@Getter`, `@NoArgsConstructor` etc.
Neither Java nor Kotlin have anything similar to those Swift types you are talking about. Assignment *always* copies references to an object, rather than the object itself. What Kotlin's data classes do is that they create a `copy` method (among other things) that allows you to explicitly make a copy of an object, but ...
58,460,780
**using python 3.7** Hi. I am trying to get the the selected treeview item and want to print it once i click left menu item. This is my treeview list. When I right click a menu appeas with stop process command. I am trying to get the selected item and print it but its giving me error ``` AttributeError: 'str' object...
2019/10/19
[ "https://Stackoverflow.com/questions/58460780", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12241800/" ]
No, there is nothing like that, but there are tools, that try to mimic this behavior, for example lombok. Using `@Data` annotation we're getting default constructor, getters, setters, `toString`, `equals`, `hashCode`. We can fine-tune it by using annotations like `@Getter`, `@NoArgsConstructor` etc.
Starting with [Java 14](https://blogs.oracle.com/javamagazine/records-come-to-java) you will have access to [`Record`](https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/lang/Record.html) immutable class. It is similar in concept to `data` class in Kotlin.
29,943,146
I am new to python, trying to port a script in 2.x to 3.x i am encountering the error TypeError; Must use key word argument or key function in python 3.x. Below is the piece of code: Please help ``` def resort_working_array( self, chosen_values_arr, num ): for item in self.__working_arr[num]: data_node = s...
2015/04/29
[ "https://Stackoverflow.com/questions/29943146", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4846265/" ]
Looks like the problem is in this line. ``` self.__working_arr[num].sort( key = lambda a,b: cmp(a.weights, b.weights) ) ``` The `key` callable should take only one argument. Try: ``` self.__working_arr[num].sort(key = lambda a: a.weights) ```
The exact same error message appears if you try to pass the *key* parameter as a positional parameter. Wrong: ``` sort(lst, myKeyFunction) ``` Correct: ``` sort(lst, key=myKeyFunction) ``` Python 3.6.6
29,943,146
I am new to python, trying to port a script in 2.x to 3.x i am encountering the error TypeError; Must use key word argument or key function in python 3.x. Below is the piece of code: Please help ``` def resort_working_array( self, chosen_values_arr, num ): for item in self.__working_arr[num]: data_node = s...
2015/04/29
[ "https://Stackoverflow.com/questions/29943146", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4846265/" ]
Looks like the problem is in this line. ``` self.__working_arr[num].sort( key = lambda a,b: cmp(a.weights, b.weights) ) ``` The `key` callable should take only one argument. Try: ``` self.__working_arr[num].sort(key = lambda a: a.weights) ```
Following on from the [answer by @Kevin](https://stackoverflow.com/a/29944332/3363571) - and more specifically the comment/question by @featuresky: Using [functools.cmp\_to\_key](https://docs.python.org/3/library/functools.html#functools.cmp_to_key) and reimplementing cmp (as noted in the [porting guide](https://porti...
29,943,146
I am new to python, trying to port a script in 2.x to 3.x i am encountering the error TypeError; Must use key word argument or key function in python 3.x. Below is the piece of code: Please help ``` def resort_working_array( self, chosen_values_arr, num ): for item in self.__working_arr[num]: data_node = s...
2015/04/29
[ "https://Stackoverflow.com/questions/29943146", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4846265/" ]
The exact same error message appears if you try to pass the *key* parameter as a positional parameter. Wrong: ``` sort(lst, myKeyFunction) ``` Correct: ``` sort(lst, key=myKeyFunction) ``` Python 3.6.6
Following on from the [answer by @Kevin](https://stackoverflow.com/a/29944332/3363571) - and more specifically the comment/question by @featuresky: Using [functools.cmp\_to\_key](https://docs.python.org/3/library/functools.html#functools.cmp_to_key) and reimplementing cmp (as noted in the [porting guide](https://porti...
64,620,456
I'm a beginner in python and I want to use comprehension to create a dictionary. Let's say I have the below two list and want to convert them to a dictionary like `{'Key 1':['c','d'], 'Key 2':['a','f'], 'Key 3':['b','e']}`. I can only think of the code below and I don't know how to change the value of the key and the f...
2020/10/31
[ "https://Stackoverflow.com/questions/64620456", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
This should do it: ``` value = ['a','b','c','d','e','f'] key = [2, 3, 1, 1, 3, 2] answer = {} for k, v in zip(key, value): if k in answer: answer[k].append(v) else: answer[k] = [v] print(answer) {2: ['a', 'f'], 3: ['b', 'e'], 1: ['c', 'd']} ``` EDIT: oops, jumped the gun. Apologies. Here's...
You could do it with dictionary comprehension *and* list comprehension: ``` {f"Key {k}" : [value for key,value in zip(key,value) if key == k] for k in key} ``` Your lists would yield the following: ``` {'Key 2': ['a', 'f'], 'Key 3': ['b', 'e'], 'Key 1': ['c', 'd']} ``` As requested.
64,620,456
I'm a beginner in python and I want to use comprehension to create a dictionary. Let's say I have the below two list and want to convert them to a dictionary like `{'Key 1':['c','d'], 'Key 2':['a','f'], 'Key 3':['b','e']}`. I can only think of the code below and I don't know how to change the value of the key and the f...
2020/10/31
[ "https://Stackoverflow.com/questions/64620456", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
This should do it: ``` value = ['a','b','c','d','e','f'] key = [2, 3, 1, 1, 3, 2] answer = {} for k, v in zip(key, value): if k in answer: answer[k].append(v) else: answer[k] = [v] print(answer) {2: ['a', 'f'], 3: ['b', 'e'], 1: ['c', 'd']} ``` EDIT: oops, jumped the gun. Apologies. Here's...
use dict [setdefault](https://www.w3schools.com/python/ref_dictionary_setdefault.asp) ``` value = ['a', 'b', 'c', 'd', 'e', 'f'] key = [2, 3, 1, 1, 3, 2] d = {} {d.setdefault(f'Key {k}', []).append(v) for k, v in zip(key, value)} print(d) ``` output ``` {'Key 2': ['a', 'f'], 'Key 3': ['b', 'e'], 'Key 1': ['c', 'd']...
64,620,456
I'm a beginner in python and I want to use comprehension to create a dictionary. Let's say I have the below two list and want to convert them to a dictionary like `{'Key 1':['c','d'], 'Key 2':['a','f'], 'Key 3':['b','e']}`. I can only think of the code below and I don't know how to change the value of the key and the f...
2020/10/31
[ "https://Stackoverflow.com/questions/64620456", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
This should do it: ``` value = ['a','b','c','d','e','f'] key = [2, 3, 1, 1, 3, 2] answer = {} for k, v in zip(key, value): if k in answer: answer[k].append(v) else: answer[k] = [v] print(answer) {2: ['a', 'f'], 3: ['b', 'e'], 1: ['c', 'd']} ``` EDIT: oops, jumped the gun. Apologies. Here's...
Usually, it is written as an explicit loop (O(n) solution): ``` >>> letters = 'abcdef' >>> digits = [2, 3, 1, 1, 3, 2] >>> from collections import defaultdict >>> result = defaultdict(list) # digit -> letters >>> for digit, letter in zip(digits, letters): ... result[digit].append(letter) >>> result defaultdict(<c...
64,620,456
I'm a beginner in python and I want to use comprehension to create a dictionary. Let's say I have the below two list and want to convert them to a dictionary like `{'Key 1':['c','d'], 'Key 2':['a','f'], 'Key 3':['b','e']}`. I can only think of the code below and I don't know how to change the value of the key and the f...
2020/10/31
[ "https://Stackoverflow.com/questions/64620456", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
You could do it with dictionary comprehension *and* list comprehension: ``` {f"Key {k}" : [value for key,value in zip(key,value) if key == k] for k in key} ``` Your lists would yield the following: ``` {'Key 2': ['a', 'f'], 'Key 3': ['b', 'e'], 'Key 1': ['c', 'd']} ``` As requested.
Usually, it is written as an explicit loop (O(n) solution): ``` >>> letters = 'abcdef' >>> digits = [2, 3, 1, 1, 3, 2] >>> from collections import defaultdict >>> result = defaultdict(list) # digit -> letters >>> for digit, letter in zip(digits, letters): ... result[digit].append(letter) >>> result defaultdict(<c...
64,620,456
I'm a beginner in python and I want to use comprehension to create a dictionary. Let's say I have the below two list and want to convert them to a dictionary like `{'Key 1':['c','d'], 'Key 2':['a','f'], 'Key 3':['b','e']}`. I can only think of the code below and I don't know how to change the value of the key and the f...
2020/10/31
[ "https://Stackoverflow.com/questions/64620456", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
use dict [setdefault](https://www.w3schools.com/python/ref_dictionary_setdefault.asp) ``` value = ['a', 'b', 'c', 'd', 'e', 'f'] key = [2, 3, 1, 1, 3, 2] d = {} {d.setdefault(f'Key {k}', []).append(v) for k, v in zip(key, value)} print(d) ``` output ``` {'Key 2': ['a', 'f'], 'Key 3': ['b', 'e'], 'Key 1': ['c', 'd']...
Usually, it is written as an explicit loop (O(n) solution): ``` >>> letters = 'abcdef' >>> digits = [2, 3, 1, 1, 3, 2] >>> from collections import defaultdict >>> result = defaultdict(list) # digit -> letters >>> for digit, letter in zip(digits, letters): ... result[digit].append(letter) >>> result defaultdict(<c...
35,697,643
I have a `Frame` with two columns of `String`, ``` let first = Series.ofValues(["a";"b";"c"]) let second = Series.ofValues(["d";"e";"f"]) let df = Frame(["first"; "second"], [first; second]) ``` How do I produce a third column as the concatenation of the two columns? In `python` `pandas`, this can be achieved with...
2016/02/29
[ "https://Stackoverflow.com/questions/35697643", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1569058/" ]
It sounds like what you want is to have something that returns something like: ``` Series.ofValues(["ad"; "be"; "cf"]) ``` Then I think you need to define an addition operator with something like this: ``` let additionOperator = (fun (a:string) (b:string) -> (a + b)) ``` And then you can add them like this: ``` ...
I come across this after facing the same issue, the trick is to get the values as seq and use Seq.map2 to concat the two seqs, my solution is ``` let first = Series.ofValues(["a";"b";"c"]) let second = Series.ofValues(["d";"e";"f"]) let df = Seq.map2 (fun x y -> x+y) first.Values second.Values |> Series.ofVal...
35,697,643
I have a `Frame` with two columns of `String`, ``` let first = Series.ofValues(["a";"b";"c"]) let second = Series.ofValues(["d";"e";"f"]) let df = Frame(["first"; "second"], [first; second]) ``` How do I produce a third column as the concatenation of the two columns? In `python` `pandas`, this can be achieved with...
2016/02/29
[ "https://Stackoverflow.com/questions/35697643", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1569058/" ]
It sounds like what you want is to have something that returns something like: ``` Series.ofValues(["ad"; "be"; "cf"]) ``` Then I think you need to define an addition operator with something like this: ``` let additionOperator = (fun (a:string) (b:string) -> (a + b)) ``` And then you can add them like this: ``` ...
I believe this would work... Clearly not the most beautiful way to write it but... Will try to do some time testing later. ``` let df3c = df |> Frame.mapRows (fun _ b -> b.GetAt(0).ToString() + b.GetAt(1).ToString()) |> (fun a -> Frame.addCol "test" a df) ```
35,697,643
I have a `Frame` with two columns of `String`, ``` let first = Series.ofValues(["a";"b";"c"]) let second = Series.ofValues(["d";"e";"f"]) let df = Frame(["first"; "second"], [first; second]) ``` How do I produce a third column as the concatenation of the two columns? In `python` `pandas`, this can be achieved with...
2016/02/29
[ "https://Stackoverflow.com/questions/35697643", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1569058/" ]
I come across this after facing the same issue, the trick is to get the values as seq and use Seq.map2 to concat the two seqs, my solution is ``` let first = Series.ofValues(["a";"b";"c"]) let second = Series.ofValues(["d";"e";"f"]) let df = Seq.map2 (fun x y -> x+y) first.Values second.Values |> Series.ofVal...
I believe this would work... Clearly not the most beautiful way to write it but... Will try to do some time testing later. ``` let df3c = df |> Frame.mapRows (fun _ b -> b.GetAt(0).ToString() + b.GetAt(1).ToString()) |> (fun a -> Frame.addCol "test" a df) ```
62,030,549
I have a directory filled with '.tbl' files. The file set up is as follows: \STAR\_ID = "HD 74156" \DATA\_CATEGORY = "Planet Radial Velocity Curve" \NUMBER\_OF\_POINTS = "82" \TIME\_REFERENCE\_FRAME = "JD" \MINIMUM\_DATE = "2453342.23249" \DATE\_UNITS = "days" \MAXIMUM\_DATE = "2454231.60002" .... I need to re...
2020/05/26
[ "https://Stackoverflow.com/questions/62030549", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13622725/" ]
This error occurs because of `first_line.split('"')` is returning a list with less of 2 items. you can try ``` first_line_ls = first_line.split('"') if len(first_line_ls) > 1: system = first_line_ls[1] else: #other method ``` This code can help you prevent the error and handle cases the file\_line str hav...
It looks like these `.tbl` files are not as uniform as you might have hoped. If this line: ``` ----> 5 system = first_line.split('"')[1] ``` fails on some files, it's because their first line is not formatted as you expected, as @Leo Arad noted. You also want to make sure you're *actually* using the `STAR_ID...
48,675,435
In a personal project, I am trying to use Django as my front end and then allow data entered by users in a particular form to be copied to google sheets. Google's own docs recommend using <https://github.com/google/oauth2client> which is now deprecated, and the docs have not been updated. With this, I have started att...
2018/02/08
[ "https://Stackoverflow.com/questions/48675435", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6883167/" ]
It's true that `python-social-auth` will use some bits of the Google+ platform, at least the API to retrieve details about the user to fill in the account. From your settings, I see you have `associate_by_email` at the bottom, at that point, at that point it has no use since the user is already be created, if you real...
Just provide this in your `settings.py`: `SOCIAL_AUTH_GOOGLE_OAUTH2_AUTH_EXTRA_ARGUMENTS = { 'access_type': 'offline', 'hd': 'xyzabc.com', 'approval_prompt':'force' }` remeber there is `{'approval_prompt' : 'force'}` which will force the user to select the gmail account, this way you will get refresh token.
48,675,435
In a personal project, I am trying to use Django as my front end and then allow data entered by users in a particular form to be copied to google sheets. Google's own docs recommend using <https://github.com/google/oauth2client> which is now deprecated, and the docs have not been updated. With this, I have started att...
2018/02/08
[ "https://Stackoverflow.com/questions/48675435", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6883167/" ]
It's true that `python-social-auth` will use some bits of the Google+ platform, at least the API to retrieve details about the user to fill in the account. From your settings, I see you have `associate_by_email` at the bottom, at that point, at that point it has no use since the user is already be created, if you real...
You can send extra parameters to the OAuth2 provider using the variable ``` SOCIAL_AUTH_<PROVIDER>_AUTH_EXTRA_ARGUMENTS ``` For Google, you can see the extra parameters they accept [in their documentation (scroll down to "parameters")](https://developers.google.com/identity/protocols/OAuth2WebServer#creatingclient)....
48,675,435
In a personal project, I am trying to use Django as my front end and then allow data entered by users in a particular form to be copied to google sheets. Google's own docs recommend using <https://github.com/google/oauth2client> which is now deprecated, and the docs have not been updated. With this, I have started att...
2018/02/08
[ "https://Stackoverflow.com/questions/48675435", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6883167/" ]
Just provide this in your `settings.py`: `SOCIAL_AUTH_GOOGLE_OAUTH2_AUTH_EXTRA_ARGUMENTS = { 'access_type': 'offline', 'hd': 'xyzabc.com', 'approval_prompt':'force' }` remeber there is `{'approval_prompt' : 'force'}` which will force the user to select the gmail account, this way you will get refresh token.
You can send extra parameters to the OAuth2 provider using the variable ``` SOCIAL_AUTH_<PROVIDER>_AUTH_EXTRA_ARGUMENTS ``` For Google, you can see the extra parameters they accept [in their documentation (scroll down to "parameters")](https://developers.google.com/identity/protocols/OAuth2WebServer#creatingclient)....
67,519,212
I have written a simple caesar cipher code to take a string and a positional shift argument i.e cipher to encrypt the string. However, I have realized some of the outputs won't decrypt correctly. For example: `python .\caesar_cipher.py 'fortuna' 6771 --encrypt` outputs `☼↑↔▲↨` `python .\caesar_cipher.py '☼↑↔▲↨' 67...
2021/05/13
[ "https://Stackoverflow.com/questions/67519212", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9169087/" ]
I think the problem is after the encryption in copy and pasting the value. When I tested this code, what I found and you mentioned that too, directly transferring the encrypted value to the decrypt function by storing in a variable, doesn't cause any problem, but when directly pasting it is causing problem. To overcom...
As @KnowledgeGainer mentioned, there is no problem with your code. The issue arises because you copied the output of your encryption from the terminal, and used that as your input for decryption. The terminal you're using is trying its best to interpret some potential non-printable control characters - `fortuna` has se...
67,519,212
I have written a simple caesar cipher code to take a string and a positional shift argument i.e cipher to encrypt the string. However, I have realized some of the outputs won't decrypt correctly. For example: `python .\caesar_cipher.py 'fortuna' 6771 --encrypt` outputs `☼↑↔▲↨` `python .\caesar_cipher.py '☼↑↔▲↨' 67...
2021/05/13
[ "https://Stackoverflow.com/questions/67519212", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9169087/" ]
Add `print(' '.join([str(ord(c)) for c in result]))` along with `print(result)`. Then you see that `result` contains unprintable characters under 32 (0x20): `15,24,27,29,30,23,10`. Here's a possible technique how to stay in *printable* range of *ASCII*: ``` NO_OF_NOPRNT = 32 # number of unprintable c...
As @KnowledgeGainer mentioned, there is no problem with your code. The issue arises because you copied the output of your encryption from the terminal, and used that as your input for decryption. The terminal you're using is trying its best to interpret some potential non-printable control characters - `fortuna` has se...
34,284,737
This is a part of my code for a hangman game. it is used for all four difficulties, but when it is used on my "insane" difficulty (which uses words from a word file) it adds an extra symbol to the end of the word meaning you can't win the game. it does this for every word in the .txt file. This code works when using an...
2015/12/15
[ "https://Stackoverflow.com/questions/34284737", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5653652/" ]
You have a `\n` at the end of every word. You should strip the word of the `\n` before adding it: ``` INSANEWORDS = open("create.txt", "r+") words = [] for item in INSANEWORDS: words.append(item.strip('\n')) ``` **Before:** [![enter image description here](https://i.stack.imgur.com/d6mOJ.png)](https://i.stack.i...
If my guess is correct when you are reading a line from your text file you also reading the new line character **\n** at the end of the word, which you can remove using: ``` word = word.strip('\n') ```
10,589,933
I've been trying to learn python recently, and ran across something that I'm having a hard time understanding exactly how it works. Primarily, it is the design of a list. The list in question is from this security article talking about a simple fuzzing tool: <http://blog.securestate.com/post/2009/10/06/How-a-simple-py...
2012/05/14
[ "https://Stackoverflow.com/questions/10589933", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1298775/" ]
This ``` """ 00 00 00 90 ff 53 4d 42 72 00 00 00 00 18 53 c8 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff fe 00 00 00 00 00 6d 00 02 50 43 20 4e 45 54 57 4f 52 4b 20 50 52 4f 47 52 41 4d 20 31 2e 30 00 02 4c 41 4e 4d 41 4e 31 2e 30 00 02 57 69 6e 64 6f 77 73 20 66 6f 72 20 57 6f 72 6b 67 72 6f 75 70 73 20 33 2e 31 61 ...
The ``` """ content """ ``` format is a simple way to define multiline string literals in python. This is **not** a comment block. The `[chr(int(a, 16)) for a in "00 00 00...".split()]` is a list comprehension. The large string is split into an array (split by spaces), and for each item in the array, it convert...
10,589,933
I've been trying to learn python recently, and ran across something that I'm having a hard time understanding exactly how it works. Primarily, it is the design of a list. The list in question is from this security article talking about a simple fuzzing tool: <http://blog.securestate.com/post/2009/10/06/How-a-simple-py...
2012/05/14
[ "https://Stackoverflow.com/questions/10589933", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1298775/" ]
The ``` """ content """ ``` format is a simple way to define multiline string literals in python. This is **not** a comment block. The `[chr(int(a, 16)) for a in "00 00 00...".split()]` is a list comprehension. The large string is split into an array (split by spaces), and for each item in the array, it convert...
You're running into a couple different concepts here. Just slowly work backwards and you'll figure it out. The """00 00 00 90 ff 53 4d 42 72 00 00 00 00 18 53 c8 00 00 00 00""" stuff is just a big string. The .split on it breaks it into an array on the spaces, so at that point you have something like ['00', '00', '00'...
10,589,933
I've been trying to learn python recently, and ran across something that I'm having a hard time understanding exactly how it works. Primarily, it is the design of a list. The list in question is from this security article talking about a simple fuzzing tool: <http://blog.securestate.com/post/2009/10/06/How-a-simple-py...
2012/05/14
[ "https://Stackoverflow.com/questions/10589933", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1298775/" ]
The ``` """ content """ ``` format is a simple way to define multiline string literals in python. This is **not** a comment block. The `[chr(int(a, 16)) for a in "00 00 00...".split()]` is a list comprehension. The large string is split into an array (split by spaces), and for each item in the array, it convert...
The code sample in question seems to substitute a randomly chosen byte in the original packet for another random byte (which I believe, is one of the ideas behind fuzzing.) ``` packet = [chr(int(a, 16)) for a in """ 00 00 00 90 .... """.split()] ``` This is "split the string on whitespace, read the substrings as ch...
10,589,933
I've been trying to learn python recently, and ran across something that I'm having a hard time understanding exactly how it works. Primarily, it is the design of a list. The list in question is from this security article talking about a simple fuzzing tool: <http://blog.securestate.com/post/2009/10/06/How-a-simple-py...
2012/05/14
[ "https://Stackoverflow.com/questions/10589933", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1298775/" ]
Let's break it down, and simplify it for readability: ``` bytes = """ 00 00 00 90 ff 53 4d 42 72 00 00 00 00 18 53 c8 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff fe 00 00 00 00 00 6d 00 02 50 43 20 4e 45 54 57 4f 52 4b 20 50 52 4f 47 52 41 4d 20 31 2e 30...
The ``` """ content """ ``` format is a simple way to define multiline string literals in python. This is **not** a comment block. The `[chr(int(a, 16)) for a in "00 00 00...".split()]` is a list comprehension. The large string is split into an array (split by spaces), and for each item in the array, it convert...
10,589,933
I've been trying to learn python recently, and ran across something that I'm having a hard time understanding exactly how it works. Primarily, it is the design of a list. The list in question is from this security article talking about a simple fuzzing tool: <http://blog.securestate.com/post/2009/10/06/How-a-simple-py...
2012/05/14
[ "https://Stackoverflow.com/questions/10589933", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1298775/" ]
This ``` """ 00 00 00 90 ff 53 4d 42 72 00 00 00 00 18 53 c8 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff fe 00 00 00 00 00 6d 00 02 50 43 20 4e 45 54 57 4f 52 4b 20 50 52 4f 47 52 41 4d 20 31 2e 30 00 02 4c 41 4e 4d 41 4e 31 2e 30 00 02 57 69 6e 64 6f 77 73 20 66 6f 72 20 57 6f 72 6b 67 72 6f 75 70 73 20 33 2e 31 61 ...
You're running into a couple different concepts here. Just slowly work backwards and you'll figure it out. The """00 00 00 90 ff 53 4d 42 72 00 00 00 00 18 53 c8 00 00 00 00""" stuff is just a big string. The .split on it breaks it into an array on the spaces, so at that point you have something like ['00', '00', '00'...
10,589,933
I've been trying to learn python recently, and ran across something that I'm having a hard time understanding exactly how it works. Primarily, it is the design of a list. The list in question is from this security article talking about a simple fuzzing tool: <http://blog.securestate.com/post/2009/10/06/How-a-simple-py...
2012/05/14
[ "https://Stackoverflow.com/questions/10589933", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1298775/" ]
This ``` """ 00 00 00 90 ff 53 4d 42 72 00 00 00 00 18 53 c8 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff fe 00 00 00 00 00 6d 00 02 50 43 20 4e 45 54 57 4f 52 4b 20 50 52 4f 47 52 41 4d 20 31 2e 30 00 02 4c 41 4e 4d 41 4e 31 2e 30 00 02 57 69 6e 64 6f 77 73 20 66 6f 72 20 57 6f 72 6b 67 72 6f 75 70 73 20 33 2e 31 61 ...
The code sample in question seems to substitute a randomly chosen byte in the original packet for another random byte (which I believe, is one of the ideas behind fuzzing.) ``` packet = [chr(int(a, 16)) for a in """ 00 00 00 90 .... """.split()] ``` This is "split the string on whitespace, read the substrings as ch...
10,589,933
I've been trying to learn python recently, and ran across something that I'm having a hard time understanding exactly how it works. Primarily, it is the design of a list. The list in question is from this security article talking about a simple fuzzing tool: <http://blog.securestate.com/post/2009/10/06/How-a-simple-py...
2012/05/14
[ "https://Stackoverflow.com/questions/10589933", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1298775/" ]
You're running into a couple different concepts here. Just slowly work backwards and you'll figure it out. The """00 00 00 90 ff 53 4d 42 72 00 00 00 00 18 53 c8 00 00 00 00""" stuff is just a big string. The .split on it breaks it into an array on the spaces, so at that point you have something like ['00', '00', '00'...
The code sample in question seems to substitute a randomly chosen byte in the original packet for another random byte (which I believe, is one of the ideas behind fuzzing.) ``` packet = [chr(int(a, 16)) for a in """ 00 00 00 90 .... """.split()] ``` This is "split the string on whitespace, read the substrings as ch...
10,589,933
I've been trying to learn python recently, and ran across something that I'm having a hard time understanding exactly how it works. Primarily, it is the design of a list. The list in question is from this security article talking about a simple fuzzing tool: <http://blog.securestate.com/post/2009/10/06/How-a-simple-py...
2012/05/14
[ "https://Stackoverflow.com/questions/10589933", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1298775/" ]
Let's break it down, and simplify it for readability: ``` bytes = """ 00 00 00 90 ff 53 4d 42 72 00 00 00 00 18 53 c8 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff fe 00 00 00 00 00 6d 00 02 50 43 20 4e 45 54 57 4f 52 4b 20 50 52 4f 47 52 41 4d 20 31 2e 30...
You're running into a couple different concepts here. Just slowly work backwards and you'll figure it out. The """00 00 00 90 ff 53 4d 42 72 00 00 00 00 18 53 c8 00 00 00 00""" stuff is just a big string. The .split on it breaks it into an array on the spaces, so at that point you have something like ['00', '00', '00'...
10,589,933
I've been trying to learn python recently, and ran across something that I'm having a hard time understanding exactly how it works. Primarily, it is the design of a list. The list in question is from this security article talking about a simple fuzzing tool: <http://blog.securestate.com/post/2009/10/06/How-a-simple-py...
2012/05/14
[ "https://Stackoverflow.com/questions/10589933", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1298775/" ]
Let's break it down, and simplify it for readability: ``` bytes = """ 00 00 00 90 ff 53 4d 42 72 00 00 00 00 18 53 c8 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff fe 00 00 00 00 00 6d 00 02 50 43 20 4e 45 54 57 4f 52 4b 20 50 52 4f 47 52 41 4d 20 31 2e 30...
The code sample in question seems to substitute a randomly chosen byte in the original packet for another random byte (which I believe, is one of the ideas behind fuzzing.) ``` packet = [chr(int(a, 16)) for a in """ 00 00 00 90 .... """.split()] ``` This is "split the string on whitespace, read the substrings as ch...
36,461,925
I am not even sure how to word my question due to me being quite new to python. The basic concept of what I want to accomplish is to be able to search for something in a 2D array and retrieve the right value as well as the values associated with that value (sorry for my bad explanation) e.g. `array=[[1,a,b],[2,x,d],...
2016/04/06
[ "https://Stackoverflow.com/questions/36461925", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6168984/" ]
I am not sure if I understood the question correctly, but from what I got, I think you can create a model instance with initial values (place holders), and allow your component to initialise with this model, and then, when your data is ready, change the model instance values, which will reflect to your component. This...
What version of Angular are you with? Not sure if you're copy-pasting the redacted code, but it seems as if you're missing the `implements` keyword there in your Class. `*ngIf` works good in this [plunker](https://plnkr.co/edit/jXsRvHZ33A1KrRxROGAK?p=preview). From what I gather, something like \*ngIf is the proper w...
36,461,925
I am not even sure how to word my question due to me being quite new to python. The basic concept of what I want to accomplish is to be able to search for something in a 2D array and retrieve the right value as well as the values associated with that value (sorry for my bad explanation) e.g. `array=[[1,a,b],[2,x,d],...
2016/04/06
[ "https://Stackoverflow.com/questions/36461925", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6168984/" ]
I am not sure if I understood the question correctly, but from what I got, I think you can create a model instance with initial values (place holders), and allow your component to initialise with this model, and then, when your data is ready, change the model instance values, which will reflect to your component. This...
What I usually do is create an `EventEmitter` in my data service, and then allow each component to listen for the `dataLoaded` event before doing anything. It may not be the most efficient and "textbook" way to go about this problem, but works well. For example, in `app.component.ts` (my most parent component), I load ...
36,461,925
I am not even sure how to word my question due to me being quite new to python. The basic concept of what I want to accomplish is to be able to search for something in a 2D array and retrieve the right value as well as the values associated with that value (sorry for my bad explanation) e.g. `array=[[1,a,b],[2,x,d],...
2016/04/06
[ "https://Stackoverflow.com/questions/36461925", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6168984/" ]
What version of Angular are you with? Not sure if you're copy-pasting the redacted code, but it seems as if you're missing the `implements` keyword there in your Class. `*ngIf` works good in this [plunker](https://plnkr.co/edit/jXsRvHZ33A1KrRxROGAK?p=preview). From what I gather, something like \*ngIf is the proper w...
What I usually do is create an `EventEmitter` in my data service, and then allow each component to listen for the `dataLoaded` event before doing anything. It may not be the most efficient and "textbook" way to go about this problem, but works well. For example, in `app.component.ts` (my most parent component), I load ...
39,816,500
I've recently began work on a Python program as seen in the fragment below. ``` # General Variables running = False new = True timeStart = 0.0 timeElapsed = 0.0 def endProg(): curses.nocbreak() stdscr.keypad(False) curses.echo() curses.endwin() quit() # Draw def draw(): stdscr.addstr(1, 1, ">...
2016/10/02
[ "https://Stackoverflow.com/questions/39816500", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6911375/" ]
Install mocha and its types: ```sh npm install mocha --save-dev npm install @types/mocha --save-dev ``` Then, simply import mocha in your test files: ```js import 'mocha'; describe('my test', () => { it('does something', () => { // your test }); }); ```
Since TypeScript 2.0, you can add `mocha` to the `types` configuration of your `tsconfig.json` and it will always be loaded: ``` { "compilerOptions": { "types": [ "mocha" ] } } ```
39,816,500
I've recently began work on a Python program as seen in the fragment below. ``` # General Variables running = False new = True timeStart = 0.0 timeElapsed = 0.0 def endProg(): curses.nocbreak() stdscr.keypad(False) curses.echo() curses.endwin() quit() # Draw def draw(): stdscr.addstr(1, 1, ">...
2016/10/02
[ "https://Stackoverflow.com/questions/39816500", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6911375/" ]
Since TypeScript 2.0, you can add `mocha` to the `types` configuration of your `tsconfig.json` and it will always be loaded: ``` { "compilerOptions": { "types": [ "mocha" ] } } ```
I was having issues with errors and warnings, the problem stemmed from me renaming `tsconfig.json` to something else which makes Visual Studio Code enter "File Scope" instead of "Explicit Project". That made it impossible to import `it` without a red squiggly. Now that I've renamed the config back to `tsconfig.json` th...
39,816,500
I've recently began work on a Python program as seen in the fragment below. ``` # General Variables running = False new = True timeStart = 0.0 timeElapsed = 0.0 def endProg(): curses.nocbreak() stdscr.keypad(False) curses.echo() curses.endwin() quit() # Draw def draw(): stdscr.addstr(1, 1, ">...
2016/10/02
[ "https://Stackoverflow.com/questions/39816500", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6911375/" ]
Install mocha and its types: ```sh npm install mocha --save-dev npm install @types/mocha --save-dev ``` Then, simply import mocha in your test files: ```js import 'mocha'; describe('my test', () => { it('does something', () => { // your test }); }); ```
I was having issues with errors and warnings, the problem stemmed from me renaming `tsconfig.json` to something else which makes Visual Studio Code enter "File Scope" instead of "Explicit Project". That made it impossible to import `it` without a red squiggly. Now that I've renamed the config back to `tsconfig.json` th...
34,756,978
I am trying to download py2exe but every time that run the setup program it says "no python installation found in registry" but I have downloaded python 3.4 and have it on my computer working? please help. I'm using a 64 bit computer with the 64 bit py2exe, I downloaded python from the python website. And i'm on windo...
2016/01/13
[ "https://Stackoverflow.com/questions/34756978", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5781821/" ]
Try to use [cx\_Freeze](https://pypi.python.org/pypi/cx_Freeze) instead py2exe.
I assume that you have installed everything properly. In your install settings you can choose if you want to assign the **system variable** python.as you can see from the [point 3.3 of the documentation](https://docs.python.org/3.4/using/windows.html#configuring-python), you should: > > 3.3.1. Excursus: Setting envir...
31,256,397
I have data of the following form: ``` #@ <abc> <http://stackoverflow.com/questions/ask> <question> _:question1 . #@ <def> <The> <second> <http://line> . #@ <ghi> _:question1 <http#responseCode> "200"^^<http://integer> . #@ <klm> <The> <second> <http://line1.xml> . #@ <nop> _:question1 <date> "Mon, 23 Apr 2012 13:4...
2015/07/06
[ "https://Stackoverflow.com/questions/31256397", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4360034/" ]
Keep a boolean hashtable of hash codes of lines already seen. For each line: * if line hash()es to something you have already seen, you have a potential match: scan the file to check if it really is a duplicate. * if line hash()es to a new hash, just mark the hash for the first time. Dedicate as much memory you can ...
One fairly straightforward way - make a version of your data such that each line includes a field with its line number. Use unix 'sort' to sort that new file, excluding the line number field. The sort utility will merge sort the file even if it exceeds the size of available memory. Now you have a new file in which the ...
31,256,397
I have data of the following form: ``` #@ <abc> <http://stackoverflow.com/questions/ask> <question> _:question1 . #@ <def> <The> <second> <http://line> . #@ <ghi> _:question1 <http#responseCode> "200"^^<http://integer> . #@ <klm> <The> <second> <http://line1.xml> . #@ <nop> _:question1 <date> "Mon, 23 Apr 2012 13:4...
2015/07/06
[ "https://Stackoverflow.com/questions/31256397", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4360034/" ]
Keep a boolean hashtable of hash codes of lines already seen. For each line: * if line hash()es to something you have already seen, you have a potential match: scan the file to check if it really is a duplicate. * if line hash()es to a new hash, just mark the hash for the first time. Dedicate as much memory you can ...
Here's an outline of how I'd do it using UNIX sort/uniq: 1. Modify the data format so that each record is a single line. You could do this using the methods [here](https://stackoverflow.com/questions/8987257/concatenating-every-other-line-with-the-next). 2. Sort the data with the [`sort` command](http://unixhelp.ed.ac...
48,964,181
I am currently trying to load a pickled file from S3 into AWS lambda and store it to a list (the pickle is a list). Here is my code: ``` import pickle import boto3 s3 = boto3.resource('s3') with open('oldscreenurls.pkl', 'rb') as data: old_list = s3.Bucket("pythonpickles").download_fileobj("oldscreenurls.pkl", d...
2018/02/24
[ "https://Stackoverflow.com/questions/48964181", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6327717/" ]
Super simple solution ```py import pickle import boto3 s3 = boto3.resource('s3') my_pickle = pickle.loads(s3.Bucket("bucket_name").Object("key_to_pickle.pickle").get()['Body'].read()) ```
As shown in the documentation for [`download_fileobj`](http://boto3.readthedocs.io/en/latest/reference/services/s3.html#S3.Bucket.download_fileobj), you need to open the file in binary *write* mode and save to the file first. Once the file is downloaded, you can open it for reading and unpickle. ``` import pickle impo...
48,964,181
I am currently trying to load a pickled file from S3 into AWS lambda and store it to a list (the pickle is a list). Here is my code: ``` import pickle import boto3 s3 = boto3.resource('s3') with open('oldscreenurls.pkl', 'rb') as data: old_list = s3.Bucket("pythonpickles").download_fileobj("oldscreenurls.pkl", d...
2018/02/24
[ "https://Stackoverflow.com/questions/48964181", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6327717/" ]
As shown in the documentation for [`download_fileobj`](http://boto3.readthedocs.io/en/latest/reference/services/s3.html#S3.Bucket.download_fileobj), you need to open the file in binary *write* mode and save to the file first. Once the file is downloaded, you can open it for reading and unpickle. ``` import pickle impo...
This is the easiest solution. You can load the data without even downloading the file locally using **S3FileSystem** ``` from s3fs.core import S3FileSystem s3_file = S3FileSystem() data = pickle.load(s3_file.open('{}/{}'.format(bucket_name, file_path))) ```
48,964,181
I am currently trying to load a pickled file from S3 into AWS lambda and store it to a list (the pickle is a list). Here is my code: ``` import pickle import boto3 s3 = boto3.resource('s3') with open('oldscreenurls.pkl', 'rb') as data: old_list = s3.Bucket("pythonpickles").download_fileobj("oldscreenurls.pkl", d...
2018/02/24
[ "https://Stackoverflow.com/questions/48964181", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6327717/" ]
As shown in the documentation for [`download_fileobj`](http://boto3.readthedocs.io/en/latest/reference/services/s3.html#S3.Bucket.download_fileobj), you need to open the file in binary *write* mode and save to the file first. Once the file is downloaded, you can open it for reading and unpickle. ``` import pickle impo...
According to my implementation, S3 file path read with pickle. ``` import pickle import boto3 name = img_url.split('/')[::-1][0] folder = 'media' file_name = f'{folder}/{name}' bucket_name = bucket_name s3 = boto3.client('s3', aws_access_key_id=aws_access_key_id,aws_secret_access_key=aws_secret_access_key) response =...
48,964,181
I am currently trying to load a pickled file from S3 into AWS lambda and store it to a list (the pickle is a list). Here is my code: ``` import pickle import boto3 s3 = boto3.resource('s3') with open('oldscreenurls.pkl', 'rb') as data: old_list = s3.Bucket("pythonpickles").download_fileobj("oldscreenurls.pkl", d...
2018/02/24
[ "https://Stackoverflow.com/questions/48964181", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6327717/" ]
Super simple solution ```py import pickle import boto3 s3 = boto3.resource('s3') my_pickle = pickle.loads(s3.Bucket("bucket_name").Object("key_to_pickle.pickle").get()['Body'].read()) ```
This is the easiest solution. You can load the data without even downloading the file locally using **S3FileSystem** ``` from s3fs.core import S3FileSystem s3_file = S3FileSystem() data = pickle.load(s3_file.open('{}/{}'.format(bucket_name, file_path))) ```
48,964,181
I am currently trying to load a pickled file from S3 into AWS lambda and store it to a list (the pickle is a list). Here is my code: ``` import pickle import boto3 s3 = boto3.resource('s3') with open('oldscreenurls.pkl', 'rb') as data: old_list = s3.Bucket("pythonpickles").download_fileobj("oldscreenurls.pkl", d...
2018/02/24
[ "https://Stackoverflow.com/questions/48964181", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6327717/" ]
Super simple solution ```py import pickle import boto3 s3 = boto3.resource('s3') my_pickle = pickle.loads(s3.Bucket("bucket_name").Object("key_to_pickle.pickle").get()['Body'].read()) ```
According to my implementation, S3 file path read with pickle. ``` import pickle import boto3 name = img_url.split('/')[::-1][0] folder = 'media' file_name = f'{folder}/{name}' bucket_name = bucket_name s3 = boto3.client('s3', aws_access_key_id=aws_access_key_id,aws_secret_access_key=aws_secret_access_key) response =...
48,964,181
I am currently trying to load a pickled file from S3 into AWS lambda and store it to a list (the pickle is a list). Here is my code: ``` import pickle import boto3 s3 = boto3.resource('s3') with open('oldscreenurls.pkl', 'rb') as data: old_list = s3.Bucket("pythonpickles").download_fileobj("oldscreenurls.pkl", d...
2018/02/24
[ "https://Stackoverflow.com/questions/48964181", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6327717/" ]
This is the easiest solution. You can load the data without even downloading the file locally using **S3FileSystem** ``` from s3fs.core import S3FileSystem s3_file = S3FileSystem() data = pickle.load(s3_file.open('{}/{}'.format(bucket_name, file_path))) ```
According to my implementation, S3 file path read with pickle. ``` import pickle import boto3 name = img_url.split('/')[::-1][0] folder = 'media' file_name = f'{folder}/{name}' bucket_name = bucket_name s3 = boto3.client('s3', aws_access_key_id=aws_access_key_id,aws_secret_access_key=aws_secret_access_key) response =...
66,144,386
I have a large list of numbers (4,718,515 of them) and I need to run a method with each of them. I have a method `Check(number)` that needs to be ran with the items in `numbers`. I don't know the most efficient way to go about this in c# Here are some examples of how I was able to do it in other languages if it helps...
2021/02/10
[ "https://Stackoverflow.com/questions/66144386", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10252192/" ]
There should not be any joining since the information is available in that table. Instead of selecting all the columns you can select only DebtAccountReferences as required. ``` select DebtAccountReferences from DebtPayment_DL where PaymentStartDate > '01/01/2021' and CloseDate is null; ```
Based on the information you have given, you do not need a join statement. All of the information you need is stored in the table 'DebtPayment\_DL' Your code is therefore correct and should generate the correct output.
21,361,281
I'm trying to modify a list in a tuple, the `append` method works, while `+=` operator works yet with an exception raised saying tuple could not be modified. I know a tuple is immutable, but I'm not trying to mutate it. Why this happen? ``` In [36]: t=([1,2],) In [37]: t[0].append(123) In [38]: t Out[38]: ([1, 2, 12...
2014/01/26
[ "https://Stackoverflow.com/questions/21361281", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1150712/" ]
Because `t[0] += [4,5,]` is interpreted as: ``` t[0] = t[0].__iadd__([4,5,]) ``` `t[0]__iadd__([4,5])` succeed, while `t[0] = ..` fail. --- `list.__iadd__` extend the list, and return itself. ``` >>> lst = [0] >>> lst2 = lst.__iadd__([1]) >>> lst [0, 1] >>> lst2 [0, 1] >>> lst is lst2 True ```
In fact you **do** change the tuple: The `+` operator for lists creates a new list and you try to mutate your tuple by replacing the old list by the new one. `append`modifies the list in the tuple, therefore it works.
21,361,281
I'm trying to modify a list in a tuple, the `append` method works, while `+=` operator works yet with an exception raised saying tuple could not be modified. I know a tuple is immutable, but I'm not trying to mutate it. Why this happen? ``` In [36]: t=([1,2],) In [37]: t[0].append(123) In [38]: t Out[38]: ([1, 2, 12...
2014/01/26
[ "https://Stackoverflow.com/questions/21361281", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1150712/" ]
Because `t[0] += [4,5,]` is interpreted as: ``` t[0] = t[0].__iadd__([4,5,]) ``` `t[0]__iadd__([4,5])` succeed, while `t[0] = ..` fail. --- `list.__iadd__` extend the list, and return itself. ``` >>> lst = [0] >>> lst2 = lst.__iadd__([1]) >>> lst [0, 1] >>> lst2 [0, 1] >>> lst is lst2 True ```
When we say tuple is immutable, it means that the elements of a tuple (which are references to other objects), cannot be changed (read as, cannot be made to refer other objects). So, when you say, ``` t[0].append(123) ``` You are not changing the element at index 0, to refer some other object. Instead, you are maki...
21,361,281
I'm trying to modify a list in a tuple, the `append` method works, while `+=` operator works yet with an exception raised saying tuple could not be modified. I know a tuple is immutable, but I'm not trying to mutate it. Why this happen? ``` In [36]: t=([1,2],) In [37]: t[0].append(123) In [38]: t Out[38]: ([1, 2, 12...
2014/01/26
[ "https://Stackoverflow.com/questions/21361281", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1150712/" ]
`+=` is the in-place addition operator. It does *two* things: * it calls `obj.__iadd__(rhs)` to give the object the *opportunity* to mutate the object in-place. * it rebinds the reference to whatever the `obj.__iadd__(rhs)` call returns. By using `+=` on a list stored in a tuple, the first step succeeds; the `t[0]` l...
Because `t[0] += [4,5,]` is interpreted as: ``` t[0] = t[0].__iadd__([4,5,]) ``` `t[0]__iadd__([4,5])` succeed, while `t[0] = ..` fail. --- `list.__iadd__` extend the list, and return itself. ``` >>> lst = [0] >>> lst2 = lst.__iadd__([1]) >>> lst [0, 1] >>> lst2 [0, 1] >>> lst is lst2 True ```
21,361,281
I'm trying to modify a list in a tuple, the `append` method works, while `+=` operator works yet with an exception raised saying tuple could not be modified. I know a tuple is immutable, but I'm not trying to mutate it. Why this happen? ``` In [36]: t=([1,2],) In [37]: t[0].append(123) In [38]: t Out[38]: ([1, 2, 12...
2014/01/26
[ "https://Stackoverflow.com/questions/21361281", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1150712/" ]
`+=` is the in-place addition operator. It does *two* things: * it calls `obj.__iadd__(rhs)` to give the object the *opportunity* to mutate the object in-place. * it rebinds the reference to whatever the `obj.__iadd__(rhs)` call returns. By using `+=` on a list stored in a tuple, the first step succeeds; the `t[0]` l...
In fact you **do** change the tuple: The `+` operator for lists creates a new list and you try to mutate your tuple by replacing the old list by the new one. `append`modifies the list in the tuple, therefore it works.
21,361,281
I'm trying to modify a list in a tuple, the `append` method works, while `+=` operator works yet with an exception raised saying tuple could not be modified. I know a tuple is immutable, but I'm not trying to mutate it. Why this happen? ``` In [36]: t=([1,2],) In [37]: t[0].append(123) In [38]: t Out[38]: ([1, 2, 12...
2014/01/26
[ "https://Stackoverflow.com/questions/21361281", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1150712/" ]
`+=` is the in-place addition operator. It does *two* things: * it calls `obj.__iadd__(rhs)` to give the object the *opportunity* to mutate the object in-place. * it rebinds the reference to whatever the `obj.__iadd__(rhs)` call returns. By using `+=` on a list stored in a tuple, the first step succeeds; the `t[0]` l...
When we say tuple is immutable, it means that the elements of a tuple (which are references to other objects), cannot be changed (read as, cannot be made to refer other objects). So, when you say, ``` t[0].append(123) ``` You are not changing the element at index 0, to refer some other object. Instead, you are maki...
50,314,242
I want to save floating-point numbers as pixels in an image file. I am currently working in OpenCV-python, but I had also tried it with Pillow (PIL). Both packages convert `float` pixel data to integer before writing them to the file. I want to save pixel values such as: ```none (245.7865, 123.18788, 98.9866) ``` B...
2018/05/13
[ "https://Stackoverflow.com/questions/50314242", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5256558/" ]
Most likely your are looking for: ``` lapply(seq_along(x), function(i){ quantile(x[1:i], probs = 0.95) }) ``` for each index `i` in `x`, subset `x` from `1` to `i` and return `quantile`. The output will be a list, you can convert it to vector: ``` unlist(lapply(seq_along(x), function(i){ quantile(x[1:i], probs...
Using `rollapply` would be something like the following. ``` library(xts) rollapply(x[, "random"], width = list(seq(-length(x[, "random"]), 0)), FUN = quantile, probs = 0.95, partial = 0) ```
50,314,242
I want to save floating-point numbers as pixels in an image file. I am currently working in OpenCV-python, but I had also tried it with Pillow (PIL). Both packages convert `float` pixel data to integer before writing them to the file. I want to save pixel values such as: ```none (245.7865, 123.18788, 98.9866) ``` B...
2018/05/13
[ "https://Stackoverflow.com/questions/50314242", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5256558/" ]
Most likely your are looking for: ``` lapply(seq_along(x), function(i){ quantile(x[1:i], probs = 0.95) }) ``` for each index `i` in `x`, subset `x` from `1` to `i` and return `quantile`. The output will be a list, you can convert it to vector: ``` unlist(lapply(seq_along(x), function(i){ quantile(x[1:i], probs...
Convert to zoo in which case `rollapplyr.zoo` can handle vector widths: ``` rollapplyr(as.zoo(x), seq_along(x), quantile, probs = 0.95) ``` Another approach is to use a width of `length(x)` and specify `partial=TRUE` : ``` rollapplyr(as.zoo(x), length(x), quantile, probs = 0.95, partial = TRUE) ```
68,873,535
I've a large MPEG (.ts) Binary file, usually a multiple of 188 bytes, I use python3,when I read 188 byte each time and parse to get required value, I found it really slow. I must traverse through each 188 bytes packet to get the value of the PID (binary data). * On the same time when I use any MPEG offline professiona...
2021/08/21
[ "https://Stackoverflow.com/questions/68873535", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8014376/" ]
It's already been copied. A `c_char_p` return is automatically converted to an immutable Python `bytes` object. If the return type was `POINTER(c_char)` *then* you would have a pointer to the actual memory. Sometimes you need the explicit type if you need to pass that pointer to a function to free the memory later. A ...
`c_char_p` by default returns bytes object. So it will print with `b'` bytes. If need to print as string, we can do with `.decode('utf-8')` **Example:** ``` print(b2) # prints b'hello, world!' as bytes print(b2.decode('utf-8')) # prints 'hello, world!' as string ```
38,736,872
I am trying to understand more about `__iter__` in Python 3. For some reason `__getitem__` is better understood by me than `__iter__`. I think I get somehow don't get the corresponding **next** implemention followed with `__iter__`. I have this following code: ``` class Item: def __getitem__(self,pos): re...
2016/08/03
[ "https://Stackoverflow.com/questions/38736872", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2126725/" ]
In general, a really good approach is to make `__iter__` a generator by `yield`ing values. This might be *less* intuitive but it is straight-forward; you just yield back the results you want and `__next__` is then provided automatically for you: ``` class Item: def __iter__(self): for item in range(0, 30, 10)...
Iter returns a iterator, mainly a generator as @machineyearning told at the comments, with next you can iterate over the object, see the example: ``` class Item: def __init__(self): self.elems = range(10) self.current = 0 def __iter__(self): return (x for x in self.elems) def __...
68,019,978
I am building an Ada boost model with Sklearn. Last year I made the same model with the same data, and I was able to access the feature importances. This year when I build the model with the same data the feature importance attribute contains NaNs.I have read some other stuff where people have has the same problem and ...
2021/06/17
[ "https://Stackoverflow.com/questions/68019978", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8684167/" ]
Make an AJAX call to the specific endpoint and update the DOM accordingly.
Laravel is A PHP framework, PHP framework, PHP request data from server and return to client in which it must refresh the page. To archive interchange of data you have few option. **option one** use jquery ajax, it works well and fine with laravel and bootsrtap. Get started [here](https://jquery.com/) on offical websi...
50,735,626
Am trying to make a simple post api in flask-python but am getting this error : ``` TypeError: list object is not an iterator ``` but when i revise my code seems fine what could be the problem. My function which specifically has the problem: ``` def post(self,name): #return {'message': name} item =...
2018/06/07
[ "https://Stackoverflow.com/questions/50735626", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6687699/" ]
Try using `iter()` **Ex:** ``` item = next(iter(filter(lambda x: x['name'] == name, items)), None) ```
To elaborate on @Rakesh's answer, lists aren't iterators, and the output of `filter()` in Python 2 is a list. To fix this, you can use the `iter()` function to output an iterator corresponding to the problematic list so that `next()` can be called appropriately. The same code then should solve your problem: ``` item =...
576,557
If I learn python 3.0 and code in it, will my code be still compatible with Python 2.6 (or 2.5 too!)? --- Remarkably similar to: [If I'm Going to Learn Python, Should I Learn 2.x or Just Jump Into 3.0?](https://stackoverflow.com/questions/410609/if-im-going-to-learn-python-should-i-learn-2-x-or-just-jump-into-3-0/41...
2009/02/23
[ "https://Stackoverflow.com/questions/576557", "https://Stackoverflow.com", "https://Stackoverflow.com/users/69746/" ]
No, 3.x is largely incompatible with 2.x (that was actually a major motivation for doing it). In fact, you probably shouldn't be using 3.0 at all-- it's rather unusable at the moment, and is still mostly intended for library developers to port to it so that it can be usable.
NO. Python 3 code is backwards incompatible with 2.6. I recommend to begin with 2.6, because your code will be more **useful**.
576,557
If I learn python 3.0 and code in it, will my code be still compatible with Python 2.6 (or 2.5 too!)? --- Remarkably similar to: [If I'm Going to Learn Python, Should I Learn 2.x or Just Jump Into 3.0?](https://stackoverflow.com/questions/410609/if-im-going-to-learn-python-should-i-learn-2-x-or-just-jump-into-3-0/41...
2009/02/23
[ "https://Stackoverflow.com/questions/576557", "https://Stackoverflow.com", "https://Stackoverflow.com/users/69746/" ]
No, 3.x is largely incompatible with 2.x (that was actually a major motivation for doing it). In fact, you probably shouldn't be using 3.0 at all-- it's rather unusable at the moment, and is still mostly intended for library developers to port to it so that it can be usable.
It would be easier to use 2.6 right now because most external libraries are not compatible with 3 yet.