2,646 Posted Topics
Re: 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 … | |
Re: 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. | |
Re: 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 … | |
Re: 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. | |
Re: I have a fast function in this snippet [click here](https://www.daniweb.com/software-development/python/code/221031/string-to-bits#post1484218). | |
Re: 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 = … | |
Re: 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, … | |
Re: >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 … | |
Re: 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 … | |
Re: write export PYTHONPATH="$HOME/bin/libpy:$PYTHONPATH" at the end of the file /home/garrett/.bashrc Then restart the terminal. | |
Re: Assuming you installed 14.04 Trusty, look in [this page](http://ubuntuguide.org/wiki/Ubuntu_Trusty_Tips#Associate_default_applications). | |
Re: I dont see a `return` statement in `cadena_aletoria()`. It means that it returns `None` instead of a string. | |
Re: 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 … | |
Re: Replace the beginning of Pag01 with class Pag01(): def __init__(self, master): tk = Tkinter self.master = master self.label1_text = ... ... | |
Re: 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 = … | |
Re: > 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. | |
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. | |
Re: 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. | |
Re: You can install phpmyadmin: sudo apt-get install phpmyadmin I hope it will work with your previous xampp install. | |
Re: do `sudo chmod 755 xampp-linux-*-installer.run` first. | |
Re: 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. | |
Re: 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, … | |
Re: 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 … | |
Re: 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 … | |
Re: 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. | |
Re: In ubuntu one uses `apt-get` instead of `yum`. | |
Re: 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. | |
Re: Use a video tutorial such as [this one](https://www.youtube.com/watch?v=0WiiswmOH1Q). | |
Re: 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 … ![]() | |
Re: It means that none of the calls to `.find()` finds anything. | |
Re: 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. | |
Re: 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) | |
Re: 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 … | |
Re: > 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 … | |
Re: 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, … | |
Re: Upload to where ? There is no general solution. It depends on the receiving site or computer. | |
Re: 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 | |
Re: 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. | |
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 … | |
Re: 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). | |
Re: 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. | |
Re: 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] | |
Re: 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 … | |
Re: 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', … | |
Re: 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) | |
Re: 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. | |
Re: 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 … | |
Re: Replace the blocks for item in data: writer.writerow(data) with writer.writerow(data) | |
Re: I suggest to execute sql queries on the database using module MySQLdb. |
The End.