ZZucker 342 Practically a Master Poster

The Washington Post reports that the NSA has done many thousands of illegal snooping without the approval of the rubberstamp courts. Is the system out of control?

By the time people are scared to say anything against their rulers, it's too late!

ZZucker 342 Practically a Master Poster

So this is where Samsung gets all their good ideas.

nitin1 commented: hehe.... yeah :p +0
ZZucker 342 Practically a Master Poster

To me Python has always been the quick tool to develop ideas. A bloated cumbersome IDE does not help.

ZZucker 342 Practically a Master Poster

Data mining of large amounts of text (like e-mails or tweets) for certain keywords or key phrases.

ZZucker 342 Practically a Master Poster

Do not use str for a string variable name

ZZucker 342 Practically a Master Poster

However, if you want to use the error handler, things are a lot simpler and an integer wil be changed to a float too:

while True:
    s = raw_input("Enter a float: ")
    try:
        n = float(s)
        break
    except ValueError:
        pass

print(n)
ZZucker 342 Practically a Master Poster

If the user enters an integer, your program should be smart enough to use it as a float.
I also understood you didn't want to use "try except" error handling.

Quoting:

... but how it will be done without using "try and exception"

ZZucker 342 Practically a Master Poster

Moral:
"Don't assume if a program does not work, that it is fault of the computer or the language."

ZZucker 342 Practically a Master Poster

Password expansion is a good idea. Here is one way to do it:

''' password_expand.py
a longer password is more secure, so expand it this way
'''

def password_expand(pw):
    s1 = pw
    s2 = "".join(chr(ord(c) + 1) for c in pw)
    s3 = "".join(chr(ord(c) - 1) for c in pw)
    return s1 + s2 + s3

# the user enters this password
pw = 'Nixon'

# program uses this password
pw2 = password_expand(pw)

# test
print(pw)
print('-'*30)
print(pw2)

''' my output -->
Nixon
------------------------------
NixonOjypoMhwnm
'''
ZZucker 342 Practically a Master Poster

The code from james.lu.75491856 (James Lu) can easily be cracked with character frequency analysis, since the most common characters in the English language (or any other language) will still be assigned the same sub characters.

ZZucker 342 Practically a Master Poster
ZZucker 342 Practically a Master Poster

No need to do that.

ZZucker 342 Practically a Master Poster

Use the Python module decimal to show that the result of 1/61
has a period of 60 (repeats every 60 digits),
also every digit appears 6 times in the period.

ZZucker 342 Practically a Master Poster

Another option is to use Tkinter's simple dialogs for user input, and to some extent output too:

# use Tkinter's simple dialogs (pop-up) to ask for input
# minvalue and maxvalue are optional

try:
    # for Python2
    import Tkinter as tk
    import tkSimpleDialog as tksd
except ImportError:
    # for Python3
    import tkinter as tk
    import tkinter.simpledialog as tksd

root = tk.Tk()
# show input dialogs without the Tkinter window
root.withdraw()

# if a non-numeric value is entered, will prompt again
price = tksd.askfloat("Price", "Enter the price of the item:")
print(price)
# use askfloat or askinteger (whole items only)
quantity = tksd.askinteger("Quantity", "Number of items needed:",
    minvalue=1, maxvalue=1000)
print(quantity)

result = "Total cost is %0.2f" % (price*quantity)
print(result)

# you could use askstring to display the result
sf = "%0.2f" % (price*quantity)
tksd.askstring("Result", "Total cost is:", initialvalue=sf)
ZZucker 342 Practically a Master Poster

Thanks for pointing that pywin32 needs to be installed too!

ZZucker 342 Practically a Master Poster

Check out Python module difflib

ZZucker 342 Practically a Master Poster

Thanks Henri, module pyttsx is somewhat complicated to install, but works well.
Doesn't seem to work with Python3?

ZZucker 342 Practically a Master Poster

A slight modification of vegaseat's original code to take care of whole words:

''' re_sub_whole words.py
replace whole words in a text using Python module re
and a dictionary of key_word:replace_with pairs

tested with Python273  ZZ
'''

import re

def word_replace(text, replace_dict):
    '''
    Replace words in a text that match a key in replace_dict
    with the associated value, return the modified text.
    Only whole words are replaced.
    Note that replacement is case sensitive, but attached
    quotes and punctuation marks are neutral.
    '''
    rc = re.compile(r"[A-Za-z_]\w*")
    def translate(match):
        word = match.group(0)
        return replace_dict.get(word, word)
    return rc.sub(translate, text)

old_text = """\
In this text 'debug' will be changed but not 'debugger'.
Similarly red will be replaced but not reduce.
How about Fred, -red- and red?
Red, white and blue shipped a ship!"""

# create a dictionary of key_word:replace_with pairs
replace_dict = {
"red" : "redish",
"debug" : "fix",
'ship': 'boat'
}

new_text = word_replace(old_text, replace_dict)

print(old_text)
print('-'*60)
print(new_text)

''' my output -->
In this text 'debug' will be changed but not 'debugger'.
Similarly red will be replaced but not reduce.
How about Fred, -red- and red?
Red, white and blue shipped a ship!
------------------------------------------------------------
In this text 'fix' will be changed but not 'debugger'.
Similarly redish will be replaced but not reduce.
How about Fred, -redish- and redish?
Red, white and blue shipped a boat!
'''
ZZucker 342 Practically a Master Poster

Java has been around for about 20 years and they still correct their bugs about every week.

ZZucker 342 Practically a Master Poster

I am unhappy to report that Python 3.3.1 still comes with the Tkinter Filedialog bug.
Could be a bug introduced by the Windows OS?
Looking in
C:\Python33\tcl\tk8.5
is the highest version listed

ZZucker 342 Practically a Master Poster

Implement the Comb Sort algorithm in Python code.
See:
http://en.wikipedia.org/wiki/Comb_sort

ZZucker 342 Practically a Master Poster

Thanks for the info, I have to look into Pillow replacing PIL for Python33.

ZZucker 342 Practically a Master Poster

Why not, as long as they don't ask you wear snowshoes.

ZZucker 342 Practically a Master Poster

This is my simple religion. There is no need for temples; no need for complicated philosophy. Our own brain, our own heart is our temple; the philosophy is kindness.
=== Dalai Lama

Reverend Jim commented: One of my favourites. +0
ZZucker 342 Practically a Master Poster
ZZucker 342 Practically a Master Poster

The Python3 str.format() method has been backported to Python 2.6.

See
http://docs.python.org/2.6/library/stdtypes.html
http://docs.python.org/2.6/whatsnew/2.6.html
and
PEP 3101

Even with Python33 you can still use the % specifier:

import sys
for key in sys.modules.keys():
    print("hello from %s" % key)
ZZucker 342 Practically a Master Poster

I think the problem is:
isnumeric for what purpose?

ZZucker 342 Practically a Master Poster

You need to save your updates and a dictionary is ideal to do this with. Python has module shelve to make a 'persistent to file' dictionary automatically. Very powerful stuff indeed!

ZZucker 342 Practically a Master Poster

Convert the json string object to a Python dictionary and look at the dictionary keys.

ZZucker 342 Practically a Master Poster

Write a Python program that finds the smallest number that can be divided by each of the numbers from 1 to 10 without leaving a remainder.

ZZucker 342 Practically a Master Poster

print(not None)

ZZucker 342 Practically a Master Poster

The Miller-Urey experiment in 1953 raised the possibility that lightning may have been a key to the origin of life on Earth.

ZZucker 342 Practically a Master Poster

Being from California I am rooting for the 49ers. I really like the halftime show!

ZZucker 342 Practically a Master Poster

Thank y'all!
I studied up a little and came to these insights:

   NB. a simple 3 by 4 array ...
   array34 =: i. 3 4

   array34
0 1  2  3
4 5  6  7
8 9 10 11

   NB. this sums up each column
   +/ array34
12 15 18 21

   NB. link (;) box values original array34 (,.) and summed up (+/)
   box_vertical =: ,. @; +/
   box_horizontal =: ,. ; +/

   box_vertical array34
┌───────────┐
│0 1  2  3  │
│4 5  6  7  │
│8 9 10 11  │
├───────────┤
│12 15 18 21│
└───────────┘

   box_horizontal array34
┌─────────┬───────────┐
│0 1  2  3│12 15 18 21│
│4 5  6  7│           │
│8 9 10 11│           │
└─────────┴───────────┘
ZZucker 342 Practically a Master Poster

I am exploring the J language for scientific purposes and am running this Fibonacci number code. Does anyone know how to add up the values in each of the four columns?

   NB. Fibo101.ijs
   NB. Fibonacci numbers
   NB. using J language free from www.jsoftware.com

   NB. F creates a list of the first 64 Fibonacci numbers
   F =: ((, [: +/_2&{.)^:62)0 1x

   NB. Show the numbers arranged in 4 columns
   _4 [\ F  
            0             1             1             2
            3             5             8            13
           21            34            55            89
          144           233           377           610
          987          1597          2584          4181
         6765         10946         17711         28657
        46368         75025        121393        196418
       317811        514229        832040       1346269
      2178309       3524578       5702887       9227465
     14930352      24157817      39088169      63245986
    102334155     165580141     267914296     433494437
    701408733    1134903170    1836311903    2971215073
   4807526976    7778742049   12586269025   20365011074
  32951280099   53316291173   86267571272  139583862445
 225851433717  365435296162  591286729879  956722026041
1548008755920 2504730781961 4052739537881 6557470319842
ZZucker 342 Practically a Master Poster

C++ is an easy language.

ZZucker 342 Practically a Master Poster

However, when Java is promoted as the sole programming language, its flaws and limitations become serious.
--- Bjarne Stroustrup

ZZucker 342 Practically a Master Poster

I like the SharpDevelop IDE very useful for C# and IronPython.

With Java having all those security issues right now, I am reluctant to use software like Eclipse or Netbeans.

ZZucker 342 Practically a Master Poster

Java (not the drink) is responsible for 50 percent of all cyberattacks last year, followed by Adobe software with 28 percent. Microsoft software is only 3 percent.

Oracle is considered to do a poor job with Java security issues.

ZZucker 342 Practically a Master Poster

Not sure if QMainWindow accepts absolute layout?

ZZucker 342 Practically a Master Poster

Holy smokes woooee, this person has been a busy little beaver.
All this because he/she confuses thousands with hundreths of a second.

ZZucker 342 Practically a Master Poster

Thanks everybody!

ZZucker 342 Practically a Master Poster

Look at something like
PIL.pth
the PIL package directory and it's
__init__.py file

ZZucker 342 Practically a Master Poster

vegaseat, this must be the commented out test version
replace
#@Memoize
with
@Memoize
to get the working version

ZZucker 342 Practically a Master Poster

The lowest paying jobs in the USA are amongst
food preparation and serving workers (including fast food)

ZZucker 342 Practically a Master Poster

A decorator can be used to check a function's requirements:

''' require_decorator1.py
creating a general safe decorator
a safe decorator can be combined with other decorators
py2 and py3 tested on http://ideone.com/SPkbev
'''

def require(expr):
    """a general decorator checking args requirement"""
    def decorator(func):
        def wrapper(*__args,**__kw):
            message = "failed precondition %s" % expr
            assert eval(expr), message
            return func(*__args,**__kw)
        # optional next 3 lines make decorator safe
        wrapper.__name__ = func.__name__
        wrapper.__dict__ = func.__dict__
        wrapper.__doc__ = func.__doc__
        return wrapper
    return decorator

# allows only 1 argument here
@require("len(__args)==1")
def test(*args):
    print(args[0])

# no problem, prints Hello world!
test("Hello world!")

print('-'*50)

# has 2 arguments and will fail showing 
# AssertionError: failed precondition len(__args)==1
test("Hello", "World")
ZZucker 342 Practically a Master Poster

Santa just brought me a fancy notebook computer and I want to know if anyone has some experiemce with accessing that little camera with Python code?

ZZucker 342 Practically a Master Poster

"Dive Into Python" Mark Pilgrim's Free online book, novice to pro, is updated constantly, and has been rewritten for Python3
http://getpython3.com/diveintopython3/
check appendix A for Py2-to-Py3 differences!

Also check:
http://www.swaroopch.com/notes/Python

Google Python video series:
http://code.google.com/edu/languages/index.html#_python_understanding

ZZucker 342 Practically a Master Poster

Slate is right, a little test print within the function allows you to follow what is going on:

def f(x, y):
    print(x, y)  # test print to check progress
    if y == 0:
        return x
    else:
        return f(y, x%y)

print(f(240, 150))

Or:

num = 0
for i in range(0,10,1):
    if (i%2 == i%3):
        num = num + 1
    print(i%2, i%3, num)  # test print to check progress

print(num)

Later you can comment out the test print when done.

ZZucker 342 Practically a Master Poster

One more stone turned:

import collections
import random

# values are integers
ddict = collections.defaultdict(int)
for k in range(100):
    n = random.randint(0, 10)
    ddict[n] += 1

print(ddict[3])