Posts

Showing posts with the label python

Pygame - locking the scroll of a surface area to a limited amount

Image
Pygame - locking the scroll of a surface area to a limited amount I'm playing with pygame and I'm making a memory game. In my memory game I need to have a small Menu on the middle-bottom of the screen and the player list on top of the screen. The game manager will output the message in the upper left corner of the screen. The playable board where the cards will be situated should be in the center of the screen with a small margin on the right and the left and about 200px from the top and the bottom.(e.g. if the screen width and height are 1200 x 800, the playable board should be from 2 to 1998 width and 200 to 600 height. I've made a screenshot of the idea I have: I've put up the idea of the scrollable board with the cards, although it's hardcoded for now, I mostly need the idea not the code since I just have a hard time figuring out how it should work. The playable board (game board on the screenshot), should be moved through the keyboard(so up, right, down, left a...

Docker mongodb connection refused on mac os when loading http://0.0.0.0:27017

Docker mongodb connection refused on mac os when loading http://0.0.0.0:27017 Browser Screenshot I have 2 docker containers running mongo:3.0.3 and python:2.7. And I have an app.py which connects to mongodb instance. In my app.py I have used port 5000 to map 27017. The app.py runs fine but when I visit http://0.0.0.0:5000 this connection refused error comes on terminal. 172.17.0.1 - - [01/Jul/2018 10:01:32] "GET / HTTP/1.1" 500 - Traceback (most recent call last): File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__ return self.wsgi_app(environ, start_response) File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app response = self.make_response(self.handle_exception(e)) File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception reraise(exc_type, exc_value, tb) File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1817, i...

Python regex needed for format: 'delete([any text here])'

Python regex needed for format: 'delete([any text here])' I am a total regex beginner. I want to create a regular expression that strictly allows the word delete followed by two closed parenthesis that contain any kind of characters (http://www.waynesworld1.com) . delete (http://www.waynesworld1.com) If I put it all together, it should accept the following: delete(http://www.waynesworld123.com) . delete(http://www.waynesworld123.com) Let me emphasize that the regex should strictly accept delete() and shouldn't accept elete() . As long as the user types in delete() anything is acceptable within the parenthesis ( example: this would be fine delete(12!@Ww) delete() elete() delete() delete(12!@Ww) How can I craft this regex in Python? So far all I have is /delete/ for my regex. /delete/ Why the downvote? This is a perfectly reasonable question that is well constructed and very understandable. I have done previous research and haven't found a...

How do I get the opposite (negation) of a Boolean in Python?

How do I get the opposite (negation) of a Boolean in Python? For the following sample: def fuctionName(int, bool): if int in range(...): if bool == True: return False else: return True Is there any way to skip the second if-statement? Just to tell the computer to return the opposite of the boolean bool ? bool This is probably just pseudocode, but int and bool are both builtin names (for the types they represent), and should not be used as variable names. – SingleNegationElimination Aug 11 '11 at 18:19 int bool yes, it's just a pseudo-code ,, demonstration purposes only... – amyassin Aug 11 '11 at 18:26 ...

creating a custom template tags in django

creating a custom template tags in django I am new to Django and I am trying to create custom tags in django my custom tag file templatetag/custom_tag.py templatetag/custom_tag.py from django import template from model_file.models import my_Model register = template.Library() @register.simple_tag def get_custom_tag_fn(): return my_Model.objects.all() my html file {% load custom_tag %} {% get_custom_tag_fn as queries %} {% for query in queries %} {{query.json_my_model_data}} {% endfor %} I am not getting any output or error from this code. Can anyone point where I went wrong. for extra information my model.py looks like model.py from django.db import models from jsonfield import JSONField class my_Model(models.Model): json_my_model_data = JSONField() Are there any instances in my_Model ? – Willem Van Onsem Jul 1 at 9:43 ...

Pandas - Check adjacent column for value

Pandas - Check adjacent column for value I have a df that tracks the status of an issue. From 'Open', 'In Progress' to 'Closed' like such: T1 T2 T3 T4 T5 1 Open In Progress Closed 2 In Progress Closed 3 Open In Progress Open Closed 4 Open In Progress Closed Open Closed 5 Open In Progress Closed Basically I want to find all issues that get reopened. This can be noted by any row that has a Closed value that then has a followup transition. For example, index  4  has a closed value in  T3  but then  T4  contains something to indicate it has been reopened. Closed 4 T3 T4 The output would be: T1 T2 T3 T4 T5       Reopened 1 Open In Progress Closed                       0 2 In Progress Closed                                   0   3 Open In Progress Open Closed               0 4 Open In Progress Cl...

How to stop the mainWindow while opened a new Window and get my Value

How to stop the mainWindow while opened a new Window and get my Value My problem is that i have an Main-Class with an button-click function, where if i click the button, the EntryBox will be opened and in the button-click function i want to create the folder too, but i dont know how to "stop" the mainWindow while the EntryBox-Window is open to get the value(Folder name). @BryanOakley Minimal, Complete, and Verifiable example: That's my msBox.py import tkinter as tk FolderName = "" class EntryBox: def __init__(self, Text): self.root = tk.Tk() self.textBox = tk.Entry(self.root) self.EBOKAY = tk.Button(self.root, text="Okay") self.EBOKAY.bind("<Button-1>", self.EBOKAY_click) self.EBLabel = tk.Label(self.root, text=Text) self.EBLabel.pack() self.textBox.pack() self.EBOKAY.pack() self.root.mainloop() def EBOKAY_click(self, event): global FolderName FolderName = self.textBox.get() self.root.dest...

Difference between r'^specific expression$' and r'specific expression' [duplicate]

Difference between r'^specific expression$' and r'specific expression' [duplicate] This question already has an answer here: My doubt is that I came across a regex which checks whether a password is strong or not. What is the impact of ^ and $ in this expression. a = compile(r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$') It has ^ and $ signs in it. But the below code works the same as above. a = compile(r'(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}') If so why are they been used in the above code. Or is there reason for its usage. Thanks in advance! This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. You would not ask the difference if you knew why caret and dollar sign are being used. Please check the marked question. – revo Jul 1 at 10:27 ...

How to share a :memory: database between different process in python using python sqlite3 package

How to share a :memory: database between different process in python using python sqlite3 package scenario is shown as below,i got many processes to do CPU-bound work and read only on the same database,i know cache and uri key words could be used for sqlite to share database cache between threads,but how about between processes?it's better to be available both for linux and windows, Thank you! def run(self): self.phyconn = apsw.Connection(self.fileName) self.memconn = apsw.Connection(":memory:") try:#backup.__exit__() just make sure copy if finished,not close backup,so with is good,memconn is still exist when out with self.memconn.backup("main", self.phyconn, "main") as backup: # call with 0 to get the total pages backup.step(0) total = backup.pagecount stepped = 0 one_percent = total if total < 100 else total // 100 last_percentage = 0 while step...

while/try/except decimal TypeError not working

while/try/except decimal TypeError not working I thought I could finally get some use out of the while/try/except loop, but I am encountering a problem. My task is to have the computer request numbers from a user until '0' is entered. After this, the numbers entered will be added. My problem is that the Except part isn't catching non-numeric entries. If a non-numeric entry is entered, I get a regular error message that stops the program. Here is what happens when I enter 3 numbers and the 4th entry is 'm': on win32 Type "copyright", "credits" or "license()" for more information. >>> RESTART: C:/Users/Username/Documents/CISPROG1/Homework 5/Homework5.1.SumGenerator.py Enter 1st element (or type '0' to finish). 1 Enter 2nd element (or type '0' to finish). 2 Enter 3rd element (or type '0' to finish). 3 Enter 4th element (or type '0' to finish). m Traceback (most recent call last): File "C:/...

Neural Network - ValueError: Cannot feed value of shape

Neural Network - ValueError: Cannot feed value of shape I'm new in Python and Tensorflow . For the beginning I watched the MNIST tutorial and understood it so far. But now I have to create a new Neural Network with numerical input_datas. I got a dataset which delivers an input_data and v_data. If I run input_data.shape -> (1000,25,4) If I run v_data.shape -> (1000,2) What I tried to do is to split the data for (Training + Validation) and Testing. Training + Validation = 90% of train_data (90% of the input.pkl) Testing data = the remaining 10% And then I devided the 90% of the input_data in training and validation (70% training, 30% validation) The network should correctly predict based on v_data, but I still get an error. See the code and the error below. import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # Imports import tensorflow as tf import pickle as pkl import numpy as np # load data with open('input.pkl', 'rb') as f: input_data = pkl...

python paramiko error “AttributeError: 'NoneType' object has no attribute 'open_session'”

python paramiko error “AttributeError: 'NoneType' object has no attribute 'open_session'” I'm trying python paramiko module, got below error. How can I solve this? (I searched a lot, but no lucky) Any replies will be appreciated. (On Mac OS) python2.7 aaa.py Traceback (most recent call last): File "aaa.py", line 24, in <module> ssh_command('172.16.129.130', 22, 'user', 'password', 'ls') File "aaa.py", line 14, in ssh_command stdin,stdout,stderr = client.exec_command(command) File "/Users/usera/anaconda2/lib/python2.7/site- packages/paramiko/client.py", line 480, in exec_command chan = self._transport.open_session(timeout=timeout) AttributeError: 'NoneType' object has no attribute 'open_session' Python version Python 2.7.14 |Anaconda, Inc.| (default, Dec 7 2017, 11:07:58) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin Type "he...

Facing “Missing XCode Dependency: Python Module ”Six“ ” even after installing six

Facing “Missing XCode Dependency: Python Module ”Six“ ” even after installing six Facing "Missing XCode Dependency: Python Module "Six" " even after installing six Pip Already installed pip install six Requirement already satisfied: six in /usr/local/lib/python2.7/site-packages (1.11.0) But still flutter doctor asks to install pip Shivas-MacBook-Pro:Flutter shivapokala$ flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel beta, v0.5.1, on Mac OS X 10.13.5 17F77, locale en-US) [✓] Android toolchain - develop for Android devices (Android SDK 27.0.0) [!] iOS toolchain - develop for iOS devices (Xcode 9.4.1) ✗ Missing Xcode dependency: Python module "six". Install via 'pip install six' or 'sudo easy_install six'. [✓] Android Studio (version 3.1) [!] Connected devices ! No devices available ! Doctor found issues in 2 categories. 1 Answer ...

Iterate over every nth element in string in loop - python

Iterate over every nth element in string in loop - python How can iterate over every second element in string ? One way to do this would be(If I want to iterate over nth element): sample = "This is a string" n = 3 # I want to iterate over every third element i = 1 for x in sample: if i % n == 0: # do something with x else: # do something else with x i += 1 Is thery any "pythonic" way to do this? (I am pretty sure my method is not good) for i,x in enumerate(sample,1): – Jean-François Fabre Jul 1 at 9:11 for i,x in enumerate(sample,1): 3 Answers 3 If you want to do something every nth step, and something else for other cases, you could use enumerate to get the index, and use modulus: enumerate sample = ...