sneekula 969 Nearly a Posting Maven

After the Swiss Federal Bank floated the Swiss Franc against the Euro, the Franc shot up so much that many Swiss take the short trip to Germany to literally buy things at half price.

sneekula 969 Nearly a Posting Maven

Then you have to change your code to:

def message():
    label['text'] = 'Good morning'

# for Python3 replace Tkinter with tkinter
import Tkinter as tk

win = tk.Tk()

label = tk.Label(win)
label.pack()
message()

win.mainloop()
sneekula 969 Nearly a Posting Maven

Apply append() this way:

i = 0
pack = []
mylist = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
while i < 17:
    sublist = mylist[i : i + 3]
    pack.append(sublist)
    i += 1
print (pack)
sneekula 969 Nearly a Posting Maven

I would use with, it closes your files properly. Also use a protocol for larger files:

import pickle

fname = "films.db"
with open(fname, "wb") as fout:
    # default protocol is zero
    # -1 gives highest prototcol and smallest data file size
    pickle.dump(favorite_movies, fout, protocol=-1)

# pickle load the object back in (senses protocol)
with open(fname, "rb") as fin:
    favorite_movies = pickle.load(fin)
sneekula 969 Nearly a Posting Maven

What operating system are you using?

marcelocent commented: win7 +0
sneekula 969 Nearly a Posting Maven

I took the liberty to time some of the approaches:

''' str_count_sub_timing_hperf.py
timing functions that count the number of sub_strings in a string
using high performance time.perf_counter() 
new in Python 3.3 and higher
'''

import time

def count_tony(text, sub):
    return sum(text[n:].startswith(sub)
           for n in range(len(text) - len(sub) + 1))

def count_snee(text, sub, start=0):
    count = 0
    while True:
        ix = text.find(sub, start)
        if ix < 0: break
        start = ix + 1
        count += 1
    return count

text = "this person assesses your performance"
sub = "sses"

# returned value is in fractional seconds
start = time.perf_counter()
result1 = count_tony(text, sub)
end = time.perf_counter()

elapsed = end - start
print("count_tony('{}', '{}') --> {}".format(text, sub, result1))
print("elapsed time = {:0.6f} micro_seconds".format(elapsed*1000000))

start2 = time.perf_counter()
result2 = count_snee(text, sub)
end2 = time.perf_counter()

elapsed2 = end2 - start2
print("count_snee('{}', '{}') --> {}".format(text, sub, result2))
print("elapsed time = {:0.6f} micro_seconds".format(elapsed2*1000000))

''' result (Python 3.4.1 64bit)-->
count_tony('this person assesses your performance', 'sses') --> 2
elapsed time = 38.228700 micro_seconds
count_snee('this person assesses your performance', 'sses') --> 2
elapsed time = 5.119915 micro_seconds
'''
Slavi commented: time well spent! :D +5
sneekula 969 Nearly a Posting Maven

@ivel
I looked at the code you have written and at NathanOliver's helpful suggestions. I came to the conclusion that you need beginner's help.

I took your code and corrected it, please study it:

/* modulus_exercise101.cpp
Write a program that counts the numbers from 3 to 117.
For multiples of three add 3 instead of 1
For the multiples of five add 5 instead of 1.
For numbers which are multiples of both three and five add 15
instead of 1.

Ex: If we are looking at numbers 5 to 15 (inclusive),
the program would output 39

compiled with mingw32-g++.exe on CodeBlocks IDE
*/

#include<iostream>

using namespace std;

int main()
{
    int x, y;
    int sum = 0;

    /*
    cout << "Choose starting number (from 3-117) " << endl;
    cin >> x;
    cout << "Choose ending number (from 3-117) " << endl;
    cin >> y;
    */
    // for testing only
    x = 5; y = 15;

    for (int i = x; i <= y; i++)
    {
        // do this conditional statement first
        if (i%3 == 0 && i%5 == 0)
        {
            sum += 15;
        }
        else if (i%3 == 0)
        {
            sum += 3;
        }
        else if (i%5 == 0)
        {
            sum += 5;
        }
        else
        {
            sum += 1;
        }
    }

    cout << "The total output between " <<x<< " and " <<y<< " is " << sum;

    return 0;
}

Your conditional if statements have to be in a certain order and you also have …

ddanbe commented: Nice +15
sneekula 969 Nearly a Posting Maven

@cambalinho
you are mixing char and int types, do the proper casts and your approach will work:

// str_Upper.cpp
// convert a string to all upper case

#include <iostream>
#include <string>

using namespace std;

string Upper(string text)
{
    string result;

    result.resize(text.size());
    for(int i = 0; i < text.size(); i++)
    {
        if ((int) text[i] > 96 && (int) text[i] < 123)
            result[i] = (char) ((int) text[i] - 32);
        else
            result[i] = text[i];
    }
    return result;
}

int main()
{
  string s = "A test this is 123";

  cout << s << endl;
  cout << Upper(s) << endl;

  return 0;
}

/* output -->
A test this is 123
A TEST THIS IS 123
*/
cambalinho commented: thanks +3
sneekula 969 Nearly a Posting Maven

Something like that:

// removes the third bit, simple way to create upper case char
char toupper(char ch)
{
  return ch & 0xDF;
}

Sorry doesn't handle numbers etc.

cambalinho commented: thanks +0
sneekula 969 Nearly a Posting Maven

Here you go:

s = "happy Hello World!"

print(s)
print(s.capitalize())
print(" ".join(w.capitalize() for w in s.split()))
print(s.lower())
print(s.upper())
print(s.swapcase())

''' my result -->
happy Hello World!
Happy hello world!
Happy Hello World!
happy hello world!
HAPPY HELLO WORLD!
HAPPY hELLO wORLD!
'''
sneekula 969 Nearly a Posting Maven

Why Did the Chicken Cross the Road?

KINDERGARTEN TEACHER: To get to the other side

PLATO: For the greater good.

ARISTOTLE: It is the nature of chickens to cross roads.

KARL MARX: It was a historical inevitability.

GEORGE W. BUSH: We don't really care why the chicken crossed the road.
We just want to know if the chicken is on our side of the road or not.

PROGRAMMER: It heard that they paid better on the other side.

sneekula 969 Nearly a Posting Maven

I wonder if they ever come back with a good old Western?

sneekula 969 Nearly a Posting Maven

@RobertHDD
I tried all your suggestions, but to no avail. PriceLess keeps popping up in the Chrome browser extensions.

I took XFind.exe and searched for the string PriceLess and found it in folder ProgramData, hidden in the Wildtangent games that MS shipped with Windows7. I deleted those silly games.

Then I disabled it in the Chrome extension and so far it stays disabled. When I removed it in the past, it simply came back after a few boots.

It is also found in folder:
ProgramData/Microsoft/Application Virtualization Client/Softgrid Client/sftfs.fsd

That is a huge file and I don't want to mess with it. Let's hope it stays disabled in the Chrome extensions.

sneekula 969 Nearly a Posting Maven

Junkware Removsl Tool found a few things and removed them, but PriceLess popped up again.

sneekula 969 Nearly a Posting Maven
sneekula 969 Nearly a Posting Maven

I got infected right after a Java and Adobe update on my Windows7 machine.
folder \jnihmpibahpjjmcodbopcpdaelkbpjnc is most likely a random generated folder.

Note on malware PriceLess (pops up as Chrome extension, highlights strings for ads):
PriceLess is in folders:
C:\Users\HomeGroupUser$\AppData\Local\Chromatic Browser\User Data\Default\Extensions\jnihmpibahpjjmcodbopcpdaelkbpjnc\5.2
C:\Users\HomeGroupUser$\AppData\Local\Comodo\Dragon\User Data\Default\Extensions\jnihmpibahpjjmcodbopcpdaelkbpjnc\5.2
C:\Users\HomeGroupUser$\AppData\Local\Google\Chrome\User Data\Default\Extensions\jnihmpibahpjjmcodbopcpdaelkbpjnc\5.2
C:\Users\HomeGroupUser$\AppData\Local\Google\Chrome SxS\User Data\Default\Extensions\jnihmpibahpjjmcodbopcpdaelkbpjnc\5.2
C:\Users\HomeGroupUser$\AppData\Local\Torch\User Data\Default\Extensions\jnihmpibahpjjmcodbopcpdaelkbpjnc\5.2
go down to /Extensions each and delete folder \jnihmpibahpjjmcodbopcpdaelkbpjnc

do the same for folders:
C:\Users\Guest\AppData\Local\Chromatic Browser\User Data\Default\Extensions
C:\Users\Guest\AppData\Local\Comodo\Dragon\User Data\Default\Extensions
C:\Guest\AppData\Local\Google\Chrome\User Data\Default\Extensions
C:\Users\Guest\AppData\Local\Google\Chrome SxS\User Data\Default\Extensions
C:\Users\Guest\AppData\Local\Torch\User Data\Default\Extensions

also do the same for folders:
C:\Users\Administrator\AppData\Local\Chromatic Browser\User Data\Default\Extensions
C:\Users\Administrator\AppData\Local\Comodo\Dragon\User Data\Default\Extensions
C:\Users\Administrator\AppData\Local\Google\Chrome\User Data\Default\Extensions
C:\Users\Administrator\AppData\Local\Google\Chrome SxS\User Data\Default\Extensions
C:\Users\Administrator\AppData\Local\Torch\User Data\Default\Extensions

in each case remove folder /jnihmpibahpjjmcodbopcpdaelkbpjnc
contains subfolder /5.2
with files -->
background.html
content.js
lsdb.js
manifest.json --> contains ref to "PriceLess"
r1Iz.js

Do a FindFile search for
*/5.2/r1Iz.js
to make sure you deleted them all

Clear your Recycle Bin

sneekula 969 Nearly a Posting Maven

Just a little faster than isprime2():

def isprime5(n):
    if n == 2 or n == 3: return True
    if n < 2 or n%2 == 0: return False
    if n < 9: return True
    if n%3 == 0: return False
    sqr = int(n**0.5)
    f = 5
    while f <= sqr:
        if n%f == 0: return False
        if n%(f+2) == 0: return False
        # loop every 6th integer
        f += 6
    return True
sneekula 969 Nearly a Posting Maven

The average American gains about 4 to 7 pounds between Thanksgiving and Christmas.

http://www.huffingtonpost.com/

sneekula 969 Nearly a Posting Maven

Okay, I got my Raspberry Pi B+ and have the Linux installed and running. Even wrote a few Python programs on the included Idle IDE.

I tried to write a Python program to turn on some of the io pins, but can't find good examples. Most of the web site references are pretty bad or nonexistent.

sneekula 969 Nearly a Posting Maven

One possibility:

def translate(text, e_s_dict):
    swed = ""
    space = " "
    for word in text.split():
        swed += e_s_dict[word] + space
    return swed


# english:swedish dictionary
e_s_dict = {"merry":"god",
"christmas":"jul",
"and":"och",
"happy":"gott",
"new":"nytt",
"year":"år"}

# english text
eng_text = "merry christmas"

# translate to swedish text
swed_text = translate(eng_text, e_s_dict)
print(swed_text)  # result --> god jul

Use meaningful variable names. It will help you understand what is going on.

sneekula 969 Nearly a Posting Maven

Knock knock!
Who's there?
"I am the beginning of the end
and the end of space and time"
Who are you?
"e"

sneekula 969 Nearly a Posting Maven

Hint:

mystring = "briyani"
for c in mystring:
    print(c)

# then this should give you the length
length = sum(1 for c in mystring)
print(length)
sneekula 969 Nearly a Posting Maven

If you use an IDE like Ninja, then you can switch beteeen different versions of Python by following the tabs:
Edit
Preferences
Execution
then simply edit the Python Path field.
If it shows
C:/Python32/python.exe
replace the 32 with 27

The Ninja IDE is free from:
http://www.ninja-ide.org/

sneekula 969 Nearly a Posting Maven

Write these two batch files and put a shortcut of each on your desk top:

rem save as idle27.bat
rem run the IDLE IDE with Python27
C:\Python27\pythonw.exe -u  C:\Python27\Lib\idlelib\idle.pyw

and

rem save as idle32.bat
rem run the IDLE IDE with Python32
C:\Python32\pythonw.exe -u  C:\Python32\Lib\idlelib\idle.pyw
sneekula 969 Nearly a Posting Maven

Looks like you use the Gregory–Leibniz series which converges rather slowly.
A much faster series is given in the Python manual under the decimal module recipes:

import decimal

def pi_decimal(prec):
    """
    compute Pi to the current precision
    """
    # increase precision for intermediate steps
    decimal.getcontext().prec = prec + 2
    D = decimal.Decimal
    # make starting assignments
    lasts, t, s, n, na, d, da = D(0), D(3), D(3), D(1), D(0), D(0), D(24)
    while s != lasts:
        lasts = s
        n, na = n+na, na+8
        d, da = d+da, da+32
        t = (t * n) / d
        s += t
    # reset to original precision
    decimal.getcontext().prec -= 2
    # unary plus applies the reset precision
    return +s


precision = 60
print("pi calculated to a precision of {}".format(precision))
print(pi_decimal(precision))
print("compare with published pi")
print("3.14159265358979323846264338327950288419716939937510582097494")

'''result ...
pi calculated to a precision of 60
3.14159265358979323846264338327950288419716939937510582097494
compare with published pi
3.14159265358979323846264338327950288419716939937510582097494
'''
sneekula 969 Nearly a Posting Maven

Here is a nice C# tutorial:
http://zetcode.com/lang/csharp/

The Python tutorial:
http://zetcode.com/lang/python/

Might as well look at the Java tutorial too:
http://zetcode.com/lang/java/

ddanbe commented: Nice links! +15
sneekula 969 Nearly a Posting Maven

I am not a Twitterer since I don't want them to violate the privacy of my e-mail contact list.

sneekula 969 Nearly a Posting Maven

Here is an example to get you started:

''' random_sentences101.py

# use this template to add more data
adjectives.append('')
subjects.append('')
verbs.append('')
objects.append('')

'''

import random

# create lists
adjectives = []
subjects = []
verbs = []
objects = []

# add data to the lists
adjectives.append('A small')
subjects.append(' boy')
verbs.append(' walked')
objects.append(' the fence')

adjectives.append('The big')
subjects.append(' trucker')
verbs.append(' climbed')
objects.append(' a tree')

adjectives.append('A tiny')
subjects.append(' frog')
verbs.append(' jumped over')
objects.append(' a log')

adjectives.append('The tardy')
subjects.append(' teacher')
verbs.append(' fell under')
objects.append(' two tables')


# construct n random sentences
n = 5
for k in range(n):
    sentence = random.choice(adjectives)
    sentence += random.choice(subjects)
    sentence += random.choice(verbs)
    sentence += random.choice(objects)

    print(sentence)
sneekula 969 Nearly a Posting Maven

The British spy agency the Government Communications Headquarters (GCHQ) has used a sophistcated version of the Regin virus to infect the Belgian telecommunications company Belgacom.

By targeting engineers through a faked LinkedIn page, GCHQ was able to get deep inside the Internet provider to steal data. One of Belgacom's main clients was the European Commission, the European Parliament, and the European Council of member state leaders.

Source:
http://news.yahoo.com/now-know-developed-state-sponsored-180205552.html

sneekula 969 Nearly a Posting Maven

Boy in a letter to Santa: "Send me a baby brother."
Santa in a letter to boy: "Send me your mother."

sneekula 969 Nearly a Posting Maven

News is often falsified on government orders, and the media seems to go along with it. That's too bad since a working democracy needs well informed, not missinformed, voters.

sneekula 969 Nearly a Posting Maven

Draw a group of shapes on the Tkinter GUI toolkit canvas and animate the group using the common tag names.

sneekula 969 Nearly a Posting Maven

You can try:

pre = "21:20:01 T:5796  NOTICE:"
for item in programList:
    print("{} {}".format(pre, item))
sneekula 969 Nearly a Posting Maven

You can accesss the clipboard simply by using the Tkinter GUI toolkit that comes with your Python installation.

Gribouillis commented: interesting +14
sneekula 969 Nearly a Posting Maven

Explore the Tkinter GUI toolkit to draw a circle and move it with the arrow keys:

# use a Tkinter canvas to draw a circle, move it with the arrow keys

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

class MyApp(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self.title("move circle with arrow keys")
        # create a canvas to draw on
        self.cv = tk.Canvas(self, width=400, height=400, bg='white')
        self.cv.grid()
        # create a square box with upper left corner (x,y)
        self.x = 120
        self.y = 120
        size = 150
        box = (self.x, self.y, self.x + size, self.y + size)
        # create a circle that fits the bounding box
        self.circle = self.cv.create_oval(box, fill='red')
        # bind arrow keys to movement
        self.bind('<Up>', self.move_up)
        self.bind('<Down>', self.move_down)
        self.bind('<Left>', self.move_left)
        self.bind('<Right>', self.move_right)

    def move_up(self, event):
        # move_increment is 5 pixels
        y = -5
        # move circle by increments x, y
        self.cv.move(self.circle, 0, y)

    def move_down(self, event):
        y = 5
        self.cv.move(self.circle, 0, y)

    def move_left(self, event):
        x = -5
        self.cv.move(self.circle, x, 0)

    def move_right(self, event):
        x = 5
        self.cv.move(self.circle, x, 0)


app = MyApp()
app.mainloop()
sneekula 969 Nearly a Posting Maven

A Toyota Prius battery, contains 168 1.2-Volt nickel-metal-hydride cells, which contain a total of 1.6 kilowatt-hours of energy. Its peak power output is 27 kilowatts, or about 36 horsepower.

sneekula 969 Nearly a Posting Maven

No module named pk_DOMI
means that cx_Freeze can't find the mnodule, or you don't have it.

BTW, if you really want help don't hijack old solved posts. Most helpful folks won't look there for your problem. Start a new thread.

sneekula 969 Nearly a Posting Maven

Explore the Tkinter GUI toolkit to draw a circle:

# draw a circle with given center (x,y) and radius
# tkinter normally needs a specified square

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

def get_center(x1, y1, x2, y2):
    '''
    for a rectangle with ulc=(x1,y1) and lrc=(x2,y2)
    calculate the center (x,y)
    '''
    x = x1 + (x2 - x1)//2
    y = y1 + (y2 - y1)//2
    return x, y

def get_square(x, y, radius):
    '''
    given the center=(x,y) and radius
    calculate the square for the circle to fit into
    return x1, y1, x2, y2 of square's ulc=(x1,y1) and lrc=(x2,y2)
    '''
    x1 = x - radius
    y1 = y - radius
    x2 = x + radius
    y2 = y + radius
    return x1, y1, x2, y2

# create the basic window, let's call it 'root'
root = tk.Tk()

# create a canvas to draw on
cv = tk.Canvas(root, width=300, height=300, bg='white')
cv.grid()

# draw a circle with given center (x,y) and radius
x, y = 150, 120
radius = 65
# to draw a circle you need to get the ul and lr corner coordinates
# of a square that the circle will fit inside of
rect = get_square(x, y, radius)
# draw the cicle that fits into the rect/square
# default fill is canvas bg
#cv.create_oval(rect)
circle1 = cv.create_oval(rect, fill='red')
# optionally show the recangle the circle fits into
cv.create_rectangle(rect)

# testing ...
print(get_square(x, y, radius))  # (10, 10, 90, 90)
print(get_center(*rect))   # …
sneekula 969 Nearly a Posting Maven

Strange, pyserial has a class Serial()
Did you accidentally save your code file as serial.py?

sneekula 969 Nearly a Posting Maven

Thanks, I got it to go!

''' pyg_Sound1.py
playing sound files using pyglet
download and install
pyglet-1.2alpha1.win32-py2.7.exe
from
http://www.lfd.uci.edu/~gohlke/pythonlibs/

avbin.dll is included
so pyglet can play .wav  .mp3  .ogg sound files
(but not .mid Midi files)
'''

import pyglet

# pick a sound file you have, or one of those below
# in this case file names are case sensitive
#sound_file = 'drums.ogg'
#sound_file = 'cool_f.wav'
sound_file = 'Boing.mp3'

music = pyglet.media.load(sound_file)
music.play()

pyglet.app.run()
sneekula 969 Nearly a Posting Maven

The American News Media can only handle three major events at a time.

sneekula 969 Nearly a Posting Maven

"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones."
--- Albert Einstein

sneekula 969 Nearly a Posting Maven

"We are asleep until we fall in Love!"
--- Leo Tolstoy

sneekula 969 Nearly a Posting Maven

Here is a typical example:

def funk(arg1, arg2, arg3):
    pass

arg1 = 77
# call function with only one argument
funk(arg1)

''' error -->
Traceback (most recent call last):
  File "<module1>", line 5, in <module>
TypeError: funk() takes exactly 3 arguments (1 given)
'''
sneekula 969 Nearly a Posting Maven

... not fixed and running properly??

sneekula 969 Nearly a Posting Maven

Looks like I have to bring up IDLE or IDLEX for each version of Python.

sneekula 969 Nearly a Posting Maven

Ninja looks great, but again fails the input test, at least on a Windoze machine. The output console does not show the prompt or what you type in until Enter is pressed. Pretty bad!

sneekula 969 Nearly a Posting Maven

Since Python has this miserable version two-three mess right now, it would be nice to have an IDE that let's the user select the version to run.

Editra that comes in the wx folder allows you to easily do that, but it does not handle input() well at al.

sneekula 969 Nearly a Posting Maven

The newer Portable Python 2.7.6.1 package contains the following applications/libraries:

PyScripter v2.5.3
PyCharm Community Edition 3.1.2 (Thanks to cebik)
NymPy 1.8.1
SciPy 0.13.3
Matplotlib 1.3.1
PyWin32 218
Django 1.6.2
PIL 1.1.7
Py2Exe 0.6.9
wxPython 3.0.0.0
NetworkX 1.7
Lxml 3.3.4
PySerial 2.7
PyODBC 3.0.7
PyGame 1.9.1
PyGTK 2.24.2
PyQt 4.10.4
IPython 1.2.1
Pandas 0.11.0
Dateutil 2.2
PyParsing 2.0.1
Six 1.6.1
XLRD 0.9.2
XLWT 0.7.5
XLUtils 1.7.0
OpenPyXL 1.8.5

The best way to run Python on a Windoze machine! Since MS tries so hard to discourage Python users.

Now you have three IDEs available:
Pyscripter (PyScripter-Portable.exe)
Pycharm (PyCharm-Portable.exe)
IDLE (IDLE-Portable.exe)

There is also the old Pythonwin.exe in the site-packages folder.

sneekula 969 Nearly a Posting Maven

Santa has no religious meaning. He is a jolly soul that represents gift giving, flying sleds and obesity. Let's name the whole thing Santaday.