Is that an error in Python tutorial?

How we can improve TutorialsPoint.com
no avatar
Paniov
 
Posts: 1
Joined: Sat May 14, 2011 2:07 am

Is that an error in Python tutorial?

by Paniov » Sat May 14, 2011 2:25 am

Hi, I like it your Python tutorial! Thanks, it is really good. But I think you did mistake on this page http://www.tutorialspoint.com/python/python_loop_control.htm. Check example of The continue Statement, I guess this part of code should be like this:
Code: Select all
var = 10                    # Second Example
while var > 0:
   var = var - 1
   if var == 5:
      continue
   print 'Current variable value :', var;

And of course it will affect the result of it, where number 5 will not be printed.

Am I correct? ))

no avatar
tutorialspoint
Site Admin
 
Posts: 144
Joined: Fri Apr 27, 2007 6:52 pm

by tutorialspoint » Tue May 17, 2011 3:16 am

Thanks Paniov, I have fixed it.

no avatar
LouieInSeattle
 
Posts: 1
Joined: Tue Aug 09, 2011 6:02 am

Missing argument in example

by LouieInSeattle » Tue Aug 09, 2011 6:06 am

on page http://www.tutorialspoint.com/python/st ... etrans.htm
the str.translate example only has one argument: trantab.
It should have two: the line it is working on, and trantab e.g. str.translate(line,trantab)

no avatar
tutorialspoint
Site Admin
 
Posts: 144
Joined: Fri Apr 27, 2007 6:52 pm

by tutorialspoint » Wed Aug 10, 2011 4:28 am

Pls try given example and I'm sure it will work.

!/usr/bin/python

from string import maketrans # Required to call maketrans function.

intab = "aeiou"
outtab = "12345"
trantab = maketrans(intab, outtab)

str = "this is string example....wow!!!";
print str.translate(trantab);

no avatar
Sn00kumS
 
Posts: 2
Joined: Thu Sep 29, 2011 6:57 pm

Multithreading

by Sn00kumS » Thu Sep 29, 2011 7:05 pm

Hi,

could it be that one needs a specific version of python or some optional modules for every examples to work?
I ask because the Mutlithreading with queues doesn't seem to work for me
Code: Select all
#!/usr/bin/python

import Queue
import threading
import time

exitFlag = 0

class myThread (threading.Thread):
    def __init__(self, threadID, name, q):
        self.threadID = threadID
        self.name = name
        self.q = q
        threading.Thread.__init__(self)
    def run(self):
        print "Starting " + self.name
        process_data(self.name, self.q)
        print "Exiting " + self.name

def process_data(threadName, q):
    while not exitFlag:
        queueLock.acquire()
        if not workQueue.empty():
            data = q.get()
            queueLock.release()
            print "%s processing %s" % (threadName, data)
        else:
            queueLock.release()
        time.sleep(1)

threadList = ["Thread-1", "Thread-2", "Thread-3"]
nameList = ["One", "Two", "Three", "Four", "Five"]
queueLock = threading.Lock()
workQueue = Queue.Queue(10)
threads = []
threadID = 1

# Create new threads
for tName in threadList:
    thread = myThread(threadID, tName, workQueue)
    thread.start()
    threads.append(thread)
    threadID += 1

# Fill the queue
queueLock.acquire()
for word in nameList:
    workQueue.put(word)
queueLock.release()

# Wait for queue to empty
while not workQueue.empty():
    pass

# Notify threads it's time to exit
exitFlag = 1

# Wait for all threads to complete
for t in threads:
    t.join()
print "Exiting Main Thread"


I just wanted to test it (I'm not really familiar with python yet.) But all I got was:

Code: Select all
Traceback (most recent call last):
  File "threads.py", line 40, in <module>
    thread = myThread(threadID, tName, workQueue)
  File "threads.py", line 12, in __init__
    self.name = name
  File "/usr/lib/python2.7/threading.py", line 689, in name
    assert self.__initialized, "Thread.__init__() not called"
AssertionError: Thread.__init__() not called


I'm working on Ubuntu 11.04 with the newest version of Python from the repositories.

regards Sn00kumS

no avatar
Sn00kumS
 
Posts: 2
Joined: Thu Sep 29, 2011 6:57 pm

by Sn00kumS » Tue Oct 25, 2011 9:01 pm

Ok I found a solution via our best friend Google!

http://www.velocityreviews.com/forums/t ... ading.html

It seems that the Subclass is a little bit mixed up. Like KevinSimpson in the above Forum states:

"If the subclass overrides the constructor, it must make sure to
invoke the base class constructor (Thread.__init__()) before doing
anything else to the thread."

So the Code has to be changed so that

Code: Select all
threading.Thread.__init__(self)


is called before one defines

Code: Select all
        self.threadID = threadID
        self.name = name
        self.q = q

no avatar
princelee1019
 
Posts: 2
Joined: Tue Mar 12, 2013 7:43 pm

Re: Is that an error in Python tutorial?

by princelee1019 » Tue Mar 12, 2013 7:56 pm

It should have two: the line it is working on, and trantab e.g. str.translate(line,trantab)
3D Wallpapers 3D Wallpapers
beautiful endangered species beautiful endangered species
albino animals albino animals
cool wine label designs creative and cool wine label designs
origami artists amazing master origami artists

Return to Suggestions

cron