Gribouillis 1,391 Programming Explorer Team Colleague

If I were you, I would try the boot-repair disk. It always repaired my broken boots in one click. Unfortunately, sourceforge is currently down, and I'm not sure you can download the disk.

Edit: if you have a live ubuntu disk, you can run boot-repair as explained here.

Gribouillis 1,391 Programming Explorer Team Colleague

I don't know Runestone Interactive. About languages, my personal opinion is that you are wasting your time learning perl at the same time as python. Both languages can be used for the same tasks and you will end up not using perl because it is older and harder to use than python. There are many languages to learn. You could learn php to start web development.

Gribouillis 1,391 Programming Explorer Team Colleague

A regex to match more than 1 space character is

r' {2,}'

To match a dot followed by a letter without consuming the letter, you can use

r'\.(?=[a-zA-Z])'

Always use raw strings(r'...') with regexes, in order to preserve \ characters.

Gribouillis 1,391 Programming Explorer Team Colleague

Ooops! My great solution uses 'in' :). Fortunately, we have map()

def is_member(x, a):
    return any(map(lambda item: item == x, a))
Gribouillis 1,391 Programming Explorer Team Colleague

You can avoid many calls to print() by printing multiline strings such as

banner = '''
  _____           ____             
 |  ___|__   ___ | __ )  __ _ _ __ 
 | |_ / _ \ / _ \|  _ \ / _` | '__|
 |  _| (_) | (_) | |_) | (_| | |   
 |_|  \___/ \___/|____/ \__,_|_|   

 a program by John Doe
 ---------------------
 '''.strip('\n')

print(banner)

Also I think it is better to catch KeyboardInterrupt than to define a signal handler for SIGINT. Python already catches the signal. You can do

def main():
    print(banner)
    uinput = input("Letters: ")
    if uinput != "":
        run(uinput)
    else:
        print("Error in validation; please restart.")

if __name__ == '__main__':
    try:
        main()
    except KeyboardInterrupt:
        print('\n\nGoodbye. :)')

You could avoid the version check at the top of the program if it is not strictly necessary: people may have older versions of python, don't sys.exit() them immediately.

Gribouillis 1,391 Programming Explorer Team Colleague

Another solution, using the any() builtin function

def is_member(x, a):
    return any(item == x for item in a)
Gribouillis 1,391 Programming Explorer Team Colleague

In ubuntu there is a package python-enum34 for this, together with 3 other enum packages for python.

Gribouillis 1,391 Programming Explorer Team Colleague

I think you could add a launcher to the explorer's context menu by following this tutorial.

Gribouillis 1,391 Programming Explorer Team Colleague

You must indent line 50 to 89 (they belong to the while loop) and you must probably change raspberry[1] at line 79 with raspberryPosition[1].

Gribouillis 1,391 Programming Explorer Team Colleague

Python says 5.16294852309750916500022794327 e287193 and 6.74114012549907340226906510470 e315652. For example

Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from scipy.misc import factorial
>>> x = factorial(65536, exact=True)
>>> s = str(x)
>>> s[-1]
'0'
>>> s[:30]
'516294852309750916500022794327'
>>> len(s)
287194
>>> 
>>> x = 65536 ** 65536
>>> s = str(x)
>>> s[-1]
'6'
>>> s[:30]
'674114012549907340226906510470'
>>> len(s)
315653
Gribouillis 1,391 Programming Explorer Team Colleague

Apparently, there is a fuzzy logic toolbox for Scilab as these links tend to prove

Scilab is free software under CeCILL license and it is very close to Matlab. There is also a python module called sciscipy to connect python to scilab.

Apart from this, a search with the keyword fuzzy in the python package index (pypi) yields various modules purporting to be fuzzy logic modules. Did you see them ?

Gribouillis 1,391 Programming Explorer Team Colleague

I don't know ESX, but in principle, if you can describe precisely how to do it manually, python should be able to do it.

Gribouillis 1,391 Programming Explorer Team Colleague

I have a running version for scilab here. I didn't check that the numerical result is good however

clear;
function func = foo(z, x)
    func = ((0.6369).*sin(z.*sin(x)).*sin(x))
endfunction

function simpson = simpson(f, a, b, n)
h  = (b-a)/n;
i   = 0;
fks = 0.0;
while (i<=n)
    xk = a+i*h;
    if i==or(0, n) then
        fk = f(xk);
    elseif (i-fix(i./2).*2)== 1 then
        // https://help.scilab.org/docs/5.5.0/en_US/m2sci_rem.html
        fk = 4.*f(xk);
    else
        fk = 2.*f(xk);
    end
    fks = fks + fk;
    i = i + 1;
end
simpson = (h./3).*fks;
endfunction

function func = baz(x)
    func = foo(1, x)
endfunction

simpson(baz, 0, 1.57, 10)
Gribouillis 1,391 Programming Explorer Team Colleague

Yes he is one of the knights on the Bayeux tapestry, a very good friend of William the Conqueror.

Gribouillis 1,391 Programming Explorer Team Colleague

I want to print for each title outside of the loop.

This is meaningless. It does not matter if the titles are printed inside or outside of the loop (which loop ? why ?) as long as the program prints the correct output. Change your priorities: first the program must work as expected, then the secondary details.

Gribouillis 1,391 Programming Explorer Team Colleague

Hm the documentation speaks about the tk clipboard, which is probably different from the system clipboard. Your code works for me, but I can't use it to paste something into an external window, such as firefox. It doesn't copy anything to the system clipboard.

Gribouillis 1,391 Programming Explorer Team Colleague

It is interesting although I cannot make it work in linux with KDE. However, a search for clipboard in pypi yields a number of results. Among them, pyperclip looks promising. Which is the best module for clipboard access ?

Gribouillis 1,391 Programming Explorer Team Colleague

I bought three Acer Aspire laptops with i7 and i5 processors. They were sold with windows 8, which I replaced with kubuntu 64 bits and they work very well.

Gribouillis 1,391 Programming Explorer Team Colleague

I use one password for all my internet accounts , it is a sentence consisting of 6 words ( english + persian ) which reminds me of my college girlfriend .

Reusing a password is unsafe. Suppose you have an account in an online store with a primitive and unsafe website, your password can easily be stolen together with your email address or other personal data, then tried in more critical sites.

It happens. In my town, a pizza place had all its user data stolen. Fortunately I had a different password for my wuala account.

Gribouillis 1,391 Programming Explorer Team Colleague

It works in 2 clicks, with a temporary copy and paste.

Gribouillis 1,391 Programming Explorer Team Colleague

@slavi Using a password manager, you can easily have unique random uncrackable passwords with more than 20 characters. The only password you need to remember is the password manager's password. I don't know any of my passwords but one or two, and I have many accounts, each with an impossible password. I can also very easily change them when the news say that 1.2 billion passwords have been stolen.

Gribouillis 1,391 Programming Explorer Team Colleague

You can create a list of numbers

>>> L = range(4128, 4616)
>>> L = [x for x in L if (x-4128) % 70 != 69]
>>> L
[4128, 4129, 4130, 4131, 4132, 4133, 4134, 4135, 4136, 4137, 4138, 4139, 4140, 4141, 4142, 4143, 4144, 4145, 4146, 4147, 4148, 4149, 4150, 4151, 4152, 4153, 4154, 4155, 4156, 4157, 4158, 4159, 4160, 4161, 4162, 4163, 4164, 4165, 4166, 4167, 4168, 4169, 4170, 4171, 4172, 4173, 4174, 4175, 4176, 4177, 4178, 4179, 4180, 4181, 4182, 4183, 4184, 4185, 4186, 4187, 4188, 4189, 4190, 4191, 4192, 4193, 4194, 4195, 4196, 4198, 4199, 4200, 4201, 4202, 4203, 4204, 4205, 4206, 4207, 4208, 4209, 4210, 4211, 4212, 4213, 4214, 4215, 4216, 4217, 4218, 4219, 4220, 4221, 4222, 4223, 4224, 4225, 4226, 4227, 4228, 4229, 4230, 4231, 4232, 4233, 4234, 4235, 4236, 4237, 4238, 4239, 4240, 4241, 4242, 4243, 4244, 4245, 4246, 4247, 4248, 4249, 4250, 4251, 4252, 4253, 4254, 4255, 4256, 4257, 4258, 4259, 4260, 4261, 4262, 4263, 4264, 4265, 4266, 4268, 4269,...]
Gribouillis 1,391 Programming Explorer Team Colleague

In CPython, Socket.recv() is implemented by calling the C function

ssize_t recv(int sockfd, void *buf, size_t len, int flags);

You can see this by downloading the python source code and looking into socketmodule.c, or online here. Before calling the C function, python allocates a buffer which capacity is bufsize (4096 in your case).

The documentation says

The maximum amount of data to be received at once is specified by bufsize

It means that a single call can not receive more than 4096 bytes at a time and you need to make a loop to read more.

It may look strange, but the socket module is a low level module and its main purpose is to make the C socket api available to python programs.

Gribouillis 1,391 Programming Explorer Team Colleague

Ok, a while loop should do the trick

def space_to_tab(work_string):
    """Replace spaces with tab at the beginning of each line of a text
    """
    result = []
    s_to_tab = 4
    space = REAL_SPACE * s_to_tab
    for line in work_string.split('\n'):
        rest = line.lstrip()
        white = line[:len(line) - len(rest)]
        white = white.replace(space, REAL_TAB).lstrip(REAL_SPACE)
        result.append(white + rest)
    return '\n'.join(result)
Gribouillis 1,391 Programming Explorer Team Colleague

You can make it a helper function for a function which acts on a full text:

def _space_to_tab(work_string):
    """Replace spaces with tab at the beginning of a line of text
    """
    s_to_tab = 4

    whitespace = work_string[ : len(work_string) - len(work_string.lstrip())]
    whitespace = whitespace.replace(REAL_SPACE * s_to_tab, REAL_TAB)
    whitespace = whitespace.lstrip(REAL_SPACE)
    result = whitespace + (work_string.lstrip())
    return result

def space_to_tab(work_string):
    """Replace spaces with tab at the beginning of each line of a text
    """
    lines = work_string.split('\n')
    lines = (_space_to_tab(line) for line in lines)
    return '\n'.join(lines)
Gribouillis 1,391 Programming Explorer Team Colleague

Because your home directory is /home/weber. If you want the other path, use

os.path.join(os.path.expanduser('~'), 'jbwrk', 'xsend.py')

However, I think /home/weber/.xsend was probably meant. It may be a configuration file or directory. Try

ls -a ~

to see if there is a .xsend in your home directory.

Gribouillis 1,391 Programming Explorer Team Colleague

I have 2 Toyotas: a Prius, great great great hybrid car ! and an Aygo.

Gribouillis 1,391 Programming Explorer Team Colleague

Sometimes there are errors in a postscript or pdf document. There are several things you can try. If you can open the document with several programs, it may print with one of these programs and not with another. For example a pdf may print from a qpdfview window but not from an okular window.

Another thing you can try is to install a pdf printer. In ubuntu, it is done with

sudo apt-get install cups-pdf

You can then select the pdf printer when you want to print a document. It will create a pdf file in a folder (probably ~/PDF), then you can open this pdf with say qpdfview and try to print again with your printer.

Gribouillis 1,391 Programming Explorer Team Colleague

If you do >>> help(chr) in python 3, you get

Help on built-in function chr in module builtins:

chr(...)
    chr(i) -> Unicode character

    Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff.

Now we can get a set of numbers with

>>> s = [i for i in range(0x10ffff) if unicodedata.category(chr(i)) == 'Lu']
>>> len(s)
1441
>>> s
[65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 216, 217, 218, 219, 220, 221, 222, 256, 258, 260, 262, 264, 266, 268, 270, 272, 274, 276, 278, 280, 282, 284, 286, 288, 290, 292, 294, 296, 298, 300, 302, 304, 306, 308, 310,...]
Gribouillis 1,391 Programming Explorer Team Colleague

This program may help

# -*-coding: utf8-*-

__doc__ = '''
'''

import sys

S4 = " " * 4

def main():
    while True:
        line = sys.stdin.readline()
        if not line:
            break
        result = line.replace('\t', S4)
        print(result, end='')

if __name__ == '__main__':
    main()
Gribouillis 1,391 Programming Explorer Team Colleague

Start with

Write a program that asks the user to enter a series of 20 numbers.

then post your code in this thread :)

Gribouillis 1,391 Programming Explorer Team Colleague

Try

sudo apt-get install trash-cli

It works for me in kde, providing commands

trash-put
trash-empty
trash-list
restore-trash

See Click Here.

Gribouillis 1,391 Programming Explorer Team Colleague

Goodbye Ancient Dragon, RIP.

Gribouillis 1,391 Programming Explorer Team Colleague

Don't print directly, use strings operations to create new strings with your data instead, for example

>>> args = (1,2,3,4)
>>> L = [str(n) for n in args]
>>> L
['1', '2', '3', '4']
>>> s = '+'.join(L)
>>> s
'1+2+3+4'
Gribouillis 1,391 Programming Explorer Team Colleague

When python says invalid syntax, it shows a point in code near the point where there is an error

File "foo.py", line 11
    print("Therefore, your total shipping charge would be " total)
                                                                ^
SyntaxError: invalid syntax

If you look at your code at line 11, you will see the error. Conclusion: take the time to analyse python's error messages. You can also post these error messages in the forum. They are very useful for helpers.

Gribouillis 1,391 Programming Explorer Team Colleague

I have a fast function in this snippet click here.

Gribouillis 1,391 Programming Explorer Team Colleague

Note that there may be some more trouble if the database contains '29-FEB-00' because 2000 is a leap year, and not 1900.

Gribouillis 1,391 Programming Explorer Team Colleague

If you want to round the number for printed output, the correct way is to use string formatting operations. Click here to see some examples.

Gribouillis 1,391 Programming Explorer Team Colleague

The main drawback of ipython's notebook is its limited editing capabilities. A web browser is far from being as responsive as an IDE and most code editing features are missing.

Gribouillis 1,391 Programming Explorer Team Colleague

Think about where you are going to insert op if the phrase is street. You are going to insert op when you meet the first e, because it is not a consonant and the previous letter is a consonant. You are also going to insert op at the end of the string because the previous letter is a consonnant. So, an algorithm would go this way, in pseudo-code.

previous_is_a_consonant = False
for letter in phrase:
    if letter is a consonant:
        previous_is_a_consonant = True
    else:
        if previous_is_a_consonant:
            append 'op'
        previous_is_a_consonant = False
    append letter
if previous_is_a_consonant:
    append 'op'
Gribouillis 1,391 Programming Explorer Team Colleague

The test line is not safe. Here is my result

$ env x='() { :;}; echo vulnerable' bash -c "start patching now"
vulnerable
start: Tâche inconnue : patching

Tâche inconnue means unknown task. So bash echoed vulnerable and then tried to run the start command. On my system, /sbin/start is a symlink to the initctl command. Fortunately, initctl does not know the subcommand patching and it aborted.

Edit: After running the update manager, bash now says that it ignores the function definition attempt. It means that the bug has been corrected today for kubuntu 14.04.

Gribouillis 1,391 Programming Explorer Team Colleague

The definition of the assignment statement is click here in the docs. As you can see, the left part of it can be a sequence of targets separated by commas. In this case, the right side must be a sequence of expression matching the left side. For example, the left side can be a sequence of identifiers (names) as in

>>> u, v, w = [1, 2, 3]

or something more complicated, such as

>>> x, ((y, z), t) = [1, ([2,3], 4)]
>>> x, y, z, t
(1, 2, 3, 4)

or even, in recent versions of python:

>>> x, *foo, y = (1, 2, 3, 4, 5, 6)
>>> foo
[2, 3, 4, 5]

In your case, the program works if the script is invoked with a single argument (the filename).

Gribouillis 1,391 Programming Explorer Team Colleague

You only need to start all the jobs before you call out_q.get().

Gribouillis 1,391 Programming Explorer Team Colleague

The following code works for me

#!/usr/bin/env python
# -*-coding: utf8-*-
# ./main.py
from multiprocessing import Process, Queue
from subprocess import Popen, PIPE

def runJob(out_q):
    p1 = Popen(['./jobexe','job_to_run'], stdout=PIPE)
    out, err = p1.communicate()
    out_q.put((p1.returncode, out))

out_q= Queue()
outlst=[]
proc = Process(target=runJob, args=(out_q,))
proc.start()
outlst.append(out_q.get())
proc.join()
print(outlst)

I used this jobexe program

#!/usr/bin/env python
# -*-coding: utf8-*-
# jobexe

if __name__ == '__main__':
    import sys
    print(sys.argv)

Did you by any chance import Queue from Queue instead of importing it from multiprocessing ? This would block.

Your argument with communicate() does not hold water because the child process calls communicate (the process which runs runJob()). This does not prevent the main process from starting new children.

If jobexe outputs a lot of data, then it makes sense to write a loop to read the output and write it to a file instead of using communicate().

Gribouillis 1,391 Programming Explorer Team Colleague

The conversion specifier is not the single character %. It has 7 components, most of them optional, as described in the documentation: click here.

So, for example %s and %d are valid conversion specifiers.

Gribouillis 1,391 Programming Explorer Team Colleague

Your installer is not executable. Run

chmod a+x xampp*
ls -l xampp*

In linux one uses ls instead of dir. You should see

-rwxr-xr-x 1 rik rik 124487989 aug  30 18:58 xampp-linux-x64-1.8.3-5-installer.run
Gribouillis 1,391 Programming Explorer Team Colleague

Great! let us know if PyUserInput suits your needs.

Gribouillis 1,391 Programming Explorer Team Colleague

In ubuntu one uses apt-get instead of yum.

Gribouillis 1,391 Programming Explorer Team Colleague

You need to install setuptools. Follow these instructions.

Gribouillis 1,391 Programming Explorer Team Colleague

Sorry, the folder must be added to PATH (provided there is a file C:\Python33\Scripts\pip.exe)