2,646 Posted Topics

Member Avatar for valestrom

The most efficient way is to append the rows one at a time to a **list**: ... matrix1_rows = input(...) matrix1_rows = int(matrix1_rows) ... matrix1 = [] for i in range(matrix1_rows): ... input ... row = ... matrix1.append(row) after this loop, the rows will be `matrix1[0], matrix1[1],...` up to `matrix1[1matrix1_rows …

Member Avatar for David W
0
494
Member Avatar for Myronz

If you want to round the number for printed output, the correct way is to use string formatting operations. [Click here](https://www.daniweb.com/software-development/python/code/232375/string-formatting-specifications) to see some examples.

Member Avatar for isla.rose.3
0
285
Member Avatar for bumsfeld

I wrote a code snippet some time ago with a base class for functors in python, [click here](https://www.daniweb.com/software-development/python/code/369943/a-base-class-to-define-functors). I use this class quite often to code reasonably-sized tasks which can be divided into smaller tasks sharing a temporary common state. As an example, the following code defines a functor to …

Member Avatar for bumsfeld
0
3K
Member Avatar for capton

Did you try to run the [boot repair disk](http://sourceforge.net/projects/boot-repair-cd/?source=directory) ? Edit: sorry, this is 6 months old :) I guess the OP managed to boot.

Member Avatar for Gribouillis
0
1K
Member Avatar for psichoman5

I have a fast function in this snippet [click here](https://www.daniweb.com/software-development/python/code/221031/string-to-bits#post1484218).

Member Avatar for Gribouillis
0
2K
Member Avatar for kuchi

I don't know why it reads 1899. Here is a possible patch >>> import datetime as dt >>> def patch_datetime(x): ... delta = x - dt.datetime(x.year, x.month, x.day) ... s = "{:0>2}-{:0>2}-{:0>2}".format(x.day, x.month, x.year % 100) ... d = dt.datetime.strptime(s, '%d-%m-%y') ... return d + delta ... >>> x = …

Member Avatar for Lardmeister
0
182
Member Avatar for davidbr

I would tend to use a Condition object and a `wait()` with timeout instead of a timer. Here is an example #!/usr/bin/env python # -*-coding: utf8-*- from __future__ import (absolute_import, division, print_function, unicode_literals) __doc__ = ''' ''' import threading def hello_world(): print('hello world') class PeriodicCall(object): def __init__(self, seconds, func, *args, …

Member Avatar for Gribouillis
0
220
Member Avatar for Fo.katia

>I have this but I dont know how to code it so that it works with only two clicks, 4 works but not 2. There is a line missing somewhere, such as win = GraphWin("My Rectangle", 300, 300) Apart from that, this is good python code You can do it …

Member Avatar for vegaseat
0
3K
Member Avatar for shammi.khan.73

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 …

Member Avatar for Gribouillis
0
378
Member Avatar for lewashby

write export PYTHONPATH="$HOME/bin/libpy:$PYTHONPATH" at the end of the file /home/garrett/.bashrc Then restart the terminal.

Member Avatar for Gribouillis
0
701
Member Avatar for RikTelner

Assuming you installed 14.04 Trusty, look in [this page](http://ubuntuguide.org/wiki/Ubuntu_Trusty_Tips#Associate_default_applications).

Member Avatar for TylerD75
0
455
Member Avatar for psichoman5

I dont see a `return` statement in `cadena_aletoria()`. It means that it returns `None` instead of a string.

Member Avatar for Gribouillis
0
183
Member Avatar for sritechprasad

The definition of the assignment statement is [click here](https://docs.python.org/3/reference/simple_stmts.html#assignment-statements) 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 …

Member Avatar for Gribouillis
0
176
Member Avatar for davidbr

Replace the beginning of Pag01 with class Pag01(): def __init__(self, master): tk = Tkinter self.master = master self.label1_text = ... ...

Member Avatar for davidbr
0
8K
Member Avatar for fatalaccidents

It seems to me that with `stdout=PIPE`, the subprocess may hang if nobody reads its stdout. Apparently, you are not doing anything with the output of jobexe, so you don't need `stdout=PIPE`. You can also use the `communicate()` method instead of a watching thread, why not def runJob(out_q): p1 = …

Member Avatar for ~s.o.s~
0
5K
Member Avatar for saimasiddiqui

> I couldn't concatenate a list & a string so I forced 'poisonous' into a list by adding brackets A more common way is poisonous = flowers[-1:] Notice that this gives an empty list if flowers is empty, unlike your code which raises an exception.

Member Avatar for Gribouillis
0
1K
Member Avatar for Gribouillis

This snippet defines a function `printat()` which adds line and file information to the normal `print()` function output. The intended use is a quick and dirty debugging information for everyday's use. A more complete solution is to use a logging/debugging/tracing framework.

Member Avatar for Gribouillis
5
961
Member Avatar for kiddo39

The *conversion specifier* is not the single character `%`. It has 7 components, most of them optional, as described in the documentation: [click here](https://docs.python.org/2/library/stdtypes.html#string-formatting-operations). So, for example `%s` and `%d` are valid conversion specifiers.

Member Avatar for kiddo39
0
274
Member Avatar for RikTelner

You can install phpmyadmin: sudo apt-get install phpmyadmin I hope it will work with your previous xampp install.

Member Avatar for RikTelner
0
212
Member Avatar for RikTelner
Member Avatar for ShawnM9913

Did you try googling for similar issues in ubuntu forums ? Start by reading threads such as this one [click here](http://ubuntuforums.org/showthread.php?t=1968492), where you can find solutions that worked for others.

Member Avatar for ShawnM9913
0
274
Member Avatar for sneekula

It was [my first code snippet](https://www.daniweb.com/software-development/python/code/217111/cutting-a-string-in-equal-pieces) in daniweb :). Here we go >>> splitIt = lambda d, s: [s[i:i+d] for i in range(0, len(s), d)] >>> mylist = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] >>> splitIt(3, mylist) [[0, 1, 2], [3, 4, 5], [6, …

Member Avatar for sneekula
0
260
Member Avatar for RikTelner

I agree with Slavi that *gparted* is probably the tool you need. What you can do is burn a [boot-repair-disk](http://sourceforge.net/projects/boot-repair-cd/files/). Apart from repairing boots, it contains a few tools, among which *gparted*. I used it today to resize and move a 300 GB partition (it took a few hours, but …

Member Avatar for Gribouillis
0
866
Member Avatar for asaidi

You could try a very nice trick which I used recently to restart a ubuntu PC without the password - Restart the computer and in Grub, choose *Recovery Mode* - In the menu, choose *root* - In the terminal type mount -o rw,remount / passwd <YOUR USER NAME> reboot After …

Member Avatar for Gribouillis
0
862
Member Avatar for entropicII

To use pip, in Windows, execute the program `cmd`, and type pip install PyUserInput in cmd's terminal window. In ubuntu linux, open a terminal and type sudo pip install PyUserInput give your login password on request.

Member Avatar for Gribouillis
0
2K
Member Avatar for zzmrzz
Member Avatar for Chem_1
Member Avatar for Mafiasays

If you want to fix this, you must say what the bot should do when it doesnt grab the time because it gets a blank page.

Member Avatar for Mafiasays
0
784
Member Avatar for Chem_1

Use a video tutorial such as [this one](https://www.youtube.com/watch?v=0WiiswmOH1Q).

Member Avatar for rubberman
0
333
Member Avatar for AdampskiB

This error happens in the assignment statement when you try to assign the wrong number of values to the wrong number of names, for example [code=python] >>> a, b, c = (1, 2) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: need more than 2 values …

Member Avatar for Narenthirasamy
0
9K
Member Avatar for abaddon2031
Member Avatar for abaddon2031
0
298
Member Avatar for faisal.qureshi.7121614_1

Did you try to query and change the screen resolution with the xrandr command ? See [this blog entry](http://blog.bodhizazen.net/linux/use-xrandr-to-set-a-screen-resolution/) for example. If a command line with xrandr works, you could perhaps add a script at startup to execute this command line.

Member Avatar for hbutt875
0
350
Member Avatar for chophouse

You can use `lambda line: bool(re.match(r"^\d", line))`, but following woooee's idea of not using lambda, you can also write def starts_with_digit(line): return bool(re.match(r"^\d", line)) RDD2 = RDD1.filter(starts_with_digit)

Member Avatar for Gribouillis
0
342
Member Avatar for lewashby
Re: grub

I cannot solve your issue, but I used [boot-repair](http://sourceforge.net/projects/boot-repair/) recently to restore broken boot configurations and it worked each time. In ubuntu, or live ubuntu, you can install boot-repair with apt-get, as described here: https://help.ubuntu.com/community/Boot-Repair . You only need to run the tool, click on 'Recommended Repair', and perhaps answer …

Member Avatar for lewashby
0
232
Member Avatar for ddanbe

> tell me why the dimension of Koch's curve is log(4)/log(3)? Suppose your Koch's curve is contained in a disk of radius 1, then by construction, it can be covered by 4 disks of radius 1/3. By induction, the curve can be covered by `4^n` disks of radius `r=(1/3)^n`. We …

Member Avatar for mattster
0
766
Member Avatar for chophouse

I would do it this way >>> def shift_right(list_in, offset): ... offset = offset % len(list_in) if list_in else 0 ... return list_in[-offset:] + list_in[:-offset] ... >>> one = [1,2,3,4,5,6,7] >>> for i in range(-3, 10): ... print(shift_right(one, i)) ... [4, 5, 6, 7, 1, 2, 3] [3, 4, 5, …

Member Avatar for chophouse
0
298
Member Avatar for apaulogy

Upload to where ? There is no general solution. It depends on the receiving site or computer.

Member Avatar for Jack_9
0
167
Member Avatar for frankie198

I like [spyder](https://code.google.com/p/spyderlib/). A nice feature is that you can start working with a good old plain python file, while many IDE want you to define a project first. It is also genuine free software ! In ubuntu, install with $ sudo apt-get install spyder

Member Avatar for Jack_9
0
854
Member Avatar for dancks

In linux you could use a command line such as lynx --dump URL to get a textual version of the web page. Here is what it does to this page (attachment). Edit: it seems that lynx is available in various platforms too.

Member Avatar for Gribouillis
0
298
Member Avatar for Gribouillis

A feature of the doctest module can be useful when people copy and paste their idle window in the python forum: the ability to transform an example from the python interpreter into python code without the prompts [icode]>>>, ...[/icode] and the output messages. The script below permits to use this …

Member Avatar for Gribouillis
3
907
Member Avatar for JubalBarca

Did you check [this code](http://tkinter.unpythonic.net/wiki/EnhancedText) which apparently implements playing with the arrow keys and the numpad to move the cursor in a text widget ? It could be a starting point. tkinter.unpythonic.net is a good site :) The 5 is [KP_Begin](http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/key-names.html).

Member Avatar for woooee
0
3K
Member Avatar for UCHIHAOTOBI

Assuming you can `import Tkinter`, type >>> import nltk >>> nltk.download() in the GUI which appears, select `Everything from the nltk book` and click download. Wait.

Member Avatar for Gribouillis
0
1K
Member Avatar for abaddon2031

Another way, returning a list of integers >>> import re >>> def getints(string): ... return [int(x) for x in re.findall(r'\d+', string)] ... >>> getints("foo23bar01-14qux2") [23, 1, 14, 2]

Member Avatar for Gribouillis
0
478
Member Avatar for Ravi_exact

I don't know a lot of Qt, but [this tutorial](http://www.pythoncentral.io/pysidepyqt-tutorial-creating-your-own-signals-and-slots/) says that you can pass any python types to `Signal()`. From the interpreter's point of vue, there is no difference between lst_employees = list obj_sender = object dataChanged = QtCore.Signal(lst_employees, obj_sender) and dataChanged = QtCore.Signal(list, object) If you want to …

Member Avatar for Gribouillis
0
303
Member Avatar for mohan raj91

I think you misunderstand the meaning of the raw strings. The important point is the sequence of characters that the string contains. You can see it by converting to a list. For example >>> line = "\python\001tag\file.txt" >>> list(line) ['\', 'p', 'y', 't', 'h', 'o', 'n', '\x01', 't', 'a', 'g', …

Member Avatar for Gribouillis
0
460
Member Avatar for rohan1111

Use this python script #!/usr/bin/env python #-*-coding: utf8-*- import argparse import os if __name__ == '__main__': parser = argparse.ArgumentParser(description='chmod files to mode 744') parser.add_argument('files', nargs='+', metavar='FILES') args = parser.parse_args() for filename in args.files: os.chmod(filename, 0744)

Member Avatar for rohan1111
0
191
Member Avatar for neeraj_shri

If you want mysql for LAMP, the easiest way I know is sudo aptitude install tasksel sudo tasksel navigate the menu with arrow keys, select LAMP with spacebar, return, done.

Member Avatar for JeoSaurus
0
400
Member Avatar for Needhelp2

Using `readlines()` is a bad idea as it reads the whole file in memory. You could try something like the following code, which loads one line at a time #!/usr/local/bin/python2.7 from __future__ import print_function search_phrase = "Jul" with open('input.txt','r') as f: data = enumerate(f, 1) try: while True: line_num, line …

Member Avatar for Needhelp2
0
3K
Member Avatar for abaddon2031

Replace the blocks for item in data: writer.writerow(data) with writer.writerow(data)

Member Avatar for abaddon2031
0
2K
Member Avatar for acurit1

The End.