Community Member
Member Avatar
sneekula 969 Replied To a Post in writing text from right to left
Topic by fonzali in Software Development
There might be a Persian version of Python. Reply by sneekula
Member Avatar
Topic by Niloofar24 in Software Development
Normally you build a house from the bottom up. Try to understand the basics of Python first and put the windows in later. Reply by sneekula
Member Avatar
Featured sneekula 969 Gave Reputation to almostbob in Jokes
Topic by Ancient Dragon in Community Center
I had a power outage at my house this morning and my PC, Laptop, TV, DVD, IPad and my new surround sound music system were all shut down.

Then I discovered that my iPhone battery was flat.

To top it off, it was raining so I couldn't go for a … Reply by almostbob
Member Avatar
Featured sneekula 969 Replied To a Post in There is an elephant on the loo!
Topic by vegaseat in Community Center


Computer languages Worldwide, Jan 2015
Meassured by the number of inquiries on Google
(a mixture of "I am interested" and "I am lost")
----------------------------------------------------
Rank Language Share(%) Trend(% vs a year ago)
----------------------------------------------------
1 Java 24.7 -0.4
2 PHP 11.7 -1.2
3 Python 10.6 +0.9
4 C# 8.9 -0.3
5 … Reply by sneekula
Member Avatar
Featured sneekula 969 Replied To a Post in PriceLess malware
Topic by sneekula in Information Security
Update:
PriceLess has so far stayed away from my Chrome Web Browser extensions. However I can still find references to it, for instance if I save a file without extension then the file manager lists "PriceLess" as the file type. Like I claimed before frigging Windows7 is like Swiss cheese, … Reply by sneekula
Member Avatar
Topic by Niloofar24 in Software Development
Try it this way:


''' favemovies.py

with iPython on Windows use:
run C:\Python27\Atest27\Bull\favemovies.py view
'''

import sys
import pickle
# for Python3 replace Tkinter with tkinter
import tkinter as tk

def view():
favorite_movies = pickle.load( open("films.db", "rb"))
favorite_movies_string = "\n".join(favorite_movies)
label['text'] = favorite_movies_string


win = tk.Tk()

label = tk.Label(win, bg='yellow') … Reply by sneekula
Member Avatar
Featured sneekula 969 Replied To a Post in Random Facts
Topic by Reverend Jim in Community Center
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. Reply by sneekula
Member Avatar
Topic by Niloofar24 in Software Development
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() Reply by sneekula
Member Avatar
Topic by Niloofar24 in Software Development
Try:


def message():
print('Good morning')

from Tkinter import *
tk = Tk()
message()
tk.mainloop() Reply by sneekula
Member Avatar
sneekula 969 Replied To a Post in creating list of lists
Topic by kouty in Software Development
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) Reply by sneekula
Member Avatar
sneekula 969 Replied To a Post in creating list of lists
Topic by kouty in Software Development
Avoid using Python function names like **list** for variable names.

if you use
list = [1, 2, 3]
and later
abc_list = list('abc')
it won't work! Reply by sneekula
Member Avatar
Topic by Niloofar24 in Software Development
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 … Reply by sneekula
Member Avatar
Featured sneekula 969 Replied To a Post in Code Snippet Check if a number is a prime number (Python)
Topic by vegaseat in Software Development
A simple timing example:


import time

def print_timing(func):
"""
a decorator function to time another function
time.clock() works on Windows systems only
you can use time.time() instead, but it gets updated less
frequently and can give 0.0 results on faster functions
"""
def inner(*arg):
"""*arg are the arguments of function … Reply by sneekula
Member Avatar
Topic by marcelocent in Software Development
To work with the clipboard see:
https://www.daniweb.com/software-development/python/code/487653/access-the-clipboard-via-tkinter#post2142575 Reply by sneekula
Member Avatar
Topic by marcelocent in Software Development
What operating system are you using? Reply by sneekula
Member Avatar
sneekula 969 Replied To a Post in do-while loop in python
Topic by shafter111 in Software Development
The elegant thing about the **while True** loop is that you can break at a given point between statements. Reply by sneekula
Member Avatar
sneekula 969 Replied To a Post in count of substrings. append method
Topic by kouty in Software Development
Note that overlapping subs won't work with text.count():


text = "assesses"
sub = "sses"

print(text.count(sub)) # --> 1 ??? Reply by sneekula
Member Avatar
sneekula 969 Replied To a Post in count of substrings. append method
Topic by kouty in Software Development
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 … Reply by sneekula
Member Avatar
sneekula 969 Replied To a Post in how do the uppercase and lowercase?
Topic by cambalinho in Software Development
c++
You can modernize this a little:


// str_toupper.cpp
// convert a string to all upper case
// compiled with mingw32-g++.exe

#include <algorithm> // transform()
#include <cctype> // toupper()
#include <iostream>
#include <string>

using namespace std;

char upper_case(char ch)
{
return toupper(ch);
}

int main()
{
string s = "this is … Reply by sneekula
Member Avatar
Topic by RobertHDD in Community Center
Slowing down the Earth to a speed that would make it fall into the Sun within a few days time, would flatten it like a ripe tomato hitting a wall. Reply by sneekula
Member Avatar
Featured sneekula 969 Replied To a Post in Projects for the Beginner
Topic by vegaseat in Software Development
If you go to:
http://en.wikipedia.org/wiki/List_of_countries_by_inflation_rate
you can extract the 10 countries with the highest inflatuion rate.

You end up with this tab delimited data string:


data = '''\
Uruguay 8.11 2014 November
Turkey 8.9 2014 November
Egypt 10.61 2014 June
Argentina 24.2 2014 November
Ukraine 13 2014 December
Syria 13.6 … Reply by sneekula
Member Avatar
Featured sneekula 969 Replied To a Post in There is an elephant on the loo!
Topic by vegaseat in Community Center
10 countries with with the highest mid 2014 inflation rate:

Country Inflation (%)
Venezuela 60.9
Sudan 46.8
Belarus 32.8
Argentina 24.2
Iran 14.6
Syria 13.6
Ukraine 13.0
Egypt 10.61
Turkey 8.9
Uruguay 8.11

Source:
http://en.wikipedia.org/wiki/List_of_countries_by_inflation_rate Reply by sneekula
Member Avatar
Topic by RobertHDD in Community Center
What external force could slow down the Earth orbital speed? Reply by sneekula
Member Avatar
sneekula 969 Replied To a Post in counting numbers
Topic by ivel in Software Development
c++
You have this execution/evaluation order:
1) if (i%3 == 0 && i%5 == 0)
2) else if (i%3 == 0)
3) else if (i%5 == 0)
4) else

Here 2) and 3) could be swapped

If 1) is true then the else conditions 2) 3) 4) will not be evaluated. … Reply by sneekula
Member Avatar
sneekula 969 Replied To a Post in count of substrings. append method
Topic by kouty in Software Development
Hmm:


''' str_find_sub_index.py
explore
s.find(sub[ ,start[,end]]) returns index or -1
'''

text = "trans panamanian bananas"
sub = "an"

start = 0
count = 0
while True:
ix = text.find(sub, start)
if ix < 0:
break
# move up start in function find()
start = ix + 1
count += … Reply by sneekula
Member Avatar
sneekula 969 Replied To a Post in counting numbers
Topic by ivel in Software Development
c++
@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 … Reply by sneekula
Member Avatar
sneekula 969 Replied To a Post in how do the uppercase and lowercase?
Topic by cambalinho in Software Development
c++
@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++)
{ … Reply by sneekula
Member Avatar
sneekula 969 Replied To a Post in how do the uppercase and lowercase?
Topic by cambalinho in Software Development
c++
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. Reply by sneekula
Member Avatar
Featured sneekula 969 Replied To a Post in Projects for the Beginner
Topic by vegaseat in Software Development
Write a Python program that checks a given directory for any file changes over a given period. Reply by sneekula
Member Avatar
Topic by Niloofar24 in Software Development
Give us a short example of what your project data looks like. Reply by sneekula