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
7,550,823
I've caught myself using this in place of a traditional for loop: ``` _.each(_.range(count), function(i){ ... }); ``` The disadvantage being creating an unnecessary array of size count. Still, i prefer the semantics of, for example, *.each(*.range(10,0,-1), ...); when iterating backwards. Is there any way to do ...
2011/09/26
[ "https://Stackoverflow.com/questions/7550823", "https://Stackoverflow.com", "https://Stackoverflow.com/users/374943/" ]
Considering the [source of underscore.js](http://documentcloud.github.com/underscore/underscore.js) says the following about `range`: > > Generate an integer Array containing an arithmetic progression > > > I doubt there is a way to do lazy iteration without modifying the source.
If you don't mind getting your hands dirty, dig into the sources of the older but stable and feature-complete [MochiKit](http://mochi.github.com/mochikit/)'s [Iter](http://mochi.github.com/mochikit/doc/html/MochiKit/Iter.html) module. It tries to create something along the lines of Python's [itertools](http://docs.pyth...
7,550,823
I've caught myself using this in place of a traditional for loop: ``` _.each(_.range(count), function(i){ ... }); ``` The disadvantage being creating an unnecessary array of size count. Still, i prefer the semantics of, for example, *.each(*.range(10,0,-1), ...); when iterating backwards. Is there any way to do ...
2011/09/26
[ "https://Stackoverflow.com/questions/7550823", "https://Stackoverflow.com", "https://Stackoverflow.com/users/374943/" ]
Considering the [source of underscore.js](http://documentcloud.github.com/underscore/underscore.js) says the following about `range`: > > Generate an integer Array containing an arithmetic progression > > > I doubt there is a way to do lazy iteration without modifying the source.
Just a note: ``` _.each(_.range(count), function(i){ ... }); ``` is equivalent to ``` _.times(count, function(i){ ... }); ``` small is beautiful...
23,175,165
In python, I am trying to check if a given list of values is currently sorted in increasing order and if there are adjacent duplicates in the list. If there are, the code should return True. I am not sure why this code does not work. Any ideas? Thanks in advance!! ``` def main(): values = [1, 4, 9, 16, 25] p...
2014/04/19
[ "https://Stackoverflow.com/questions/23175165", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3495872/" ]
Your `increasingorder` function will almost certainly not work, because Python uses references, and the `sort` function modifies a list in-place and returns `None`. That means that after your call `a = hlist.sort()`, both `hlist` will be sorted and `a` will be `None`. so they will not compare equal. You probably meant...
Try creating a True False function for each value check operation you want done taking the list as a parameter. then call each function like "if 1 and 2 print 3" format. That may make thinking through the flow a little easier. Is this kind of what you were wanting? ``` def isincreasing(values): if values==sorted(...
20,529,457
Please excuse this naive question of mine. I am trying to monitor memory usage of my python code, and have come across the promising [`memory_profiler`](https://pypi.python.org/pypi/memory_profiler) package. I have a question about interpreting the output generated by @profile decorator. Here is a sample output that ...
2013/12/11
[ "https://Stackoverflow.com/questions/20529457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1146372/" ]
According to [the docs](https://pypi.python.org/pypi/memory_profiler): > > The first column represents the line number of the code that has been profiled, the second column (Mem usage) the memory usage of the Python interpreter after that line has been executed. The third column (Increment) represents the difference ...
The difference in memory between lines is given in the second column or you could write a small script to process the output.
67,395,047
I have written several python scripts that will backtest trading strategies. I am attempting to deploy these through docker compose. The feeder container copies test files to a working directory where the backtester containers will pick them up and process them. The processed test files are then sent to a "completed w...
2021/05/05
[ "https://Stackoverflow.com/questions/67395047", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15838493/" ]
It's been three weeks with no responses, but I just wanted to update with what I've found. In all cases where I've left "docker-compose up" running it eventually started. At times it took 30 minutes, but it started every time.
I faced the same problem and fix it with this tip: > > resolved It turns out if I run my docker command with "python3 -u" it will force python to run unbuffered. It was a buffering issue. > > > source: <https://www.reddit.com/r/docker/comments/gk262t/comment/fqos8j8/?utm_source=share&utm_medium=web2x&context=3>
15,152,174
I am using python version 3. For homework, I am trying to allow five digits of input from the user, then find the average of those digits. I have figured that part out (spent an hour learning about the map function, very cool). The second part of the problem is to compare each individual element of the list to the av...
2013/03/01
[ "https://Stackoverflow.com/questions/15152174", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2121886/" ]
you can add your custom class with your own css property like below ``` $this->addElement(new Zend_Form_Element_Button( 'send', array( 'label' => 'registrieren', 'class' => 'button-red', 'type' => 'submit', 'escape' => f...
Yes just apply the appropriate CSS to the 'div', 'tag' or 'class' as required. [22 CSS Button Styling Tutorials and Techniques](http://speckyboy.com/2009/05/27/22-css-button-styling-tutorials-and-techniques/) may help.
2,683,810
I'd ideally like a vim answer to this: I want to change ``` [*, 1, *, *] to [*, 2, *, *] ``` Here the stars refer to individual characters in the substring, which I would like to keep unchanged. For example ``` [0, 1, 0, 1] to [0, 2, 0, 1] [1, 1, 1, 1] to [1, 2, 1, 1] ``` If people know how to do this in perl or...
2010/04/21
[ "https://Stackoverflow.com/questions/2683810", "https://Stackoverflow.com", "https://Stackoverflow.com/users/194675/" ]
The following should do what you want: ``` :%s/\(\[[^,]*, *\)\(\d\)\([^]]*\]\)/\=submatch(1) . (submatch(2)+1) . submatch(3)/ ``` In Vim, that is.
If those are strings in Python ``` >>> a = "[0, 1, 0, 1]" >>> b = a[:4] + '2' + a[5:] >>> b '[0, 2, 0, 1]' ``` Lists are a little more trivial: ``` >>> c = [0, 1, 0, 1] >>> c[1] = 2 >>> c [0, 2, 0, 1] >>> ```
2,683,810
I'd ideally like a vim answer to this: I want to change ``` [*, 1, *, *] to [*, 2, *, *] ``` Here the stars refer to individual characters in the substring, which I would like to keep unchanged. For example ``` [0, 1, 0, 1] to [0, 2, 0, 1] [1, 1, 1, 1] to [1, 2, 1, 1] ``` If people know how to do this in perl or...
2010/04/21
[ "https://Stackoverflow.com/questions/2683810", "https://Stackoverflow.com", "https://Stackoverflow.com/users/194675/" ]
This works :) ``` 1,$s/\[\(\d\+\),\s\+\d\+,\s\+\(\d\+\),\s\+\(\d\+\)\]/[\1, 2, \2, \3]/g ``` or ``` %s/\[\(\d\+\),\s\+\d\+,\s\+\(\d\+\),\s\+\(\d\+\)\]/[\1, 2, \2, \3]/ ```
The following should do what you want: ``` :%s/\(\[[^,]*, *\)\(\d\)\([^]]*\]\)/\=submatch(1) . (submatch(2)+1) . submatch(3)/ ``` In Vim, that is.
2,683,810
I'd ideally like a vim answer to this: I want to change ``` [*, 1, *, *] to [*, 2, *, *] ``` Here the stars refer to individual characters in the substring, which I would like to keep unchanged. For example ``` [0, 1, 0, 1] to [0, 2, 0, 1] [1, 1, 1, 1] to [1, 2, 1, 1] ``` If people know how to do this in perl or...
2010/04/21
[ "https://Stackoverflow.com/questions/2683810", "https://Stackoverflow.com", "https://Stackoverflow.com/users/194675/" ]
The following should do what you want: ``` :%s/\(\[[^,]*, *\)\(\d\)\([^]]*\]\)/\=submatch(1) . (submatch(2)+1) . submatch(3)/ ``` In Vim, that is.
This one is shorter and a little more general purpose. ``` :%s/\(\[[^,],\s*\)1,/\12,/ ``` The pattern doesn't care what is in the first slot of the list, and doesn't look at the rest of the list. This may be better, or worse, depending on what exactly you're trying to do.
2,683,810
I'd ideally like a vim answer to this: I want to change ``` [*, 1, *, *] to [*, 2, *, *] ``` Here the stars refer to individual characters in the substring, which I would like to keep unchanged. For example ``` [0, 1, 0, 1] to [0, 2, 0, 1] [1, 1, 1, 1] to [1, 2, 1, 1] ``` If people know how to do this in perl or...
2010/04/21
[ "https://Stackoverflow.com/questions/2683810", "https://Stackoverflow.com", "https://Stackoverflow.com/users/194675/" ]
The following should do what you want: ``` :%s/\(\[[^,]*, *\)\(\d\)\([^]]*\]\)/\=submatch(1) . (submatch(2)+1) . submatch(3)/ ``` In Vim, that is.
Note while using regexes for substitutions/modifications it is important to focus around the portion of the string you want to modify. Here is a short regex to do what you want (in perl), that illustrates this idea with your data. Assuming $line contains the line you want to modify ``` my $two=2; $line =~ s/(,\s...
2,683,810
I'd ideally like a vim answer to this: I want to change ``` [*, 1, *, *] to [*, 2, *, *] ``` Here the stars refer to individual characters in the substring, which I would like to keep unchanged. For example ``` [0, 1, 0, 1] to [0, 2, 0, 1] [1, 1, 1, 1] to [1, 2, 1, 1] ``` If people know how to do this in perl or...
2010/04/21
[ "https://Stackoverflow.com/questions/2683810", "https://Stackoverflow.com", "https://Stackoverflow.com/users/194675/" ]
This works :) ``` 1,$s/\[\(\d\+\),\s\+\d\+,\s\+\(\d\+\),\s\+\(\d\+\)\]/[\1, 2, \2, \3]/g ``` or ``` %s/\[\(\d\+\),\s\+\d\+,\s\+\(\d\+\),\s\+\(\d\+\)\]/[\1, 2, \2, \3]/ ```
If those are strings in Python ``` >>> a = "[0, 1, 0, 1]" >>> b = a[:4] + '2' + a[5:] >>> b '[0, 2, 0, 1]' ``` Lists are a little more trivial: ``` >>> c = [0, 1, 0, 1] >>> c[1] = 2 >>> c [0, 2, 0, 1] >>> ```
2,683,810
I'd ideally like a vim answer to this: I want to change ``` [*, 1, *, *] to [*, 2, *, *] ``` Here the stars refer to individual characters in the substring, which I would like to keep unchanged. For example ``` [0, 1, 0, 1] to [0, 2, 0, 1] [1, 1, 1, 1] to [1, 2, 1, 1] ``` If people know how to do this in perl or...
2010/04/21
[ "https://Stackoverflow.com/questions/2683810", "https://Stackoverflow.com", "https://Stackoverflow.com/users/194675/" ]
This works :) ``` 1,$s/\[\(\d\+\),\s\+\d\+,\s\+\(\d\+\),\s\+\(\d\+\)\]/[\1, 2, \2, \3]/g ``` or ``` %s/\[\(\d\+\),\s\+\d\+,\s\+\(\d\+\),\s\+\(\d\+\)\]/[\1, 2, \2, \3]/ ```
This one is shorter and a little more general purpose. ``` :%s/\(\[[^,],\s*\)1,/\12,/ ``` The pattern doesn't care what is in the first slot of the list, and doesn't look at the rest of the list. This may be better, or worse, depending on what exactly you're trying to do.
2,683,810
I'd ideally like a vim answer to this: I want to change ``` [*, 1, *, *] to [*, 2, *, *] ``` Here the stars refer to individual characters in the substring, which I would like to keep unchanged. For example ``` [0, 1, 0, 1] to [0, 2, 0, 1] [1, 1, 1, 1] to [1, 2, 1, 1] ``` If people know how to do this in perl or...
2010/04/21
[ "https://Stackoverflow.com/questions/2683810", "https://Stackoverflow.com", "https://Stackoverflow.com/users/194675/" ]
This works :) ``` 1,$s/\[\(\d\+\),\s\+\d\+,\s\+\(\d\+\),\s\+\(\d\+\)\]/[\1, 2, \2, \3]/g ``` or ``` %s/\[\(\d\+\),\s\+\d\+,\s\+\(\d\+\),\s\+\(\d\+\)\]/[\1, 2, \2, \3]/ ```
Note while using regexes for substitutions/modifications it is important to focus around the portion of the string you want to modify. Here is a short regex to do what you want (in perl), that illustrates this idea with your data. Assuming $line contains the line you want to modify ``` my $two=2; $line =~ s/(,\s...
30,083,603
Alright here's a question that's eating me from inside so any help is appreciated. I have a web service that returns a list of items. The number of items returned is governed by two variables 'page' and 'per\_page'. So a URL like ``` abc.com?page=10&per_page=100 ``` Will show the 10th page with 100 items in it. I ...
2015/05/06
[ "https://Stackoverflow.com/questions/30083603", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4484709/" ]
Is there a compelling reason to not over-request? `abc.com?page=2&per_page=1024` Just always set `page=2` and `per_page` = number of items cached. The only weird case is when the number of added elements is greater than the number of items cached, in which case you have to `abc.com?page=1&per_page=99999`
Here's the code with a small bug-fix to give the most optimal page size (the suggested code wouldn't return a page size that exactly divides the total count). ``` def items_per_page(total_item_count,new_item_count): for i in itertools.count(new_item_count): if total_items % i>= new_item_count or total_it...
30,083,603
Alright here's a question that's eating me from inside so any help is appreciated. I have a web service that returns a list of items. The number of items returned is governed by two variables 'page' and 'per\_page'. So a URL like ``` abc.com?page=10&per_page=100 ``` Will show the 10th page with 100 items in it. I ...
2015/05/06
[ "https://Stackoverflow.com/questions/30083603", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4484709/" ]
so start with the knowledge that you need to have `per_page` at least equal to the number of new items (assuming you want them all on the same page) ``` def items_per_page(total_item_count,new_item_count): for i in itertools.count(new_item_count): if total_items % i>= new_item_count: return i...
Here's the code with a small bug-fix to give the most optimal page size (the suggested code wouldn't return a page size that exactly divides the total count). ``` def items_per_page(total_item_count,new_item_count): for i in itertools.count(new_item_count): if total_items % i>= new_item_count or total_it...
44,967,366
Working in python with ESRI's arcpy, I'm trying to sum values across multiple fields with an arcpy updateCursor . I'm trying to convert the None items to an 0. However, I can't figure out a way to convert the None items. I'm open to anything. ``` with arcpy.da.UpdateCursor(feature_class, score_fields) as cursor: ...
2017/07/07
[ "https://Stackoverflow.com/questions/44967366", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8269863/" ]
You should update `row` by assigning the result of the list comprehension to `row`: ``` for row in cursor: row = [0 if x is None else x+4 for x in row] ``` Also, note that since there is only one `None` object, better to test with `is` than use `==`; more Pythonic, more performant.
You can use an if statement to filter the `None` values in your list: ``` sum(row[i] for i in range(len(score_fields)) if row[i] is not None) ```
7,720,435
What is the best way to implement a tree structure (generic - not binary) in python? My intuition would have the following skeleton: ``` class TNode(self, data): #enter things for each individual node class TStructure(self): #enter code for implementing nodes that reference each other. ```
2011/10/11
[ "https://Stackoverflow.com/questions/7720435", "https://Stackoverflow.com", "https://Stackoverflow.com/users/382906/" ]
Any function which is going to be inlined must have its full source in the .di file. Any function which is going to be used in CTFE must not only have its full source in the .di file, but the full source of every function that it uses - directly or indirectly - must be available to the compiler. Also, because of how te...
> > Hardly a paragon of optimization. > > > No, that **is** an optimization. The compiler will leave the implementation in the interface file if the implementation is small enough that it can later be inlined.
69,255,736
`TypeError: unsupported operand type(s) for /: 'str' and 'float'` I'm making a football game, and I get this whenever I try to run the following code to determine how far a play will go. `playdistance = round(random.uniform(float(rbs.get(possession)[-2:]/float(30.0))-2.5,float(rbs.get(possession)[-2:]/float(30.0))+5....
2021/09/20
[ "https://Stackoverflow.com/questions/69255736", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16957998/" ]
You can't combine strings and numbers like that in Python. `rbs.get(possession)[-2:]` gives you a string, e.g. `'99'`, and `float(30.0)` gives you a number. The division of strings by numbers is not defined. You must convert the '99' to a number first before you can divide it by anything. Technically speaking, you on...
When I indent your code to make it more readable, the problem becomes evident ``` playdistance = round( random.uniform( float( rbs.get(possession)[-2:] / float(30.0) # error 1 ) - 2.5, float( rbs.get(possession)[-2:] / float(30.0) # error 2 ) + 5.5 ) ) ``` `r...
69,255,736
`TypeError: unsupported operand type(s) for /: 'str' and 'float'` I'm making a football game, and I get this whenever I try to run the following code to determine how far a play will go. `playdistance = round(random.uniform(float(rbs.get(possession)[-2:]/float(30.0))-2.5,float(rbs.get(possession)[-2:]/float(30.0))+5....
2021/09/20
[ "https://Stackoverflow.com/questions/69255736", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16957998/" ]
When I indent your code to make it more readable, the problem becomes evident ``` playdistance = round( random.uniform( float( rbs.get(possession)[-2:] / float(30.0) # error 1 ) - 2.5, float( rbs.get(possession)[-2:] / float(30.0) # error 2 ) + 5.5 ) ) ``` `r...
That fixes your problem where you need to convert to `float` before your divided ``` import numpy rbs={'NYG':'Saquon Barkley 99' } playdistance = float(round(numpy.random.uniform(float(rbs.get(possession)[-2:])/float(30.0)-2.5,float(rbs.get(possession)[-2:])/float(30.0))+5.5)) print(playdistance) ```
69,255,736
`TypeError: unsupported operand type(s) for /: 'str' and 'float'` I'm making a football game, and I get this whenever I try to run the following code to determine how far a play will go. `playdistance = round(random.uniform(float(rbs.get(possession)[-2:]/float(30.0))-2.5,float(rbs.get(possession)[-2:]/float(30.0))+5....
2021/09/20
[ "https://Stackoverflow.com/questions/69255736", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16957998/" ]
You can't combine strings and numbers like that in Python. `rbs.get(possession)[-2:]` gives you a string, e.g. `'99'`, and `float(30.0)` gives you a number. The division of strings by numbers is not defined. You must convert the '99' to a number first before you can divide it by anything. Technically speaking, you on...
That fixes your problem where you need to convert to `float` before your divided ``` import numpy rbs={'NYG':'Saquon Barkley 99' } playdistance = float(round(numpy.random.uniform(float(rbs.get(possession)[-2:])/float(30.0)-2.5,float(rbs.get(possession)[-2:])/float(30.0))+5.5)) print(playdistance) ```
12,948,935
``` $ ps aux | grep file1.py xyz 6103 0.0 0.1 33476 6480 pts/1 S+ 12:00 0:00 python file1.py xyz 6188 0.0 0.1 33476 6472 pts/2 S+ 12:05 0:00 python file1.py xyz 7294 0.0 0.0 8956 872 pts/4 S+ 12:49 0:00 grep --color=auto file1.py ``` process 6103 has started at 12:00 and af...
2012/10/18
[ "https://Stackoverflow.com/questions/12948935", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1051068/" ]
What about something like this, if you are not worried of the **os.popen()** ``` #!/usr/bin/python import os PROCNAME = "file1.py" pids = [] for proc_data in os.popen('/bin/ps -eo pid,comm,args'): bits = proc_data.strip().split() (pid, comm ) = bits[0:2] args = " ".join( bits[3:] ) if args == PROCNAME:...
please read up on `pidof`: ``` man pidof ```
58,461,785
While studying data types in Python, I encountered a data type range and used a variable to define it. However using type function to know about this still tells that it's a list data types. Am I missing something here? Please guide. Thank you so much. ``` x = range(3) print(type(x)) ``` Output is as shown below: ...
2019/10/19
[ "https://Stackoverflow.com/questions/58461785", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8808220/" ]
It seems you are mixing up Python 3 and 2. These are two major versions of Python. Python 3000 introduced many intentionally backwards incompatible changes including in the workings of the range function. In Python 2, the range function immediately expanded out to a list `list_range = list(range(3))` In Python 3 it...
With Python2, range returned the list. If you try to run your code with python3, it returns the 'range' type as a output of your code.
2,913,626
I need to parse a string `'Open URN: 100000 LA: '` and get 100000 from it. on python regexp `(?<=Open URN: )[0-9]+(?= LA:)` works fine but in php it gives following error: ``` preg_match(): Unknown modifier '[' ``` I need it working php, so please help me to solve this problem and tell about difference in python and...
2010/05/26
[ "https://Stackoverflow.com/questions/2913626", "https://Stackoverflow.com", "https://Stackoverflow.com/users/350981/" ]
You have to use [delimiters](http://www.php.net/manual/en/regexp.reference.delimiters.php) when you are using the [*Perl Compatible Regular Expressions* (PCRE) functions](http://www.php.net/manual/en/book.pcre.php) in PHP (to which [`preg_match()`](http://php.net/manual/en/function.preg-match.php) belongs). From the [...
Except of mentioned differences I found one more. re.match(r"\s", "a b") in python with preg\_match("/\s/", "a b"), the first doesn't return matches in python while the second will find space symbol. I didn't find why in official docs, it's hard to understand but it's a fact.
22,286,332
I am parsing log files in size of 1 to 10GB using python3.2, need to search for line with specific regex (some kind of timestamp), and I want to find the last occurance. I have tried to use: ``` for line in reversed(list(open("filename"))) ``` which resulted in very bad performance (in the good cases) and MemoryErr...
2014/03/09
[ "https://Stackoverflow.com/questions/22286332", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3399166/" ]
Looks like you have mistake in code: ``` echo $row['PersonnelD']; ``` shouldn't it be following? ``` echo $row['PersonnelID']; ```
check the mysql\_fetch\_assoc() function may be its parameter is empty so it can't enter the while loop
22,286,332
I am parsing log files in size of 1 to 10GB using python3.2, need to search for line with specific regex (some kind of timestamp), and I want to find the last occurance. I have tried to use: ``` for line in reversed(list(open("filename"))) ``` which resulted in very bad performance (in the good cases) and MemoryErr...
2014/03/09
[ "https://Stackoverflow.com/questions/22286332", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3399166/" ]
check the mysql\_fetch\_assoc() function may be its parameter is empty so it can't enter the while loop
In both your querys, you have ``` "SELECT * FROM validPersonnel WHERE Passkey = '$password' and Name = '$name'" ``` It should be: ``` "SELECT * FROM validPersonnel WHERE Passkey = '".$password."' and Name = '".$name."';" ``` PHP doesn't recognize the $var unless you close the quotes. The period adds the $var to...
22,286,332
I am parsing log files in size of 1 to 10GB using python3.2, need to search for line with specific regex (some kind of timestamp), and I want to find the last occurance. I have tried to use: ``` for line in reversed(list(open("filename"))) ``` which resulted in very bad performance (in the good cases) and MemoryErr...
2014/03/09
[ "https://Stackoverflow.com/questions/22286332", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3399166/" ]
check the mysql\_fetch\_assoc() function may be its parameter is empty so it can't enter the while loop
Try to debug and check the values came in the variables using `var_dump()` function. Ex: `var_dump($row);` in while loop.
22,286,332
I am parsing log files in size of 1 to 10GB using python3.2, need to search for line with specific regex (some kind of timestamp), and I want to find the last occurance. I have tried to use: ``` for line in reversed(list(open("filename"))) ``` which resulted in very bad performance (in the good cases) and MemoryErr...
2014/03/09
[ "https://Stackoverflow.com/questions/22286332", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3399166/" ]
Looks like you have mistake in code: ``` echo $row['PersonnelD']; ``` shouldn't it be following? ``` echo $row['PersonnelID']; ```
In both your querys, you have ``` "SELECT * FROM validPersonnel WHERE Passkey = '$password' and Name = '$name'" ``` It should be: ``` "SELECT * FROM validPersonnel WHERE Passkey = '".$password."' and Name = '".$name."';" ``` PHP doesn't recognize the $var unless you close the quotes. The period adds the $var to...
22,286,332
I am parsing log files in size of 1 to 10GB using python3.2, need to search for line with specific regex (some kind of timestamp), and I want to find the last occurance. I have tried to use: ``` for line in reversed(list(open("filename"))) ``` which resulted in very bad performance (in the good cases) and MemoryErr...
2014/03/09
[ "https://Stackoverflow.com/questions/22286332", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3399166/" ]
Looks like you have mistake in code: ``` echo $row['PersonnelD']; ``` shouldn't it be following? ``` echo $row['PersonnelID']; ```
Try to debug and check the values came in the variables using `var_dump()` function. Ex: `var_dump($row);` in while loop.
38,092,236
(windows 7, python 2.7.3) Here is my code: ``` from Tkinter import * root = Tk() root.geometry('400x400') Frame(root, width=20, height=20, bg='red').pack(expand=NO, fill=None, side=LEFT) Label(root, width=20, height=20, bg='black').pack(expand=NO, fill=None, side=LEFT) root.mainloop() ``` And the result is like th...
2016/06/29
[ "https://Stackoverflow.com/questions/38092236", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6032273/" ]
**Short answer:** 20 is the same as 20, but 20 meters is not the same as 20 kilometers. **Long answer:** The result you got is not as weird as you may think because the `width` and `height` options of `Tkinter.Frame()` are measured in terms of **pixels** whereas in `Tkinter.Label()`: * `width`: defines the width of...
As I know Label is used for text. Label() definition and Frame() might work differently for width and height parameters, correct me if am wrong. example: change width and height inside Label() to 1. you will see space for one character filled with black color in tk window. like `Label(root, width=1, height=1, bg='...
59,028,392
I have my docker containers up and running. There is one container running some python code and I found that it is causing some bug. I want to add some lines of code (mainly more logs) to a python script within that particular container. I want to just go into the container by `docker exec -ti container_name bash` an...
2019/11/25
[ "https://Stackoverflow.com/questions/59028392", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3703783/" ]
A couple of facts about docker containers: 1. Docker container lives as long as the process it runs lives usually. 2. Docker container is immutable, so whatever changes you do in filesystem of the container itself won't survive the restart of container (I'm not talking about volumes, its more advanced stuff) Based on...
Answering because there's some misinformation in other answers here. The correct answer is in the comment from [MyTwoCents](https://stackoverflow.com/questions/59028392/do-docker-containers-pick-up-code-changes-on-the-fly#comment104300981_59028392): > > It will behave same way as it would when you do it on your syste...
17,771,131
While following a tutorial for python, I got to know that we can use *print* for a variable name, and it works fine. But after assigning the print variable, how do we get back the original print function? ``` >>> print("Hello World!!") Hello World!!! >>> print = 5 >>> print("Hi") ``` Now, the last call gives the err...
2013/07/21
[ "https://Stackoverflow.com/questions/17771131", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1936532/" ]
``` >>> print = 5 >>> print = __builtins__.print >>> print("hello") hello ```
You can actually delete the variable so the built-in function will work again: ``` >>> print = 5 >>> print('cabbage') Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'int' object is not callable >>> del print >>> print('cabbage') cabbage ```
17,771,131
While following a tutorial for python, I got to know that we can use *print* for a variable name, and it works fine. But after assigning the print variable, how do we get back the original print function? ``` >>> print("Hello World!!") Hello World!!! >>> print = 5 >>> print("Hi") ``` Now, the last call gives the err...
2013/07/21
[ "https://Stackoverflow.com/questions/17771131", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1936532/" ]
``` >>> print = 5 >>> print = __builtins__.print >>> print("hello") hello ```
If you want to use as a temp way, do them but after that, apply `print` function to `print` variable: ``` print = __builtins__.print ```
66,730,834
I have created a conda environment and activated it already. Then inside the `use_cases/` directory I execute: `pip install -e use_case_b` (<https://github.com/geoHeil/dagster-demo/tree/master/use_cases>): ``` ... ... Installing collected packages: use-case-b Attempting uninstall: use-case-b Found existing inst...
2021/03/21
[ "https://Stackoverflow.com/questions/66730834", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2587904/" ]
When you get an error, please post it along with your question. When you are getting an error, it means that something is wrong with your code,and most likely not the flutter engine. Both are important for debugging, the error+your code. Try changing this ``` QuerySnapshot _getPost = await _firestore .collection(...
For people facing similar issues, let me tell what I found in my code: ***The error says that the children is null, not empty !*** So if you are getting the children for the parent widget like Row or Column from a separate method, ***just check if you are returning the constructed child widget from the method***. ``...
55,355,504
I have a txt file that contains "blocks of consecutive lines", each block representing one observation whereas the different lines within each block represent the value of one variable of the corresponding observation. I worked my way to here using python and I would like to read the .txt file into Stata. Therefore, I...
2019/03/26
[ "https://Stackoverflow.com/questions/55355504", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11259841/" ]
Try ``` with open('my_file.txt','r') as f: # lines should hold the data with no new lines lines = [l.strip() for l in f.readlines()] ```
you can extend the balderman's answer: ``` with open('filename.txt','r') as f: lines = [l.strip() for l in f.readlines()] ``` This part will create the list of lines of whole file. To create a single line for variables in each block you can just use dictionary to store variables in each block. Example: ``` bloc...
45,715,062
I try to create a domain filter what should look like this: ``` (Followup date < today) AND (customer = TRUE OR user_id = user.id) ``` I did it like following: ``` [('follow_up_date', '&lt;=', datetime.datetime.now().strftime('%Y-%m-%d 00:00:00')),['|', ('customer', '=', 'False'),('user_id', '=', 'user.id')]] ``` ...
2017/08/16
[ "https://Stackoverflow.com/questions/45715062", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7126858/" ]
Odoo uses the [polish notation](https://en.wikipedia.org/wiki/Polish_notation). If you'd like to use the logical expression `(A) AND (B OR C)` as a domain, that means you will have to use: `AND A OR B C`. If you'd like more information about polish notation please check the link. This means that, if I understand the q...
Try without brackets in the second expression: ``` [('follow_up_date', '&lt;=', datetime.datetime.now().strftime('%Y-%m-%d 00:00:00')),'|', ('customer', '=', 'False'),('user_id', '=', 'user.id')'] ``` I hope this help you.
66,029,297
I parsed a function from python which converts for ex. "5m" to 300 seconds (integer). My question is about the regex expression I did, because I know it's slow compared to anything else. What is the best way to get the integer part of the `timeframe` and the string part as well into a separate string? Basically, what I...
2021/02/03
[ "https://Stackoverflow.com/questions/66029297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13677853/" ]
there's no need to use [regexes](https://blog.codinghorror.com/regular-expressions-now-you-have-two-problems/) for this. just translate *what the existing python code does*: accessing substrings of your input. ``` var amount = int.Parse(timeframe.Substring(0, timeframe.Length - 1)); var unit = timeframe.Substr...
Alternatively, if you have a proper TimeSpan, you can cast your string to `TimeSpan` and then use the `TotalSeconds` prop. That will also get rid of all the if-else ifs that you have. ``` if (TimeSpan.TryParse(timeframe, out var timeSpan)) { Console.WriteLine(timeSpan.TotalSeconds); } ``` \*Edit: As is, you assu...
8,296,617
i hope the title itself was quite clear , i am solving 2D lid-driven cavity(square domain) problem using fractional step method , finite difference formulation (Navier-Stokes primitive variable form) , i have got u and v components of velocity over the entire domain , without manually calculating streamlines , is there...
2011/11/28
[ "https://Stackoverflow.com/questions/8296617", "https://Stackoverflow.com", "https://Stackoverflow.com/users/616809/" ]
Have a look at [Tom Flannaghan's `streamplot` function](http://www.atm.damtp.cam.ac.uk/people/tjf37/streamplot.py). The [relevant thread on the user's list is here](http://old.nabble.com/Any-update-on-streamline-plot-td30902670.html), and there's also another [similar code snippet by Ray Speth](http://web.mit.edu/speth...
Have a look at `matplotlib`'s `quiver`: <http://matplotlib.sourceforge.net/examples/pylab_examples/quiver_demo.html>
8,296,617
i hope the title itself was quite clear , i am solving 2D lid-driven cavity(square domain) problem using fractional step method , finite difference formulation (Navier-Stokes primitive variable form) , i have got u and v components of velocity over the entire domain , without manually calculating streamlines , is there...
2011/11/28
[ "https://Stackoverflow.com/questions/8296617", "https://Stackoverflow.com", "https://Stackoverflow.com/users/616809/" ]
Have a look at [Tom Flannaghan's `streamplot` function](http://www.atm.damtp.cam.ac.uk/people/tjf37/streamplot.py). The [relevant thread on the user's list is here](http://old.nabble.com/Any-update-on-streamline-plot-td30902670.html), and there's also another [similar code snippet by Ray Speth](http://web.mit.edu/speth...
In version 1.2 of Matplotlib, there is now a [streamplot](http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.streamplot) function.
71,825,406
I try to search the answer in stackoverflow and try to find something in the github [issues](https://github.com/googleapis/python-logging/issues) but nothing I found. Can anyone give me some tip to solve the problem? I get the following error when trying to install Google Cloud Logging by pip with docker: ``` test_we...
2022/04/11
[ "https://Stackoverflow.com/questions/71825406", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11296376/" ]
Upgrade your protobuf to 3.20.1. Unsure why its happening. Here's the git issue: <https://github.com/googleapis/python-iam/issues/185>
I had the same error while using `google-cloud-secret-manager` and `poetry`. Removing unused `gcloud` dependency as well as `google-cloud-secret-manager` and reinstalling `google-cloud-secret-manager` solved it. ``` poetry remove gcloud poetry remove google-cloud-secret-manager poetry add google-cloud-secret-manager ...
8,618,984
The server only allows access to the videos if the useragent is QT, how to add it to this script ? ``` #!/usr/bin/env python from os import pardir, rename, listdir, getcwd from os.path import join from urllib import urlopen, urlretrieve, FancyURLopener class MyOpener(FancyURLopener): version = 'QuickTime/7.6.2 (ve...
2011/12/23
[ "https://Stackoverflow.com/questions/8618984", "https://Stackoverflow.com", "https://Stackoverflow.com/users/891489/" ]
I found the solution. Practically I needed to set the Layout\_width of each container with the weight property to 0px.
From what I can tell, it seems your weightSum should be 12, not 10. First LinearLayout has weight=2, the second weight=8 and the third weight=2. It might solve your problem!
8,618,984
The server only allows access to the videos if the useragent is QT, how to add it to this script ? ``` #!/usr/bin/env python from os import pardir, rename, listdir, getcwd from os.path import join from urllib import urlopen, urlretrieve, FancyURLopener class MyOpener(FancyURLopener): version = 'QuickTime/7.6.2 (ve...
2011/12/23
[ "https://Stackoverflow.com/questions/8618984", "https://Stackoverflow.com", "https://Stackoverflow.com/users/891489/" ]
I found the solution. Practically I needed to set the Layout\_width of each container with the weight property to 0px.
AFAIK, weight in linear layout is not so linear. Component with a biggest weights wins all the extra space. For playing around with layouts I highly recommend latest IntelliJ Idea - even free comminity edition has android plugin with really usefull layout preview.
29,985,453
I am getting this strange to me error when installing Keras on an Ubuntu server: ``` Cythonizing /tmp/easy_install-qQggXs/h5py-2.5.0/h5py/utils.pyx In file included from /usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1804:0, from /usr/local/lib/python2.7/dist-packages/n...
2015/05/01
[ "https://Stackoverflow.com/questions/29985453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4262897/" ]
you can use sparql query to Dbpedia to get result for you particular resource, which here is [Vienna](http://dbpedia.org/page/Vienna). To get all property and their value of resource Vienna use can use ``` select ?property ?value where { <http://dbpedia.org/resource/Vienna> ?property ?value } ``` [Check here](htt...
> > *But what I want is something … to get all items where any property fits "Vienna"[.]* > > > In SPARQL this is very easy. E.g., on [DBpedia's SPARQL endpoint](http://dbpedia.org/sparql/): ``` select ?resource where { ?resource ?property dbpedia:Vienna } ``` [SPARQL results (limited to 100)](http://dbpedia...
29,985,453
I am getting this strange to me error when installing Keras on an Ubuntu server: ``` Cythonizing /tmp/easy_install-qQggXs/h5py-2.5.0/h5py/utils.pyx In file included from /usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1804:0, from /usr/local/lib/python2.7/dist-packages/n...
2015/05/01
[ "https://Stackoverflow.com/questions/29985453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4262897/" ]
maybe something like this: ``` SELECT ?node WHERE {?node ?pred wd:Q1741} ``` see on [Wikidata Query Service](https://query.wikidata.org/#SELECT%20%3Fnode%20WHERE%20%7B%3Fnode%20%3Fpred%20wd%3AQ1741%7D%20%20%20%20%0A)
> > *But what I want is something … to get all items where any property fits "Vienna"[.]* > > > In SPARQL this is very easy. E.g., on [DBpedia's SPARQL endpoint](http://dbpedia.org/sparql/): ``` select ?resource where { ?resource ?property dbpedia:Vienna } ``` [SPARQL results (limited to 100)](http://dbpedia...
29,985,453
I am getting this strange to me error when installing Keras on an Ubuntu server: ``` Cythonizing /tmp/easy_install-qQggXs/h5py-2.5.0/h5py/utils.pyx In file included from /usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1804:0, from /usr/local/lib/python2.7/dist-packages/n...
2015/05/01
[ "https://Stackoverflow.com/questions/29985453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4262897/" ]
you can use sparql query to Dbpedia to get result for you particular resource, which here is [Vienna](http://dbpedia.org/page/Vienna). To get all property and their value of resource Vienna use can use ``` select ?property ?value where { <http://dbpedia.org/resource/Vienna> ?property ?value } ``` [Check here](htt...
There are already some SPARQL endpoints for Wikidata available. However, they are still beta and only reflect the data from the last dump. Your query would be [this one](http://wikisparql.org/sparql?showquery=SELECT%20%3Fresource%0D%0AWHERE%20%7B%0D%0A%3Fresource%20%3Fproperty%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fenti...
29,985,453
I am getting this strange to me error when installing Keras on an Ubuntu server: ``` Cythonizing /tmp/easy_install-qQggXs/h5py-2.5.0/h5py/utils.pyx In file included from /usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1804:0, from /usr/local/lib/python2.7/dist-packages/n...
2015/05/01
[ "https://Stackoverflow.com/questions/29985453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4262897/" ]
maybe something like this: ``` SELECT ?node WHERE {?node ?pred wd:Q1741} ``` see on [Wikidata Query Service](https://query.wikidata.org/#SELECT%20%3Fnode%20WHERE%20%7B%3Fnode%20%3Fpred%20wd%3AQ1741%7D%20%20%20%20%0A)
There are already some SPARQL endpoints for Wikidata available. However, they are still beta and only reflect the data from the last dump. Your query would be [this one](http://wikisparql.org/sparql?showquery=SELECT%20%3Fresource%0D%0AWHERE%20%7B%0D%0A%3Fresource%20%3Fproperty%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fenti...
31,466,769
Similar to this question [How to add an empty column to a dataframe?](https://stackoverflow.com/questions/16327055/how-to-add-an-empty-column-to-a-dataframe), I am interested in knowing the best way to add a column of empty lists to a DataFrame. What I am trying to do is basically initialize a column and as I iterate ...
2015/07/17
[ "https://Stackoverflow.com/questions/31466769", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4403872/" ]
One more way is to use [`np.empty`](http://docs.scipy.org/doc/numpy/reference/generated/numpy.empty.html): ``` df['empty_list'] = np.empty((len(df), 0)).tolist() ``` --- You could also knock off `.index` in your "Method 1" when trying to find `len` of `df`. ``` df['empty_list'] = [[] for _ in range(len(df))] ``` ...
EDIT: the commenters caught the bug in my answer ``` s = pd.Series([[]] * 3) s.iloc[0].append(1) #adding an item only to the first element >s # unintended consequences: 0 [1] 1 [1] 2 [1] ``` So, the correct solution is ``` s = pd.Series([[] for i in range(3)]) s.iloc[0].append(1) >s 0 [1] 1 [] 2 ...
31,466,769
Similar to this question [How to add an empty column to a dataframe?](https://stackoverflow.com/questions/16327055/how-to-add-an-empty-column-to-a-dataframe), I am interested in knowing the best way to add a column of empty lists to a DataFrame. What I am trying to do is basically initialize a column and as I iterate ...
2015/07/17
[ "https://Stackoverflow.com/questions/31466769", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4403872/" ]
One more way is to use [`np.empty`](http://docs.scipy.org/doc/numpy/reference/generated/numpy.empty.html): ``` df['empty_list'] = np.empty((len(df), 0)).tolist() ``` --- You could also knock off `.index` in your "Method 1" when trying to find `len` of `df`. ``` df['empty_list'] = [[] for _ in range(len(df))] ``` ...
Canonical solutions: List comprehension, `map` and `apply` ========================================================== Obligatory disclaimer: avoid using lists in pandas columns where possible, list columns are slow to work with because they are objects and those are inherently hard to vectorize. With that out of the...
31,466,769
Similar to this question [How to add an empty column to a dataframe?](https://stackoverflow.com/questions/16327055/how-to-add-an-empty-column-to-a-dataframe), I am interested in knowing the best way to add a column of empty lists to a DataFrame. What I am trying to do is basically initialize a column and as I iterate ...
2015/07/17
[ "https://Stackoverflow.com/questions/31466769", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4403872/" ]
EDIT: the commenters caught the bug in my answer ``` s = pd.Series([[]] * 3) s.iloc[0].append(1) #adding an item only to the first element >s # unintended consequences: 0 [1] 1 [1] 2 [1] ``` So, the correct solution is ``` s = pd.Series([[] for i in range(3)]) s.iloc[0].append(1) >s 0 [1] 1 [] 2 ...
Canonical solutions: List comprehension, `map` and `apply` ========================================================== Obligatory disclaimer: avoid using lists in pandas columns where possible, list columns are slow to work with because they are objects and those are inherently hard to vectorize. With that out of the...
27,138,716
I am new to Jquery and Javascript. I've only done the intros for codeacademy and I have what I remembered from my python days. I saw this tutorial: <http://www.codecademy.com/courses/a-simple-counter/0/1> I completed the tutorial and thought: "I should learn how to do this with Jquery". So I've been trying to use ...
2014/11/25
[ "https://Stackoverflow.com/questions/27138716", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4293758/" ]
If you want to read the whole file with the spaces removed, `f.read()` is on the right track—unlike your other attempts, that gives you the whole file as a single string, not one line at a time. But you still need to replace the spaces. Which you need to do explicitly. For example: ``` f.read().replace(' ', '') ``` ...
This line: ``` f = open("clues.txt") ``` will open the file - that is, it returns a filehandle that you can read from This line: ``` open("clues.txt").read().replace(" ", "") ``` will open the file and return its contents, with all spaces removed.
27,138,716
I am new to Jquery and Javascript. I've only done the intros for codeacademy and I have what I remembered from my python days. I saw this tutorial: <http://www.codecademy.com/courses/a-simple-counter/0/1> I completed the tutorial and thought: "I should learn how to do this with Jquery". So I've been trying to use ...
2014/11/25
[ "https://Stackoverflow.com/questions/27138716", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4293758/" ]
Building upon @JonKiparsky It would be safer for you to use the python `with` statement: ``` with open("clues.txt") as f: f.read().replace(" ", "") ```
If you want to read the whole file with the spaces removed, `f.read()` is on the right track—unlike your other attempts, that gives you the whole file as a single string, not one line at a time. But you still need to replace the spaces. Which you need to do explicitly. For example: ``` f.read().replace(' ', '') ``` ...
27,138,716
I am new to Jquery and Javascript. I've only done the intros for codeacademy and I have what I remembered from my python days. I saw this tutorial: <http://www.codecademy.com/courses/a-simple-counter/0/1> I completed the tutorial and thought: "I should learn how to do this with Jquery". So I've been trying to use ...
2014/11/25
[ "https://Stackoverflow.com/questions/27138716", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4293758/" ]
Building upon @JonKiparsky It would be safer for you to use the python `with` statement: ``` with open("clues.txt") as f: f.read().replace(" ", "") ```
This line: ``` f = open("clues.txt") ``` will open the file - that is, it returns a filehandle that you can read from This line: ``` open("clues.txt").read().replace(" ", "") ``` will open the file and return its contents, with all spaces removed.
65,682,339
This is not working, Cant figure it out... i want it to print either error sentence or break.. I wanted to do it in a try/except, but that was not so good. And I'm new to python :-) ```py while True: unitFrom = input("Enter unit of temperature, either Fahrenheit, Kelvin or Celsius:") list = ["Fa...
2021/01/12
[ "https://Stackoverflow.com/questions/65682339", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14990031/" ]
1. Never use the built-in keywords to define new variables. 2. Take the list outside the loop to avoid initializing it on each iteration. 3. You need to have the list in lowercase since you're checking the lower-cased input in the list: Hence: ``` x_units = ["fahrenheit" , "celsius" , "kelvin"] # or x_units = [x.lowe...
Do you want to print break or want to execute `break` ? and `list = ["Fahrenheit" , "Celsius" , "Kelvin"]` is created new everytime execute it before `while True:` and use something other than list as array name as `list` is a keyword ``` answer_list = ["Fahrenheit" , "Celsius" , "Kelvin"] while True: unitFrom...
65,682,339
This is not working, Cant figure it out... i want it to print either error sentence or break.. I wanted to do it in a try/except, but that was not so good. And I'm new to python :-) ```py while True: unitFrom = input("Enter unit of temperature, either Fahrenheit, Kelvin or Celsius:") list = ["Fa...
2021/01/12
[ "https://Stackoverflow.com/questions/65682339", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14990031/" ]
1. Never use the built-in keywords to define new variables. 2. Take the list outside the loop to avoid initializing it on each iteration. 3. You need to have the list in lowercase since you're checking the lower-cased input in the list: Hence: ``` x_units = ["fahrenheit" , "celsius" , "kelvin"] # or x_units = [x.lowe...
The problem is that you're not using lowercase units. And then checking if `"Kelvin" =="kelvin"`, which is never `True`. Replace your list of units with lowercase or just use this code: ``` while True: unitFrom = input("Enter unit of temperature, either Fahrenheit, Kelvin or Celsius:") myList = ["Fahrenhei...
65,682,339
This is not working, Cant figure it out... i want it to print either error sentence or break.. I wanted to do it in a try/except, but that was not so good. And I'm new to python :-) ```py while True: unitFrom = input("Enter unit of temperature, either Fahrenheit, Kelvin or Celsius:") list = ["Fa...
2021/01/12
[ "https://Stackoverflow.com/questions/65682339", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14990031/" ]
1. Never use the built-in keywords to define new variables. 2. Take the list outside the loop to avoid initializing it on each iteration. 3. You need to have the list in lowercase since you're checking the lower-cased input in the list: Hence: ``` x_units = ["fahrenheit" , "celsius" , "kelvin"] # or x_units = [x.lowe...
As pointed by @dirtybit, you should take care of those points. Set Access is faster than list, if list is of big size, you can try `set` to compare with input. ### Solution : ```py units_set = set("fahrenheit" , "felsius" , "kelvin") # initializing it only once, the lower case values. while True: unit_from = i...
65,682,339
This is not working, Cant figure it out... i want it to print either error sentence or break.. I wanted to do it in a try/except, but that was not so good. And I'm new to python :-) ```py while True: unitFrom = input("Enter unit of temperature, either Fahrenheit, Kelvin or Celsius:") list = ["Fa...
2021/01/12
[ "https://Stackoverflow.com/questions/65682339", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14990031/" ]
1. Never use the built-in keywords to define new variables. 2. Take the list outside the loop to avoid initializing it on each iteration. 3. You need to have the list in lowercase since you're checking the lower-cased input in the list: Hence: ``` x_units = ["fahrenheit" , "celsius" , "kelvin"] # or x_units = [x.lowe...
You can try this, ``` loopBool = True while loopBool: unitList = ["fahrenheit", "celsius", "kelvin"] try: unitFrom = raw_input("Enter unit of temperature, either Fahrenheit, Kelvin or Celsius:") if unitFrom in unitList: inBool = True if inBool == True: ...
68,179,964
I am trying to check if all the objects in a specified bucket are public or not, using the boto3 module in python. I have tried using the `client.get_object()` and `client.list_objects()` methods, but I am unable to figure out what exactly I should search for as I am new to boto3 and AWS in general. Also, since my org...
2021/06/29
[ "https://Stackoverflow.com/questions/68179964", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16081945/" ]
I think the best way to test if an object is public or not is to make an anonymous request to that object URL. ```py import boto3 import botocore import requests bucket_name = 'example-bucket' object_key = 'example-key' config = botocore.client.Config(signature_version=botocore.UNSIGNED) object_url = boto3.client('s...
may be a combination of these to tell the full story for each object ``` client = boto3.client('s3') bucket = 'my-bucket' key = 'my-key' client.get_object_acl(Bucket=bucket, Key=key) client.get_bucket_acl(Bucket=bucket) client.get_bucket_policy(Bucket=bucket) ```
68,179,964
I am trying to check if all the objects in a specified bucket are public or not, using the boto3 module in python. I have tried using the `client.get_object()` and `client.list_objects()` methods, but I am unable to figure out what exactly I should search for as I am new to boto3 and AWS in general. Also, since my org...
2021/06/29
[ "https://Stackoverflow.com/questions/68179964", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16081945/" ]
I think the best way to test if an object is public or not is to make an anonymous request to that object URL. ```py import boto3 import botocore import requests bucket_name = 'example-bucket' object_key = 'example-key' config = botocore.client.Config(signature_version=botocore.UNSIGNED) object_url = boto3.client('s...
This function should do the trick. It gets the ACL and then loops through the `Grants` looking for `AllUsers` with `READ` or `FULL_CONTROL` permissions. ``` import boto3 def is_public(key, bucket): """Returns true if key has public access. Args: key (str): key to check bucket (str, optional):...
70,222,086
Well, I would like to get a calendars data from outlook. My purpose is making small service in Python which can read & write in someones calendar in outlook account of course I suppose that I was provided access to it in Azure Active Directory. Before writing this, I read a lot of guides on how to do this. Also I tried...
2021/12/04
[ "https://Stackoverflow.com/questions/70222086", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12961561/" ]
let's best go through the error messages: 1. `Error Message: The tenant for tenant guid 'xxxx' does not exist.` I am assuming that this is an Office 365 Business. Also that you are logged into Azure with your company address. Then you should see under: "App registrations>test feature> Overview" you should find the va...
For me, joining [Microsoft Developer Program](https://developer.microsoft.com/en-us/microsoft-365/dev-program) and using its azure directory fixed issues.
45,402,049
I've been working on a website for the past year and used python and flask to built it. Recently I encountered a lot of errors and problems and decided to start a new project (pyCharm). I figured I could copy pieces of code into the new project until I encountered a problem and then I'll know what the problem is. I cr...
2017/07/30
[ "https://Stackoverflow.com/questions/45402049", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8380994/" ]
Move the `if` outside the `echo` and assign it to a variable, then use the variable in the `echo`. I'd also use ternary operator for this. It also looks like you are comparing the full array, not the index you want to be comparing. Try: ``` while ($row = $result->fetch_assoc()) { $style = $row['move'] > 0 ? ' ...
Untested, but I think this will work: ``` while ($row = $result->fetch_assoc()) { echo "<tr><td style='text-align:left'>".$row["rank"]."</td><td style='text-align:left'>".$row["team_name"]."</td><td>".$row["record"]."</td><td>".$row["average"]."</td><td ".($row["move"] > 0 ? 'style="color:green;"' : '').">".$row["...
45,402,049
I've been working on a website for the past year and used python and flask to built it. Recently I encountered a lot of errors and problems and decided to start a new project (pyCharm). I figured I could copy pieces of code into the new project until I encountered a problem and then I'll know what the problem is. I cr...
2017/07/30
[ "https://Stackoverflow.com/questions/45402049", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8380994/" ]
Untested, but I think this will work: ``` while ($row = $result->fetch_assoc()) { echo "<tr><td style='text-align:left'>".$row["rank"]."</td><td style='text-align:left'>".$row["team_name"]."</td><td>".$row["record"]."</td><td>".$row["average"]."</td><td ".($row["move"] > 0 ? 'style="color:green;"' : '').">".$row["...
Try instead of: ``` if($row > 0) {echo 'style="color:green;"';} ``` a shorter if statement: ``` $Color = ($row > 0 )? "green" : "red"; echo 'style="color:'.$Color.';"'; ```
45,402,049
I've been working on a website for the past year and used python and flask to built it. Recently I encountered a lot of errors and problems and decided to start a new project (pyCharm). I figured I could copy pieces of code into the new project until I encountered a problem and then I'll know what the problem is. I cr...
2017/07/30
[ "https://Stackoverflow.com/questions/45402049", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8380994/" ]
Move the `if` outside the `echo` and assign it to a variable, then use the variable in the `echo`. I'd also use ternary operator for this. It also looks like you are comparing the full array, not the index you want to be comparing. Try: ``` while ($row = $result->fetch_assoc()) { $style = $row['move'] > 0 ? ' ...
Try instead of: ``` if($row > 0) {echo 'style="color:green;"';} ``` a shorter if statement: ``` $Color = ($row > 0 )? "green" : "red"; echo 'style="color:'.$Color.';"'; ```
53,178,013
I have a project for which I'd now like to use pipenv. I want to symlink this from my main bin directory, so I can run it from another directory (where it interacts with local files) but nevertheless run it in the pipenv with the appropriately installed files. Can I do something like ``` pipenv run python /PATH/TO/M...
2018/11/06
[ "https://Stackoverflow.com/questions/53178013", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8482/" ]
Not sure if this was relevant with the version of pipenv you used in 2018, but as of current versions you can use the [PIPENV\_PIPFILE](https://pipenv.kennethreitz.org/en/latest/advanced/#pipenv.environments.PIPENV_PIPFILE) environment variable. You will end up with a wrapper shell script that looks something like: ``...
pipenv is a wrapper for virtualenv which keeps the virtualenv-files in some folder in your home directory. I found them in `/home/MYUSERNAME/.local/share/virtualenvs`. So i wrote a `small_script.sh`: ``` #!/bin/bash source /home/MYUSERNAME/.local/share/virtualenvs/MYCODE-9as8Da87/bin/activate python /PATH/TO/MY/CODE...
1,976,622
I'm using python-dbus and cherrypy to monitor USB devices and provide a REST service that will maintain status on the inserted USB devices. I have written and debugged these services independently, and they work as expected. Now, I'm merging the services into a single application. My problem is: I cannot seem to get b...
2009/12/29
[ "https://Stackoverflow.com/questions/1976622", "https://Stackoverflow.com", "https://Stackoverflow.com/users/179157/" ]
You should be able to use .NET's Reflection to analyze your application AppDomain(s) and dump a list of loaded assemblies and locations. ``` var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (var assembly in loadedAssemblies) { Console.WriteLine(assembly.GetName().Name); Console.WriteLine...
Check out [`AppDomain.GetAssemblies`](http://msdn.microsoft.com/en-us/library/system.appdomain.getassemblies.aspx) ``` For Each Ass As Reflection.Assembly In CurrentDomain.GetAssemblies() Console.WriteLine(Ass.ToString()) Next ```
1,976,622
I'm using python-dbus and cherrypy to monitor USB devices and provide a REST service that will maintain status on the inserted USB devices. I have written and debugged these services independently, and they work as expected. Now, I'm merging the services into a single application. My problem is: I cannot seem to get b...
2009/12/29
[ "https://Stackoverflow.com/questions/1976622", "https://Stackoverflow.com", "https://Stackoverflow.com/users/179157/" ]
You should be able to use .NET's Reflection to analyze your application AppDomain(s) and dump a list of loaded assemblies and locations. ``` var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (var assembly in loadedAssemblies) { Console.WriteLine(assembly.GetName().Name); Console.WriteLine...
This is answered in another [question](https://stackoverflow.com/questions/458362/how-do-i-list-all-loaded-assemblies) already. The gist of it is use current appdomain to get a list of assemblies and loop through their loader location.
1,976,622
I'm using python-dbus and cherrypy to monitor USB devices and provide a REST service that will maintain status on the inserted USB devices. I have written and debugged these services independently, and they work as expected. Now, I'm merging the services into a single application. My problem is: I cannot seem to get b...
2009/12/29
[ "https://Stackoverflow.com/questions/1976622", "https://Stackoverflow.com", "https://Stackoverflow.com/users/179157/" ]
You should be able to use .NET's Reflection to analyze your application AppDomain(s) and dump a list of loaded assemblies and locations. ``` var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (var assembly in loadedAssemblies) { Console.WriteLine(assembly.GetName().Name); Console.WriteLine...
If I have understood your question, to do a fast deployment you can set in all the references of your project but the Framework ones the setting "Copy Local" to true. This way when you build your application you will have all the needed DLLs at your output directory (well, almost all, references needed by your referen...
1,976,622
I'm using python-dbus and cherrypy to monitor USB devices and provide a REST service that will maintain status on the inserted USB devices. I have written and debugged these services independently, and they work as expected. Now, I'm merging the services into a single application. My problem is: I cannot seem to get b...
2009/12/29
[ "https://Stackoverflow.com/questions/1976622", "https://Stackoverflow.com", "https://Stackoverflow.com/users/179157/" ]
Process Explorer?
Check out [`AppDomain.GetAssemblies`](http://msdn.microsoft.com/en-us/library/system.appdomain.getassemblies.aspx) ``` For Each Ass As Reflection.Assembly In CurrentDomain.GetAssemblies() Console.WriteLine(Ass.ToString()) Next ```
1,976,622
I'm using python-dbus and cherrypy to monitor USB devices and provide a REST service that will maintain status on the inserted USB devices. I have written and debugged these services independently, and they work as expected. Now, I'm merging the services into a single application. My problem is: I cannot seem to get b...
2009/12/29
[ "https://Stackoverflow.com/questions/1976622", "https://Stackoverflow.com", "https://Stackoverflow.com/users/179157/" ]
Process Explorer?
This is answered in another [question](https://stackoverflow.com/questions/458362/how-do-i-list-all-loaded-assemblies) already. The gist of it is use current appdomain to get a list of assemblies and loop through their loader location.
1,976,622
I'm using python-dbus and cherrypy to monitor USB devices and provide a REST service that will maintain status on the inserted USB devices. I have written and debugged these services independently, and they work as expected. Now, I'm merging the services into a single application. My problem is: I cannot seem to get b...
2009/12/29
[ "https://Stackoverflow.com/questions/1976622", "https://Stackoverflow.com", "https://Stackoverflow.com/users/179157/" ]
Process Explorer?
If I have understood your question, to do a fast deployment you can set in all the references of your project but the Framework ones the setting "Copy Local" to true. This way when you build your application you will have all the needed DLLs at your output directory (well, almost all, references needed by your referen...
1,777,862
I am trying to rewrite the following program in C instead of C# (which is less portable). It is obvious that "int system ( const char \* command )" will be necessary to complete the program. Starting it with "int main ( int argc, char \* argv[] )" will allow getting the command-line arguments, but there is still a prob...
2009/11/22
[ "https://Stackoverflow.com/questions/1777862", "https://Stackoverflow.com", "https://Stackoverflow.com/users/216356/" ]
Windows is all messed up. Every program has its own rules.
``` screensaver.scr "spaced argument" nonspaced_argument argc = 2 argv[0] = "screensaver.scr" argv[1] = "spaced argument" argv[2] = "nonspaced_argument" ``` Sorry my English :).
1,777,862
I am trying to rewrite the following program in C instead of C# (which is less portable). It is obvious that "int system ( const char \* command )" will be necessary to complete the program. Starting it with "int main ( int argc, char \* argv[] )" will allow getting the command-line arguments, but there is still a prob...
2009/11/22
[ "https://Stackoverflow.com/questions/1777862", "https://Stackoverflow.com", "https://Stackoverflow.com/users/216356/" ]
The correct way to do this under windows is to use [\_spawnv](http://msdn.microsoft.com/en-us/library/7zt1y878(VS.80).aspx) Its equivalent under unix like OSes is `fork()` followed by `execv`.
``` screensaver.scr "spaced argument" nonspaced_argument argc = 2 argv[0] = "screensaver.scr" argv[1] = "spaced argument" argv[2] = "nonspaced_argument" ``` Sorry my English :).
17,161,552
I have read that while writing functions it is good practice to copy the arguments into other variables because it is not always clear whether the variable is immutable or not. [I don't remember where so don't ask]. I have been writing functions according to this. As I understand creating a new variable takes some ove...
2013/06/18
[ "https://Stackoverflow.com/questions/17161552", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2235567/" ]
I think it's best to keep it simple in questions like these. The second link in your question is a really good explanation; in summary: Methods take parameters which, as pointed out in that explanation, are passed "by value". The parameters in functions take the value of variables passed in. For primitive types like...
If you are **rebinding** the name then mutability of the object it contains is irrelevant. Only if you perform **mutating** operations must you create a copy. (And if you read between the lines, that indirectly says "don't mutate objects passed to you".)
17,161,552
I have read that while writing functions it is good practice to copy the arguments into other variables because it is not always clear whether the variable is immutable or not. [I don't remember where so don't ask]. I have been writing functions according to this. As I understand creating a new variable takes some ove...
2013/06/18
[ "https://Stackoverflow.com/questions/17161552", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2235567/" ]
What you are doing in your code examples involves no noticeable overhead, but it also doesn't accomplish anything because it won't protect you from mutable/immutable problems. The way to think about this is that there are two kinds of things in Python: names and objects. When you do `x = y` you are operating on a name...
If you are **rebinding** the name then mutability of the object it contains is irrelevant. Only if you perform **mutating** operations must you create a copy. (And if you read between the lines, that indirectly says "don't mutate objects passed to you".)
17,161,552
I have read that while writing functions it is good practice to copy the arguments into other variables because it is not always clear whether the variable is immutable or not. [I don't remember where so don't ask]. I have been writing functions according to this. As I understand creating a new variable takes some ove...
2013/06/18
[ "https://Stackoverflow.com/questions/17161552", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2235567/" ]
I think it's best to keep it simple in questions like these. The second link in your question is a really good explanation; in summary: Methods take parameters which, as pointed out in that explanation, are passed "by value". The parameters in functions take the value of variables passed in. For primitive types like...
What you are doing in your code examples involves no noticeable overhead, but it also doesn't accomplish anything because it won't protect you from mutable/immutable problems. The way to think about this is that there are two kinds of things in Python: names and objects. When you do `x = y` you are operating on a name...
73,419,189
I am learning continue statement in python while loop. If I run a following code, the output shows from 2 instead of 1. ``` a = 1 while a <= 8: a += 1 if a == 5: continue print(a) ```
2022/08/19
[ "https://Stackoverflow.com/questions/73419189", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8507620/" ]
You can use the HPA (Horizontal Pod Autoscaler). Here is what the typical yaml configuration looks like. ``` apiVersion: autoscaling/v1 kind: HorizontalPodAutoscaler metadata: name: hpa_name spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: deployment_name_to_autoscale minReplicas: 1 ...
In GKE, you can achieve this with [Horizontal Pod Autoscaler (HPA)](https://cloud.google.com/kubernetes-engine/docs/concepts/horizontalpodautoscaler). The autoscaling event can be configured to be triggered by system (eg. cpu or memory) or custom metrics (eg. pubsub queued messages count). You can also set the minimum ...
73,419,189
I am learning continue statement in python while loop. If I run a following code, the output shows from 2 instead of 1. ``` a = 1 while a <= 8: a += 1 if a == 5: continue print(a) ```
2022/08/19
[ "https://Stackoverflow.com/questions/73419189", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8507620/" ]
In GKE, you can achieve this with [Horizontal Pod Autoscaler (HPA)](https://cloud.google.com/kubernetes-engine/docs/concepts/horizontalpodautoscaler). The autoscaling event can be configured to be triggered by system (eg. cpu or memory) or custom metrics (eg. pubsub queued messages count). You can also set the minimum ...
Here is another example for using HPA with external metric (e.g cloud pub/sub): ``` apiVersion: autoscaling/v2beta2 kind: HorizontalPodAutoscaler metadata: name: your-hpa-name spec: minReplicas: 1 maxReplicas: 4 metrics: - external: metric: name: pubsub.googleapis.com|subscription|num_undelivere...
73,419,189
I am learning continue statement in python while loop. If I run a following code, the output shows from 2 instead of 1. ``` a = 1 while a <= 8: a += 1 if a == 5: continue print(a) ```
2022/08/19
[ "https://Stackoverflow.com/questions/73419189", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8507620/" ]
You can use the HPA (Horizontal Pod Autoscaler). Here is what the typical yaml configuration looks like. ``` apiVersion: autoscaling/v1 kind: HorizontalPodAutoscaler metadata: name: hpa_name spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: deployment_name_to_autoscale minReplicas: 1 ...
> > Menu > GKE > Workloads > click on your deployment > 3 dots (more > actions) > Actions > Autoscale > set metrics > Save > > >
73,419,189
I am learning continue statement in python while loop. If I run a following code, the output shows from 2 instead of 1. ``` a = 1 while a <= 8: a += 1 if a == 5: continue print(a) ```
2022/08/19
[ "https://Stackoverflow.com/questions/73419189", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8507620/" ]
> > Menu > GKE > Workloads > click on your deployment > 3 dots (more > actions) > Actions > Autoscale > set metrics > Save > > >
Here is another example for using HPA with external metric (e.g cloud pub/sub): ``` apiVersion: autoscaling/v2beta2 kind: HorizontalPodAutoscaler metadata: name: your-hpa-name spec: minReplicas: 1 maxReplicas: 4 metrics: - external: metric: name: pubsub.googleapis.com|subscription|num_undelivere...
73,419,189
I am learning continue statement in python while loop. If I run a following code, the output shows from 2 instead of 1. ``` a = 1 while a <= 8: a += 1 if a == 5: continue print(a) ```
2022/08/19
[ "https://Stackoverflow.com/questions/73419189", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8507620/" ]
You can use the HPA (Horizontal Pod Autoscaler). Here is what the typical yaml configuration looks like. ``` apiVersion: autoscaling/v1 kind: HorizontalPodAutoscaler metadata: name: hpa_name spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: deployment_name_to_autoscale minReplicas: 1 ...
Here is another example for using HPA with external metric (e.g cloud pub/sub): ``` apiVersion: autoscaling/v2beta2 kind: HorizontalPodAutoscaler metadata: name: your-hpa-name spec: minReplicas: 1 maxReplicas: 4 metrics: - external: metric: name: pubsub.googleapis.com|subscription|num_undelivere...
55,599,993
I want to write a program in Python which takes a C program as input, executes it against the test cases which are also as inputs and print the output for each test case. I am using Windows I tried with subprocess.run but it is not accepting inputs at runtime (i.e dynamically) ```py from subprocess import * p1=run("r...
2019/04/09
[ "https://Stackoverflow.com/questions/55599993", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11315221/" ]
I agree with @juanpa.arrivillaga's suggestion. You can use `subprocess.Popen` and `communicate()` for that: ``` import subprocess import sys p = subprocess.Popen('rah.exe', stdout=sys.stdout, stderr=sys.stderr) p.communicate() ``` **Update:** The script above won't work on IDLE because IDLE changes the IO objects `s...
> > I tried with subprocess.run but it is not accepting inputs at runtime (i.e dynamically) > > > If you don't do anything, the subprocess will simply inherit their parent's stdin. That aside, because you're intercepting the output of the subprocess and printing it afterwards you won't get the interleaving you're...
54,371,847
I'm trying to install tensorflow but python 3.7 does not support that, so I want to get python 3.6 instead without using anaconda. So any suggestion please ?
2019/01/25
[ "https://Stackoverflow.com/questions/54371847", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10968495/" ]
I have done this multiple times. My first tip is use [virtual environments](https://realpython.com/python-virtual-environments-a-primer/). That way you can use python 3.6 for what ever project requires that version of python, and python 3.7 for other projects that need that version. However on windows these are the b...
Consider using [pyenv-win](https://github.com/pyenv-win/pyenv-win) in order to manage your global and (per-project) local Python versions. However, it only works with the Windows Subsystem for Linux.
54,371,847
I'm trying to install tensorflow but python 3.7 does not support that, so I want to get python 3.6 instead without using anaconda. So any suggestion please ?
2019/01/25
[ "https://Stackoverflow.com/questions/54371847", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10968495/" ]
Consider using [pyenv-win](https://github.com/pyenv-win/pyenv-win) in order to manage your global and (per-project) local Python versions. However, it only works with the Windows Subsystem for Linux.
This solved it for me. Run the following via anaconda prompt 1. conda create -n py36 python=3.6 2. activate py36 3. Select py36 on Anaconda navigator and launch spyder
54,371,847
I'm trying to install tensorflow but python 3.7 does not support that, so I want to get python 3.6 instead without using anaconda. So any suggestion please ?
2019/01/25
[ "https://Stackoverflow.com/questions/54371847", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10968495/" ]
I have done this multiple times. My first tip is use [virtual environments](https://realpython.com/python-virtual-environments-a-primer/). That way you can use python 3.6 for what ever project requires that version of python, and python 3.7 for other projects that need that version. However on windows these are the b...
This solved it for me. Run the following via anaconda prompt 1. conda create -n py36 python=3.6 2. activate py36 3. Select py36 on Anaconda navigator and launch spyder
66,975,127
I'm trying to install a simple Django package in a Docker container. Here is my dockerfile ``` FROM python:3.8 ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 WORKDIR /app COPY Pipfile Pipfile.lock /app/ RUN pip install pipenv && pipenv install --system COPY . /app/ ``` And here is my docker-compose: ``` ve...
2021/04/06
[ "https://Stackoverflow.com/questions/66975127", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3678257/" ]
you can use [present](https://laravel.com/docs/8.x/validation#rule-present) validation The field under validation must be present in the input data but can be empty. ``` 'topics' => 'present|array' ```
Validating array based form input fields doesn't have to be a pain. You may use "dot notation" to validate attributes within an array. For example, if the incoming HTTP request contains a `photos[profile]` field, you may validate it like so: ``` use Illuminate\Support\Facades\Validator; $validator = Validator::make($...
47,370,718
Suppose we have * an n-dimensional numpy.array A * a numpy.array B with dtype=int and shape of (n, m) How do I index A by B so that the result is an array of shape (m,), with values taken from the positions indicated by the columns of B? For example, consider this code that does what I want when B is a python list: ...
2017/11/18
[ "https://Stackoverflow.com/questions/47370718", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1073784/" ]
One alternative would be converting to linear indices and then index with `np.take` or index into its flattened version - ``` np.take(a,np.ravel_multi_index(b, a.shape)) a.flat[np.ravel_multi_index(b, a.shape)] ``` **Custom `np.ravel_multi_index` for performance boost** We could implement a custom version to simula...
Another alternative that fits your need involves the use of [`np.ravel`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ravel.html) ``` >>> a[map(np.ravel, b)] array([ 1, 10, 20]) ``` However not fully [`numpy`](http://www.numpy.org/)-based. --- ***Performance-concerns.*** *Updated following the commen...
47,370,718
Suppose we have * an n-dimensional numpy.array A * a numpy.array B with dtype=int and shape of (n, m) How do I index A by B so that the result is an array of shape (m,), with values taken from the positions indicated by the columns of B? For example, consider this code that does what I want when B is a python list: ...
2017/11/18
[ "https://Stackoverflow.com/questions/47370718", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1073784/" ]
One alternative would be converting to linear indices and then index with `np.take` or index into its flattened version - ``` np.take(a,np.ravel_multi_index(b, a.shape)) a.flat[np.ravel_multi_index(b, a.shape)] ``` **Custom `np.ravel_multi_index` for performance boost** We could implement a custom version to simula...
Are you looking for [`numpy.ndarray.tolist()`](https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.ndarray.tolist.html) ? ``` >>> a = np.arange(27).reshape(3,3,3) >>> bl = [[0, 1, 2], [0, 0, 0], [1, 1, 2]] >>> b = np.array(bl) >>> a[b.tolist()] array([ 1, 10, 20]) ``` Or for [arrays indexing arrays](ht...
5,373,195
When I tried to parse a csv which was exported by MS SQL 2005 express edition's query, the string python gives me is totally unexpected. For example if the line in the csv file is :" aaa,bbb,ccc,dddd", then when python parsed it as string, it becomes :" a a a a , b b b , c c c, d d d d" something like that.....What hap...
2011/03/21
[ "https://Stackoverflow.com/questions/5373195", "https://Stackoverflow.com", "https://Stackoverflow.com/users/612678/" ]
Sounds to me like the output of the MS SQL 2005 query is a unicode file. The python [csv module](http://docs.python.org/library/csv.html) cannot handle unicode files, but there is some [sample code](http://docs.python.org/library/csv.html#csv-examples) in the documentation for the csv module describing how to work arou...
Try to open the file in notepad and use the replace all function to replace `' '` with `''`
5,373,195
When I tried to parse a csv which was exported by MS SQL 2005 express edition's query, the string python gives me is totally unexpected. For example if the line in the csv file is :" aaa,bbb,ccc,dddd", then when python parsed it as string, it becomes :" a a a a , b b b , c c c, d d d d" something like that.....What hap...
2011/03/21
[ "https://Stackoverflow.com/questions/5373195", "https://Stackoverflow.com", "https://Stackoverflow.com/users/612678/" ]
Sounds to me like the output of the MS SQL 2005 query is a unicode file. The python [csv module](http://docs.python.org/library/csv.html) cannot handle unicode files, but there is some [sample code](http://docs.python.org/library/csv.html#csv-examples) in the documentation for the csv module describing how to work arou...
It may help to use Python's built in CSV reader. Looks like an issue with unicode, a problem that frustrated me a lot. ``` import tkFileDialog import csv ENCODING_REGEX_REPLACEMENT_LIST = [(re.compile('\xe2\x80\x99'), "'"), (re.compile('\xe2\x80\x94'), "--"), ...
5,373,195
When I tried to parse a csv which was exported by MS SQL 2005 express edition's query, the string python gives me is totally unexpected. For example if the line in the csv file is :" aaa,bbb,ccc,dddd", then when python parsed it as string, it becomes :" a a a a , b b b , c c c, d d d d" something like that.....What hap...
2011/03/21
[ "https://Stackoverflow.com/questions/5373195", "https://Stackoverflow.com", "https://Stackoverflow.com/users/612678/" ]
Sounds to me like the output of the MS SQL 2005 query is a unicode file. The python [csv module](http://docs.python.org/library/csv.html) cannot handle unicode files, but there is some [sample code](http://docs.python.org/library/csv.html#csv-examples) in the documentation for the csv module describing how to work arou...
Your file is most likely encoded with a 2byte character encoding - most likely utf-16 (but it culd be some other encoding. To get the CSV proper reading it, you'd open it with a codec so that it is decoded as its read - doing that you have Unicode objects (not string objects) inside your python program. So, instead o...
47,544,183
I'm trying to use multiprocessing, but I keep getting this error: ``` AttributeError: Can't get attribute 'processLine' on <module '__main__' ``` (The processLine function returns word, so I guess the problem is here, but I don't know how to get around it) ``` import multiprocessing as mp pool = mp.Pool(4) jobs ...
2017/11/29
[ "https://Stackoverflow.com/questions/47544183", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8138305/" ]
The `multiprocessing` module needs to be able to import your module safely. Any code not inside a function or class should be protected by the standard Python import guard: ``` if __name__ == '__main__': ...code goes here... ``` But there are other problems with your code. For example, you've got: ``` word = jo...
I worked around the AttributeError issue by using VS Code in administrator mode to run it instead of Anaconda Spyder.
10,688,389
I have a ever growing csv file that looks like: ``` 143100, 2012-05-21 09:52:54.165852 125820, 2012-05-21 09:53:54.666780 109260, 2012-05-21 09:54:55.144712 116340, 2012-05-21 09:55:55.642197 125640, 2012-05-21 09:56:56.094999 122820, 2012-05-21 09:57:56.546567 124770, 2012-05-21 09:58:57.046050 103830, 2012-05-21 09:...
2012/05/21
[ "https://Stackoverflow.com/questions/10688389", "https://Stackoverflow.com", "https://Stackoverflow.com/users/672387/" ]
The Python idiom would be to use a generator expression to filter the lines: ``` sys.stdout.writelines(line for line in sys.stdin if not line.startswith('-')) ``` Or in a processing context: ``` filtered = (line for line in sys.stdin if not line.startswith('-')) for line in filtered: # ... ```
Instead of rewriting the files, I would filter the data on read, i.e. just before plotting.
10,688,389
I have a ever growing csv file that looks like: ``` 143100, 2012-05-21 09:52:54.165852 125820, 2012-05-21 09:53:54.666780 109260, 2012-05-21 09:54:55.144712 116340, 2012-05-21 09:55:55.642197 125640, 2012-05-21 09:56:56.094999 122820, 2012-05-21 09:57:56.546567 124770, 2012-05-21 09:58:57.046050 103830, 2012-05-21 09:...
2012/05/21
[ "https://Stackoverflow.com/questions/10688389", "https://Stackoverflow.com", "https://Stackoverflow.com/users/672387/" ]
The Python idiom would be to use a generator expression to filter the lines: ``` sys.stdout.writelines(line for line in sys.stdin if not line.startswith('-')) ``` Or in a processing context: ``` filtered = (line for line in sys.stdin if not line.startswith('-')) for line in filtered: # ... ```
This program opens your csv file, removes the lines starting with negative integers, and saves it to a different file. If you want, you can overwrite this on the same file with slight modification. ``` with open('data.csv', 'r') as f: with open('data2.csv', 'w') as g: for row in f: if row[0] !=...
10,688,389
I have a ever growing csv file that looks like: ``` 143100, 2012-05-21 09:52:54.165852 125820, 2012-05-21 09:53:54.666780 109260, 2012-05-21 09:54:55.144712 116340, 2012-05-21 09:55:55.642197 125640, 2012-05-21 09:56:56.094999 122820, 2012-05-21 09:57:56.546567 124770, 2012-05-21 09:58:57.046050 103830, 2012-05-21 09:...
2012/05/21
[ "https://Stackoverflow.com/questions/10688389", "https://Stackoverflow.com", "https://Stackoverflow.com/users/672387/" ]
Instead of rewriting the files, I would filter the data on read, i.e. just before plotting.
This program opens your csv file, removes the lines starting with negative integers, and saves it to a different file. If you want, you can overwrite this on the same file with slight modification. ``` with open('data.csv', 'r') as f: with open('data2.csv', 'w') as g: for row in f: if row[0] !=...
16,881,955
I am trying to learn python and for that purpose i made a simple addition program using python 2.7.3 ``` print("Enter two Numbers\n") a = int(raw_input('A=')) b = int(raw_input('B=')) c=a+b print ('C= %s' %c) ``` i saved the file as *add.py* and when i double click and run it;the program run and exits instantenously...
2013/06/02
[ "https://Stackoverflow.com/questions/16881955", "https://Stackoverflow.com", "https://Stackoverflow.com/users/996366/" ]
add an empty `raw_input()` at the end to pause until you press `Enter` ``` print("Enter two Numbers\n") a = int(raw_input('A=')) b = int(raw_input('B=')) c=a+b print ('C= %s' %c) raw_input() # waits for you to press enter ``` Alternatively run it from `IDLE`, command line, or whichever editor you use.
Run your file from the command line. This way you can see exceptions. Execute `cmd` than in the "dos box" type: ``` python myfile.py ``` Or on Windows likley just: ``` myfile.py ```
16,881,955
I am trying to learn python and for that purpose i made a simple addition program using python 2.7.3 ``` print("Enter two Numbers\n") a = int(raw_input('A=')) b = int(raw_input('B=')) c=a+b print ('C= %s' %c) ``` i saved the file as *add.py* and when i double click and run it;the program run and exits instantenously...
2013/06/02
[ "https://Stackoverflow.com/questions/16881955", "https://Stackoverflow.com", "https://Stackoverflow.com/users/996366/" ]
add an empty `raw_input()` at the end to pause until you press `Enter` ``` print("Enter two Numbers\n") a = int(raw_input('A=')) b = int(raw_input('B=')) c=a+b print ('C= %s' %c) raw_input() # waits for you to press enter ``` Alternatively run it from `IDLE`, command line, or whichever editor you use.
It's exiting because you're not telling the interpreter to pause at any moment after printing the results. The program itself works. I recommend running it directly in the terminal/command line window like so: ![screenshot of it working](https://i.stack.imgur.com/fFTGm.png) Alternatively, you could write: ``` import...
16,881,955
I am trying to learn python and for that purpose i made a simple addition program using python 2.7.3 ``` print("Enter two Numbers\n") a = int(raw_input('A=')) b = int(raw_input('B=')) c=a+b print ('C= %s' %c) ``` i saved the file as *add.py* and when i double click and run it;the program run and exits instantenously...
2013/06/02
[ "https://Stackoverflow.com/questions/16881955", "https://Stackoverflow.com", "https://Stackoverflow.com/users/996366/" ]
It's exiting because you're not telling the interpreter to pause at any moment after printing the results. The program itself works. I recommend running it directly in the terminal/command line window like so: ![screenshot of it working](https://i.stack.imgur.com/fFTGm.png) Alternatively, you could write: ``` import...
Run your file from the command line. This way you can see exceptions. Execute `cmd` than in the "dos box" type: ``` python myfile.py ``` Or on Windows likley just: ``` myfile.py ```
34,777,676
So I have created a function in my program that allows the user to save whatever he/she draws on the Turtle canvas as a Postscript file with his/her own name. However, there have been issues with some colors not appearing in the output as per the nature of Postscript files, and also, Postscript files just won't open on...
2016/01/13
[ "https://Stackoverflow.com/questions/34777676", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5661257/" ]
[If you don't supply the file parameter](https://www.tcl.tk/man/tcl8.4/TkCmd/canvas.htm#M60) in the call to `cnv.postscript`, then a `cnv.postscript` returns the PostScript as a (unicode) string. You can then convert the unicode to bytes and feed that to `io.BytesIO` and feed that to `Image.open`. [`Image.open`](http:...
Adding to unutbu's answer, you can also write the data again to a BytesIO object, but you have to seek to the beginning of the buffer after doing so. Here's a flask example that displays the image in browser: ```python @app.route('/image.png', methods=['GET']) def image(): """Return png of current canvas""" ps...
73,025,430
I am currently running a function using python's concurrent.futures library. It looks like this (I am using Python 3.10.1 ): ``` with concurrent.futures.ThreadPoolExecutor() as executor: future_results = [executor.submit(f.get_pdf_multi_thread, ssn) for ssn in ssns] for future in concurrent.futures.as_co...
2022/07/18
[ "https://Stackoverflow.com/questions/73025430", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8972132/" ]
to find the functions and procedures where a table is referenced, you can scan the `routine_definition` column of the `sysibm.routines` view for the table name. Use `regexp_instr` function to look for the pattern FROM|UPDATE|INSERT INTO followed by the table name. ``` with t1 as ( ...
you can use ibm function RELATED\_OBJECTS SQL <https://www.ibm.com/docs/en/i/7.3?topic=services-related-objects-table-function>
26,129,650
I am a beginner in python. I want to ask the user to input his first name. The name should only contain letters A-Z,if not, I want to display an error and request the user to enter the name again until the name is correct. Here is the code am trying. However, The string is not checked even when it contains numbers and ...
2014/09/30
[ "https://Stackoverflow.com/questions/26129650", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1671718/" ]
You don't need `re`, just use [str.isalpha](http://www.tutorialspoint.com/python/string_isalpha.htm) ``` def get_first_name(): while True: first_name = raw_input("Please enter your first name.") if not first_name.isalpha(): # if not all letters, ask for input again print "Invalid ent...
``` if (re.match("^[A-Za-z]+$", first_name)==False): ``` re.match is returning None when there is no match. None does not equal False. You could write it like this: ``` if not re.match("^[A-Za-z]+$", first_name): ```
63,498,826
[![Image of cone](https://i.stack.imgur.com/NuZNp.jpg)](https://i.stack.imgur.com/NuZNp.jpg) How do I make it so everything in the image is in gray-scale except the orange cone. Using opencv python.
2020/08/20
[ "https://Stackoverflow.com/questions/63498826", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13991355/" ]
You can achieve your goal by using `bitwise_and()` function and `thresholding`. Steps: * generate `mask` for the required region.(here `thresholding` is used but other methods can also be used) * extract required `regions` using `bitwise_and` (image & mask). * Add `masked regions` to get output. Here's sample code: ...
Here is an alternate way to do that in Python/OpenCV. * Read the input * Threshold on color using cv2.inRange() * Apply morphology to clean it up and fill in holes as a mask * Create a grayscale version of the input * Merge the input and grayscale versions using the mask via np.where() * Save the results Input: [![e...
54,450,504
I was looking for this information for a while, but as additional packages and python versions can be installed through `homebrew` and `pip` I have the feeling that my environment is messed up. Furthermore a long time ago, I had installed some stuff with `sudo pip install` and as well `sudo python ~/get-pip.py`. Is th...
2019/01/30
[ "https://Stackoverflow.com/questions/54450504", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1767754/" ]
Technically inline JavaScript with a `<script>` tag could do what you are asking. You could even look into the many templating solutions available via JavaScript libraries. That would not actually provide any benefit, though. JavaScript changes what is ultimately displayed, not the file itself. Since your use case doe...
This … > > My html file contains in many places the code `&nbsp;&nbsp;&nbsp;` > > > … is actually what is wrong in your file! `&nbsp;` is not meant to use for layout purpose, you should fix that and use CSS instead to layout it correctly. `&nbsp;` is meant to stop breaking words at the end of a line that are s...