4,305 Posted Topics
Re: Make your own unique/creative templates and someone will copy them. | |
Just in time for the season, a star. (Playing with my grandson on the Raspberry Pi computer) | |
Re: I usually keep Python2 and Python3 on my Windows machine and you can do the same on a Linux computer. On Windows the trick is to tell your IDE which version to use. On Linux you can use the shebang line. My $35 Raspberry Pi computer (Linux) came with both … | |
Re: Another option ... # remove_line_numbers102.py # copied from # http://personal.denison.edu/~krone/cs173/files/PythontoC++.pdf # page 11 s = ''' 1 #include <iostream> 2 using namespace std; 3 4 int gcd(int u, int v) { 5 int r; 6 while (v != 0) { 7 r = u % v; // compute remainder 8 … | |
Re: I love action, so it would be Las Vegas or New York City. | |
Re: See http://www.ninja-ide.org/ and http://idlex.sourceforge.net/ My criteria for a good IDE is how it handles input() ... # input test (use raw_input() for Python2) name = input("Enter your name") print(name) | |
Re: See also ... http://www.raspberrypi.org/help/what-is-a-raspberry-pi/ http://www.raspberrypi.org/help/faqs/ Note: The Raspberry Pi computer module runs on Linux Debian and does come with python and pygame. It also comes with a bunch of addressable IO pins, not bad for $35. | |
Once you are on the internet, you have to come up with passwords. After a while it will be difficult to remember those passwords. You could write them down somewhere, but the wrong person could find them. Why not have Python help you to come up with a logical password … | |
Re: Virginia City in Nevada. Pretty wild area, home of the Bonanza western. | |
Re: If your scores don't exceed the line width, then you can use this simple barchart ... def h_bar(mylist): ''' a simple horizontal bar chart ''' for item in mylist: print('-' * item) scores = [2, 4, 7, 11, 25, 45, 33, 24] h_bar(scores) ''' result ... -- ---- ------- ----------- … | |
Re: Sad news indeed, rest in peace Melvin! Looking at his age, I should rename myself the "More Ancient Dragon" | |
Re: Roadrunner, fast and smart. | |
Re: Here is an example ... ''' pg_mouseposition1.py show mouse position with module pygame to see a list of event constants use: import pygame.constants help(pygame.constants) ''' import pygame as pg # create a 640x400 window/screen screen = pg.display.set_mode((640, 400)) screen.fill((255, 0, 0)) # red running = True while running: event = … | |
Re: Use of `if __name__ == '__main__':` # use it for testing function1() # allows the program to run or be an importable module # __main__ is the namespace of the current program # if a module is imported the namespace changes to the name of the module def function1(): pass … | |
Re: I haven't worked with py2exe for a while, but try this ... from distutils.core import setup import py2exe import lxml import gzip import requests import sys sys.argv.append("py2exe") sys.argv.append("-q") setup( console=['Ty.py'], options={ 'py2exe': {'includes': ['lxml.html', 'lxml._elementpath', 'lxml.etree','gzip','requests']}, } ) | |
This snippets shows how to have fun replacing multiple words in a text. The target words and the replacement words form key:value pairs in a dictionary. The search and replacement is done using Python's regular expression module re. The code also gives an example of a function within a function. | |
Re: I can not remember the last time I sent out a handwritten letter. However, I do sent birthday cards with money in them to my nieces, nephews and grandchildren. | |
Re: import os.path directory = r"C:\Python27\mystuff" # Windows filename = "New.txt" path = os.path.join(directory, filename) # test print(path) # result --> C:\Python27\mystuff\New.txt # then ... with open(path, 'r') as fin: text = fin.read() Note: Windows allows you to replace \ with / in the directory string | |
Re: In general ... mydict = { 'a':'n', 'b':'o', 'c':'p', 'd':'q', 'e':'r', 'f':'s', 'g':'t', 'h':'u', 'i':'v', 'j':'w', 'k':'x', 'l':'y', 'm':'z', 'n':'a', 'o':'b', 'p':'c', 'q':'d', 'r':'e', 's':'f', 't':'g', 'u':'h', 'v':'i', 'w':'j', 'x':'k', 'y':'l', 'z':'m', 'A':'N', 'B':'O', 'C':'P', 'D':'Q', 'E':'R', 'F':'S', 'G':'T', 'H':'U', 'I':'V', 'J':'W', 'K':'X', 'L':'Y', 'M':'Z', 'N':'A', 'O':'B', 'P':'C', 'Q':'D', 'R':'E', … | |
Re: Check ... https://www.daniweb.com/software-development/python/code/488871/year-combobox-python-tkinter | |
An example how to use Tkinter's OptionMenu() as a combobox to allow one year to be selected from an option list of let's say the past 15 years. | |
Re: You need to use at least Python version 3.4 ... ''' enum_test101.py module enum is new in Python34 see: http://legacy.python.org/dev/peps/pep-0435/ ''' from enum import Enum class Colour(Enum): WHITE = (255,255,255) BLACK = (0,0,0) RED = (215,45,45) BLUE = (45,87,214) YELLOW = (230,223,48) GREEN = (45,194,64) print(Colour.BLACK.value) # (0, 0, 0) | |
Re: Where is the loop? | |
Re: Could be as simple as this ... def generate_n_chars(n, ch): return ch * n # test ch = 'z' n = 10 print(generate_n_chars(n, ch)) # result --> zzzzzzzzzz | |
Re: Here we go ... ''' tk_button_run_hello.py run an external Python program via a tkinter button tested with Python3 ''' # replace tkinter with Tkinter in Python2 import tkinter as tk def run_hello(): execfile("hello.py") root = tk.Tk() btn = tk.Button(root, text="Run program Hello", command=run_hello) btn.pack() root.mainloop() Here is hello.py ... ''' … | |
Re: Another option ... s = "abcdefg" for ix, c in enumerate(s): pass length = ix + 1 print(length) | |
Re: Oh yes, it is necessary for the NSA to know how much fibre you are getting in your diet. With the cost of the affordable care act going up, the government needs to know that you are living healthy. Also, eating a Middle Eastern diet would make you a potential … | |
Re: See also `__STDC_VERSION__` ... http://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html | |
Re: I am partial to Dell, usually get them at Best Buy. The only problem is that most notebooks/laptops come with Wndows 8.1 that can be frustrating to the user. | |
For those of you who are inquisitive, here is a little Python program to approximate the value of pi to 77 digits. You can easily go further, just change the value n in range(n+1). | |
| |
Re: I like Python because you can be very innovative and quick when solving problems. My advice, stick with the newer Python3 version. Since the internet is full of Python2 examples, learn to recognize the older syntax and change it. If I remember it correctly, C# (Csharp) was Microsoft's answer to … | |
Re: I like Wikipedia's approach to weed out the not-so-true stuff. | |
Re: Maybe you should start with one of those remote controlled quatro-copter/camera combinations that are the rage right now. At least the first 10 km of space are yours to explore. Once you get into military airspace all bets are off! | |
This snippet shows you how to animate a dice roll with the Tkinter GUI, useful for many games that require a dice to give a random number from 1 to 6. An interesting use of Tkinter's grid(), grid_forget() and after() functions. | |
Re: IndentationError: unexpected indent | |
Re: Use a copy of image im2 = im.copy() Then in the loop try ... im2.putpixel((x, H-y-1),(p[0], p[1], p[2])) | |
![]() | Re: Another way to look at this ... ''' mpm_stuff.py comparing Python module mpmath result to C 64bit double results ''' from mpmath import * # convert to mpmath float x = mpf(65536) # set precision mp.dps = 16 print("Factorial of 65536:") print(fac(x)) print("5.162948523097533e+287193 (C)") print("65536 to the Power of 65536:") … |
| |
Re: Transferring files under Windows7 was a lot nicer than under Windows8. If Windows10 adds another "improvement", I have to think Linux. | |
Re: At your level it would be easier to time the seconds it takes to answer all the questions ... import random from datetime import datetime as dt correct = 0 incorrect = 0 name = input("Enter your name: ") start = dt.now() for i in range(10): number1 = random.randint(1,10) number2 … | |
Re: You can follow this guide ... http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Variable_Names To me the underline connector is most readable. | |
Re: You need to create a random list for the bucket_sort argument lst ... import time import random #BUCKET SORT (up to 30) def bucket_sort(lst): bucket, bucket1, bucket2 = [], [], [] #The three empty buckets #Populating the buckets with the list elements for i in range(len(lst)): if lst[i] in range(11): … | |
Re: I can not imagine working in one of those open office spaces. There are simply too many distractions to think properly. | |
Re: Your problem is in function gen(), the list comprehension should be ... def gen(number, b=100000): return [random.randint(0, b) for x in xrange(number)] | |
Re: For another possibility see ... http://greenlet.readthedocs.org/en/latest/ | |
Re: French in turn originates from Latin and old Gallic languages. "It's all Greek to me!" | |
![]() | Re: Snow, deer and mountains make a Jeep 4x4 about the best thing to drive. |
Re: If the old information is logged (saved), then go the way of your hangman game. |
The End.