Gribouillis 1,391 Programming Explorer Team Colleague

You don't need a terminal if you burn the disk from here http://sourceforge.net/projects/boot-repair-cd/files/

Gribouillis 1,391 Programming Explorer Team Colleague

What does the boot-repair disk say ?

Gribouillis 1,391 Programming Explorer Team Colleague

We don't know what n is. The easiest way is to make it an attribute of a TheShuttles instance.

class TheShuttles:
    def __init__(self):
        self.n = 0

    def getLeastCost(self, baseCost, seatCost, cnt):
        def cost(x):
            self.n = sum(m / x + (m % x != 0 ) for m in cnt)
            return self.n * (baseCost + x * seatCost)
        return min(cost(x) for x in range(1, 101))

Also, the cost function could be a method of class TheShuttle instead of a function inside a function, it would be easier to understand. Type import this in a python console for good advice.

Configure your code editor to indent python code with 4 spaces, and read PEP8 for help on coding style.

EDIT: In python 2, make sure to declare a superclass, use object if necessary:

class TheShuttles(object):
    ...

In python 3, this is not needed. If you are new to python, start with python 3.

Gribouillis 1,391 Programming Explorer Team Colleague

The if condition looks if the dictionary tm contains a key which is a tuple of length 1 containing the word as sole item. If it does not, a value is associated to this key in this dictionary.

It seems strange to me that you don't work with unicode strings instead of utf8-encoded strings. For exemple in python 2:

>>> s = 'pass\xc3\xa9'
>>> t = s.decode('utf8')
>>> print(t)
passé
>>> print(repr(t))
u'pass\xe9'
Gribouillis 1,391 Programming Explorer Team Colleague

It is not the right output. Consider the following example

>>> from binascii import unhexlify
>>> s = "f0"
>>> A = unhexlify(s)
>>> B = r"\x" + r"\x".join(s[n : n+2] for n in range(0, len(s), 2))
>>> print(A)
�
>>> print(B)
\xf0
>>> print(repr(A))
'\xf0'
>>> print(repr(B))
'\\xf0'
>>> print(len(A))
1
>>> print(len(B))
4

The string A constructed with unhexlify() contains a single byte, which is '\xf0', or the 8 bits 11110000 (it does not print well in a terminal because it is not a printable character). String B constructed with vegaseat's expression contains 4 bytes, namely the characters \, x, f, 0. Its bitwise representation is 01011100011110000110011000110000.

See this post https://www.daniweb.com/software-development/python/code/221031/string-to-bits#post1484218 for bit representations of byte strings.

Edit: are you the blog's author ?

Gribouillis 1,391 Programming Explorer Team Colleague

Vegaseat's method does not work. It gives another string:

  '\\xf0\\xcb\\xf2\\x60\\xe0\\xca\\x8e\\xc2\\x43\\x10\\x89\\xfb\\x39\\x3a\\x1c\\x29\\x51\\x3a\\xaa\\xa5\\x84\\x7d\\x13\\xe8\\xbe\\x84\\x76\\x09\\x68\\xe6\\x4d\\xc6'
Gribouillis 1,391 Programming Explorer Team Colleague

Sequences such as \xf0 represent a single byte (8 bits. Remark: in python 3, use b'\xf0').

Some bytes are better viewed as ascii characters. For example 'Q' and '\x51' are the same character. In fact, 'Q' is the character number 81 in ascii, and 81 rewritten in hexadecimal system is 51, (5*16 + 1). See https://en.wikipedia.org/wiki/ASCII .

Python displays printable characters in ascii form and other characters in hex form.

Edit: some special characters are escaped too, '\t' is a tabulation character (number 9, or '\x09').

Gribouillis 1,391 Programming Explorer Team Colleague

Hi. Use module binascii

>>> from binascii import unhexlify
>>> s = 'f0cbf260e0ca8ec2431089fb393a1c29513aaaa5847d13e8be84760968e64dc6'
>>> t = unhexlify(s)
>>> t
'\xf0\xcb\xf2`\xe0\xca\x8e\xc2C\x10\x89\xfb9:\x1c)Q:\xaa\xa5\x84}\x13\xe8\xbe\x84v\th\xe6M\xc6'
Gribouillis 1,391 Programming Explorer Team Colleague

The while True loop runs forever unless it contains a break or return statement, or an exception is raised. It means that your code repeats indefinitely the statement whichcode = 1. This is probably not what you meant. Why do you need the while loop ?

Gribouillis 1,391 Programming Explorer Team Colleague

There are many syntax errors in your code. The documentation explains the syntax of the for statement https://docs.python.org/3/reference/compound_stmts.html#the-for-statement

Schematically it is

for SPAM in HAM:
    EGGS

of course, HAM must support the in operator (so do lists, dicts and tuples for example)

Gribouillis 1,391 Programming Explorer Team Colleague

Here is the basic idea

#!/usr/bin/env python
# -*-coding: utf8-*-
'''doc
'''
from __future__ import (absolute_import, division,
                        print_function, unicode_literals)

import numpy as np
from scipy.optimize import linprog

def main():
    point = np.array([0.8, 0.12, 0.4])
    n = len(point)
    N = 30
    a = np.random.rand(n, N)
    a = np.insert(a, n, 1.0, axis=0)
    b = np.append(point, 1.0).reshape(n+1,1)
    bounds = [(0.0, 1.0) for i in range(N)]
    c = np.zeros(N)
    c[0] = 1.0
    print(a)
    print(b)
    print(c)
    result = linprog(c, A_eq=a, b_eq=b, bounds=bounds)
    print(result)
    if result.status == 0:
        print('Point is in convex hull')
    else:
        print('Point is not in convex hull')

if __name__ == '__main__':
    main()

""" my output -->
17:31 2015-03-31] python convex.py
[[ 0.26366509  0.92411732  0.9081528   0.88461942  0.68029591  0.42997518
   0.17189674  0.07542255  0.6627228   0.46370079  0.29521928  0.50230071
   0.73392039  0.70076308  0.39031932  0.73670852  0.64815496  0.52975825
   0.78314098  0.60898234  0.63308929  0.32659967  0.02298467  0.17494737
   0.01397131  0.27248117  0.98193604  0.69879033  0.90454457  0.06127812]
 [ 0.16418386  0.05802131  0.07673203  0.50894301  0.45885838  0.13100915
   0.43334997  0.3613589   0.70104947  0.47547909  0.64204601  0.18567562
   0.07257718  0.49943999  0.96490179  0.16901995  0.14288372  0.55158995
   0.12849092  0.4287121   0.33522966  0.32258957  0.54137264  0.24533261
   0.26382428  0.35957173  0.45413843  0.96331716  0.41831803  0.34442463]
 [ 0.77288019  0.04946268  0.00280707  0.07217767  0.62230434  0.97351116
   0.78616099  0.74724063  0.35259706  0.82299753  0.8465832   0.7326628
   0.65494121  0.88904928  0.67263953  0.23434955  0.74143111  0.4536738
   0.81357322  0.7408426   0.52483849  0.44427614  0.75840825  0.04656877
   0.84187546  0.94461097  0.42198365  0.20315269  0.21713841  0.29179429]
 [ 1.          1.          1.          1.          1.          1.          1.
   1.          1.          1.          1.          1.          1.          1.
   1.          1.          1.          1.          1.          1.          1.
   1.          1.          1.          1.          1.          1.          1.
   1.          1.        ]]
[[ 0.8 ]
 [ 0.12]
 [ 0.4 ]
 [ 1.  ]]
[ 1.  0.  0.  0.  0. …
fatalaccidents commented: This is the basic logic that I used, although I used scipy.spatial.ConvexHull because my anaconda distribution doesn't seem to have linprog (?) +2
Gribouillis 1,391 Programming Explorer Team Colleague

It seems to me that this question is solvable by linear programming. The function scipy.optimize.linprog() should work with convenient parameters.

Gribouillis 1,391 Programming Explorer Team Colleague

You can use tuples of integers to store the dice results, for example

attacking_values = (random.randint(1,6), random.randint(1,6),)
Gribouillis 1,391 Programming Explorer Team Colleague

You could use my snippet to restart the program https://www.daniweb.com/software-development/python/code/260268/restart-your-python-program- .

From action_reload(), you can call restart_program(). Before that, you can try to compile the main program in order to eliminate possible syntax errors.

Gribouillis 1,391 Programming Explorer Team Colleague

Very good. It can be improved with n = len(mylist) % 4.

Gribouillis 1,391 Programming Explorer Team Colleague

Here is what you can do with an array for example

>>> from array import array
>>> spam = b'5470011234567000'
>>> eggs = array('b', spam)
>>> eggs
array('b', [53, 52, 55, 48, 48, 49, 49, 50, 51, 52, 53, 54, 55, 48, 48, 48])
>>> spam
b'5470011234567000'
>>> eggs[3] = 67
>>> eggs
array('b', [53, 52, 55, 67, 48, 49, 49, 50, 51, 52, 53, 54, 55, 48, 48, 48])
>>> bytes(eggs)
b'547C011234567000'
Gribouillis 1,391 Programming Explorer Team Colleague

Your python code does not look like the C code. At line 7 and 11, it should be m_key_code[idx] = .... Also 0 should probably be n0 at the end of line 7.

It means that m_key_code must be a writable structure such as a list or an array (in module array). What type did you choose for m_key_code ?

Edit: Sorry, I see from the log that m_key_code is a bytes. It won't work because a bytes is immutable.

Gribouillis 1,391 Programming Explorer Team Colleague

Yes {} does not have the same semantics in C or in python. Use lists [] or tuples () for the e_rotor*. Or you can probably use a bytes

e_rotor_10 = bytes([5, 4, 1, 8, 7, 3, 0, 2, 9, 6])
Gribouillis 1,391 Programming Explorer Team Colleague

Great, good luck!

Gribouillis 1,391 Programming Explorer Team Colleague

We still don't know if you are using python 3, nor the type of enigma_string, which is necessary here (print type(enigma_string)). Assuming this is python 3 and enigma_string is a bytes, you can try

    key_length = len(enigma_string)
    m_key_code = enigma_string
    n0, n9, nA = b'09A'


    check_sum = 1
    for idx, n in enumerate(m_key_code[2:], 2):
        if n0 <= n <= n9:
            temp_sum = n - n0
            print("DEBUG temp Sum", temp_sum)
        else:
            temp_sum = n - nA

        check_sum += idx + temp_sum + (idx * temp_sum)
        print("DEBUG> Check Sum:", check_sum)

    check_sum = 100 - (check_sum) % 100
    dummy = [n0 + (check_sum % 10), n0 + ((check_sum // 10) % 10)]
    m_key_code = bytes(dummy) + m_key_code[2:]
Gribouillis 1,391 Programming Explorer Team Colleague

It depends on what you call good. I have a Epson XP-700 at home and it works very well with linux kubuntu. Epson publishes free drivers for the printer and the scanner. Avoid certain brands such as Lexmark which have a tradition of poor linux support (it may have changed since I had this problem, but be very careful).

Gribouillis 1,391 Programming Explorer Team Colleague

If you want to start at position 2, you only need

for idx in range(2, key_length):

Do you have a variable m_keyCode ? The body of the for loop depends on this. If you are with python 3 and m_keyCode is a bytes instance, it is easy because the values are already small integers, for example

>>> v = b'4211'
>>> print([x for x in v])
[52, 50, 49, 49]

If you are with python 2, you'll have to use ord()

>>> v = '4211'
>>> print([ord(x) for x in v])
[52, 50, 49, 49]
Gribouillis 1,391 Programming Explorer Team Colleague

Why not try D ? It was originally a language for windows because its creator Walter Bright wrote the first DMD compiler for windows, but it now works on various platforms including linux, and there are QT bindings http://www.dsource.org/projects/qtd . D is a very attractive language.

Gribouillis 1,391 Programming Explorer Team Colleague

You'll need some time and more googling to get a correct picture of all these languages. For example fortran's domain is not OS programming but engineering and numerical analysis.

Wikipedia has a long list of programming languages https://en.wikipedia.org/wiki/List_of_programming_languages : you cannot reasonably learn all of them :)

The choice of the programming language is partly independent from the choice of the gui toolkit. For example you can code QT4 guis in many languages https://en.wikipedia.org/wiki/List_of_language_bindings_for_Qt_4 The same hold for Tcl/Tk or wxwidgets.

Gribouillis 1,391 Programming Explorer Team Colleague

The first thing is to never have variable names containing a variable index, such as product_1, product_2, etc. Use lists or tuples instead

pairs = [
    ("Flake", 0.55), ("Wispa", 0.50),("Crunchie", 0.65),
    ("Milky Way", 0.35), ("Boost", 0.65)
]
product, product_price = zip(*pairs)

Then product[0] is 'Flake',product[4] is 'Boost' and similarly for product_price.

You can write loops

for i, p in enumerate(product):
    print('Item: {} Price: {}'.format(p, product_price[i]))
Basel_1 commented: Thanks man, this really helped. +0
Gribouillis 1,391 Programming Explorer Team Colleague

I would not recommend to choose Objective-C. It is a very nice language but AFAIK, most of the existing programs and tools use cocoa which is an Apple library. You could be frustrated not to be able to use these tools.

Gribouillis 1,391 Programming Explorer Team Colleague

The history of the unix system is tightly bound to the history of the C programming language, so I would say that a genuine linux application is written in C, with the help of the GNU tools.

However, C is a little bit outdated, so I think C++ can be tolerated.

There is nothing in linux that plays the role of the .net framework in windows, so that most modern languages but microsoft's languages can be considered native in linux. For example a python program is very linuxish. It is sustained by libraries written in C and it gives you a complete access to CLI and GUI libraries.

RikTelner commented: "For example a Python program is very Linuxish" - noted. +2
Gribouillis 1,391 Programming Explorer Team Colleague

Here is a french site which goal is to ungooglize internet. It is a non-profit organization supporting free software.

Gribouillis 1,391 Programming Explorer Team Colleague

There is a better way: you can disable 2C when 1A is on. In the following code, I added a callback method, which is called when one of the options is selected. It is a very good way to prohibit some choices. It is completely configurable.
This code needs to be completed, I only started the refactoring, but it already works.
Compare it to your code with a diff visualizer such as meld or kdiff3 or winmerge, etc.

import Tkinter as tk
from Tkinter import *
from functools import partial


LARGE_FONT= ("Verdana", 12)

class ChangePages(tk.Tk):

    def __init__(self, *args, **kwargs):

        tk.Tk.__init__(self, *args, **kwargs)
        container = tk.Frame(self)
        container.pack()
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)
        self.frames = {}
        for F in (MainPage, Page01, Page02):

            frame = F(container, self)

            self.frames[F] = frame

            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame(MainPage)

    def show_frame(self, cont):

        frame = self.frames[cont]
        frame.tkraise()

#MainPage
class MainPage(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self,parent)

        button1=Button(self,text='Go To Page 1',fg='blue',font=('Helvetica',26),height=5, width=20,command=lambda: controller.show_frame(Page01)).grid(row=1,column=1)

#Page01
class Page01(tk.Frame):

    def __init__(self, parent, controller):

        self.option1 = option1 = IntVar()
        self.option2 = option2 = IntVar()
        self.option3 = option3 = IntVar()

        tk.Frame.__init__(self, parent)
        f = Frame(self)
        f.pack(side='left')

        label1=Label(f,text='Select options',fg='blue', font=("Arial", 36, "bold"),width=54, relief='solid').grid(row=1,column=1,columnspan=3)

        labelspacing=Label(f,text='Option 1 ',font=("Arial", 18, "bold"),width=20,height=1).grid(row=2,column=1)
        labelspacing=Label(f,text='Option 2 ',font=("Arial", 18, "bold"),width=20,height=1).grid(row=2,column=2)
        labelspacing=Label(f,text='Option 3',font=("Arial", 18, "bold"),width=20,height=1).grid(row=2,column=3)

        def C(*args): return partial(self.option_changed, *args)

        buttonoption11=Radiobutton(f, text="Option 1 - A", variable=option1, value=1, indicatoron=0, fg='blue',font=('Helvetica',26),height=1, width=20, command=C(1,'A')).grid(row=3,column=1)
        buttonoption21=Radiobutton(f, text="Option 2 - A", variable=option2, value=1, indicatoron=0, fg='blue',font=('Helvetica',26),height=1, width=20, command=C(2,'A')).grid(row=3,column=2)
        buttonoption31=Radiobutton(f, text="Option 3 - A", variable=option3, value=1, indicatoron=0, fg='blue',font=('Helvetica',26),height=1, width=20, command=C(3,'A')).grid(row=3,column=3)

        buttonoption12=Radiobutton(f, text="Option 1 - B", variable=option1, value=2, indicatoron=0, fg='blue',font=('Helvetica',26),height=1, width=20, command=C(1,'B')).grid(row=4,column=1) …
Gribouillis 1,391 Programming Explorer Team Colleague

What is the type of soup.text ? try

print(type(soup.text))

if it is a string (type str), you could try

import re
for word in re.findall(r'\b\w+\b', soup.text):
    ...
Gribouillis 1,391 Programming Explorer Team Colleague

Isn'it if word.startswith('A') ?

Gribouillis 1,391 Programming Explorer Team Colleague

Yes because Vegaseat uses

import tkinter as tk

while you are using

from tkinter import *

Usually, people prefer to avoid import * because there is no way to see which names are imported in the current namespace. With the first import, only the variable tk is added to the current namespace.

Avoiding import * is a good rule, although very good tkinter programs have been written with this import.

Gribouillis 1,391 Programming Explorer Team Colleague

Thank you. The snippet has just been updated to version 0.2.1.

Gribouillis 1,391 Programming Explorer Team Colleague

You might be interested in my print_multicolumn() code snippet https://www.daniweb.com/software-development/python/code/468373/print-a-list-in-multicolumn-format and also by module prettytable in general. Here is what it does

>>> L = ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'bbbbbbbbbbbbbbbbbbb', 'c', 'k', 'k', 'l', 'a', 'b', 'c']
>>> print_multicolumn(L, 3, vertically=False)
  a   b                     c  
  a   b                     c  
  a   bbbbbbbbbbbbbbbbbbb   c  
  k   k                     l  
  a   b                     c 
Gribouillis 1,391 Programming Explorer Team Colleague

Standard builtin functions have been tested gazillion times by programs all around the world. It is almost impossible that you discover an unknown bug in them. strip() removes characters only at both ends of the string. You will have to use replace()

>>> 'qazxswedc'.replace('x', '')
'qazswedc'
Gribouillis 1,391 Programming Explorer Team Colleague

Python complains because the file's write() method needs a string argument. Here the correct way to handle things is to find the values of the href= attributes, which contain the link targets. If you want to write anything to the file, you can use write(str(anything)).

Gribouillis 1,391 Programming Explorer Team Colleague

You don't need to install it: it is part of the python standard library. Look in the standard's library documentation for reference.

Gribouillis 1,391 Programming Explorer Team Colleague

Yes , you mistakenly believe that the function equals 1. The square root is in fact sqrt((x-1)**2) Mathematically, it has the same value as abs(x-1), which is x-1 when x >= 1 and 1-x when x <= 1. It means that your function's value is x when x < 1.

Gribouillis 1,391 Programming Explorer Team Colleague

What is the question ?

Gribouillis 1,391 Programming Explorer Team Colleague

Well, here is the same loop with more prints to show what's happening

result = []
for c in ['as', 'df']:
    print 'c =', repr(c)
    for i in range(len(c)):
        print 'i =', repr(i)
        print 'c[%d] =' % i, repr(c[i])
        result.append(c[i])
print result

"""my output -->

c = 'as'
i = 0
c[0] = 'a'
i = 1
c[1] = 's'
c = 'df'
i = 0
c[0] = 'd'
i = 1
c[1] = 'f'
['a', 's', 'd', 'f']
"""
Gribouillis 1,391 Programming Explorer Team Colleague

It is the same difference as between

result = []
for c in ['as', 'df']:
    for i in range(len(c)):
        result.append(c[i])
print result

and

result = []
for c in ['as', 'df']:
    result.append(c[0])
print result
Gribouillis 1,391 Programming Explorer Team Colleague

Hm, the RAR file contains two exe programs which are fired by the python program. It is probably a virus or spyware. The best thing to do is not to run this program. It could very well erase all your files for example.

Gribouillis 1,391 Programming Explorer Team Colleague

The problem is that there is a file calendar.py on the python path which shadows the builtin module calendar. The traceback says

"C:/Users/palmer_a/Documents/App\calendar.py"

but it should be

"C:\Python34\lib\calendar.py"

The solution is to rename the fileApp/calendar.py or to move it out of the python path or to remove the App folder from the python path.

Edit: if there is a file App/calendar.pyc , it must be removed.

Gribouillis 1,391 Programming Explorer Team Colleague

This is very similar to your previous question. Take the time to understand how the code works

number = int(''.join(mylist))
Gribouillis 1,391 Programming Explorer Team Colleague

Well, you can use the index of the python documentation https://docs.python.org/3/genindex-all.html

It could be your beginner's project: write a command line tool which tells you from which module you can import symbols.

Gribouillis 1,391 Programming Explorer Team Colleague

A small improvement !

import time
import random
import sys
if sys.version[0]=='3':
    from tkinter import *
else:
    from Tkinter import *

root=Tk()
root.title('hello world in German')
canvas = Canvas(root,width=400, height=400, relief = RAISED,bg = 'blue')
canvas.pack()


txt2=canvas.create_text(100,300,text='hallo welt',fill='Yellow',font=('Helvetica',30,'bold'))


x1, y1 = (random.randint(1,6) for i in range(2))

while True:
    canvas.move(txt2, x1, y1)
    canvas.after(30)
    canvas.update()
    bl, bt, br, bb = canvas.bbox(txt2)
    if bl < 0 or br > 400 or bt < 0 or bb > 400:
        x1, y1 = (random.randint(1,6) for i in range(2))
    if bl < 0:
        x1 = abs(x1)
    elif br > 400:
        x1 = -abs(x1)
    if bt < 0:
        y1 = abs(y1)
    elif bb > 400:
        y1 = -abs(y1)

root.mainloop()
Gribouillis 1,391 Programming Explorer Team Colleague

To empty the list, use

numbers[:] = []
Gribouillis 1,391 Programming Explorer Team Colleague

@fonzali is this what you mean ? Click Here. Unfortunately, the code is unavailable ;). Let's rewrite it !

Gribouillis 1,391 Programming Explorer Team Colleague

This one looks better with python 3

import cgitb, os, sys, tempfile, webbrowser

dst = os.path.join(tempfile.gettempdir(), 'helloworld.html')
try:
    raise type('Hello World', (Exception,),{})
except:
    with open(dst, 'w') as ofh:
        ofh.write(cgitb.html(sys.exc_info()))

webbrowser.open(dst) 
Gribouillis 1,391 Programming Explorer Team Colleague

@pytony it says HELLO OWLR, there must be something wrong.