- Strength to Increase Rep
- +16
- Strength to Decrease Rep
- -4
- Upvotes Received
- 1K
- Posts with Upvotes
- 1K
- Upvoting Members
- 383
- Downvotes Received
- 26
- Posts with Downvotes
- 25
- Downvoting Members
- 16
Mind explorer.
- Interests
- Logic, psychology, mathematics.
- PC Specs
- Kubuntu 16.04 Xenial Xerus
2,646 Posted Topics
Re: Here is a very different solution (the bitCount() function comes [from here](http://wiki.python.org/moin/BitManipulation), it counts the number of bits set in an integer) import random def bitCount(int_type): count = 0 while(int_type): int_type &= int_type - 1 count += 1 return(count) tails = bitCount(random.getrandbits(100)) :) It is probably much faster. | |
Re: Try `print(pd)` to see where this pandas comes from. | |
Re: @urireo561 You can use pythonmagick or another imagemagick python binding to resize the image. See this snippet for example https://www.daniweb.com/programming/software-development/code/463880/resize-an-image-with-pythonmagick | |
Re: This is what I have [code=python] >>> from wxPython.wx import * __main__:1: DeprecationWarning: The wxPython compatibility package is no longer automatically generated or actively maintained. Please switch to the wx package as soon as possible. >>> import wx >>> [/code] | |
Re: HTML is a special case of XML, the difference is that in an XML file, you can have arbitrary tags, like [icode]<nunos>hello</nunos>[/icode]. So, if a library can parse XML, it can also parse HTML and other specialisations of XML, like MATHML, etc. That's why most libraries are designed for XML. … | |
Re: [QUOTE=docdawning;1059689]Sure Python requires memory management, but if you provide a bare-metal type OS beneath the interpreter, somewhat like how BIOS provides a compatibility layer, then you could set out to write an OS that's extremely heavily implemented with Python. Still, doing so would require an intimate understanding of the plumbing … | |
Re: I suppose that you can obtain the implementation of `ioctl()` by downloading the source code of the `glibc` library [http://ftp.gnu.org/gnu/glibc/](http://ftp.gnu.org/gnu/glibc/). | |
Re: see [this thread](http://www.daniweb.com/software-development/python/threads/463434/pyqt4-problem). It looks like the same issue. | |
Re: > I also want to remove header line (first line) and want to catenate rest of the lines. This code removes the first line of a file and prints the rest, concatenated whith open("myfile.txt", "rb") as ifh: next(ifh) # skip first line print(''.join(x.rstrip('\n') for x in ifh)) # read the … | |
Re: Because as you defined it, send_SMS is a method of the class sendmessage. So when you call [icode]x.send_SMS('error')[/icode], 2 arguments are passed, the first is [icode]x[/icode], the other is [icode]'error'[/icode]. There are 2 solutions, either you add an argument: [icode]def send_SMS(self, message):[/icode], or, if you don't need the instance, you … | |
Re: Perhaps a `sudo apt-get install python-pyside` (or python3-pyside). | |
Re: I would use [code=python] Calculate = sum [/code] instead of the above code ;) | |
Re: 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' | |
Re: It looks more like a windows question than a linux question. I think the [plink.exe ](http://the.earth.li/~sgtatham/putty/0.52/htmldoc/Chapter7.html) tool can execute remote commands through ssh. | |
Re: Majestic0100 is probably working on another project now as this thread was started 8 years ago! | |
Re: I've been learning python for more than 20 years. It is an endless quest. | |
Re: There are [good functions](http://tnt.math.se.tmu.ac.jp/nzmath/manual/modules/prime.html) in the [nzmath](http://tnt.math.se.tmu.ac.jp/nzmath/) module. Here is a session with python 2.7 in linux >>> import nzmath >>> from nzmath.prime import primeq /usr/local/lib/python2.7/dist-packages/nzmath/config.py:328: UserWarning: no datadir found warnings.warn('no datadir found') >>> primeq(9999991) True >>> import timeit >>> find_function = 'from __main__ import primeq' >>> stmt = 'primeq(9999991)' … | |
Re: Read this [url]http://www.daniweb.com/forums/announcement.php?f=8&announcementid=3[/url] | |
Re: You could use `itertools.groupby` and `collections.Counter`. Something along the lines of newip = [] c = Counter() for key, group in groupby(logfile, key=lambda e: e.split('.',1)[0]): for entry in group: c.update(re.findall(r'[0-9]+(?:\.[0-9]+){3}', entry)) newip.extend(ip for ip, cnt in c.items() if cnt > 10) c.clear() newblist = blacklist + newip The groupby() groups … | |
Re: Here is a perhaps more readable version try: from Tkinter import * except ImportError: from tkinter import * import time root = Tk() clock = Label(root, font=('times', 20, 'bold'), bg='green') clock.pack(fill=BOTH, expand=1) def tick(): s = time.strftime('%H:%M:%S') if s != clock["text"]: clock["text"] = s clock.after(200, tick) tick() root.mainloop() | |
Re: This deserves an answer: ''' tk_button_toggle5.py ''' from functools import partial import itertools import sys python2 = sys.version_info[0] == 2 tk = __import__("tT"[python2] + "kinter") def toggle(button): button.state = not button.state button['text'] = str(button.state) def new_btn(state): btn = tk.Button(width=12) btn.state = bool(state) btn.config(text= str(btn.state), command = partial(toggle, btn)) btn.pack(pady=5) return … | |
Re: [QUOTE=novice20;1448561]And... import in script2 worked fine when mode_check() was defined before main. Please let me know, why is it wrong to define a function before main, if it is so? and why did it work now?[/QUOTE] Your problem is a circular import like this [code=python] # in module A import … | |
Re: I don't think it's correct to blame Google for Q&A sites' success. I think these sites meet a specific programmers' need: we want to use software and libraries and we don't have time to learn APIs or read every manual. So we need expert answers to specific use cases. The … | |
Re: You can try [Qwant](https://www.qwant.com/) [Qwant](https://www.qwant.com/?q=foobar&t=all), although it is said to be bing + privacy. | |
Re: The problem is that you write `from tkinter import *` after `from graphics import *`. Some objects defined in the [graphics.py](https://pypi.org/project/graphics.py/) package get shadowed by objects defined in the tkinter package. In this case, the graphics.py [Text](http://mcsp.wartburg.edu/zelle/python/graphics/graphics/node11.html) class is shadowed by the tkinter [Text](http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/text.html) widget. The best thing to do … | |
Re: The best layout for french is the [BÉPO](https://en.wikipedia.org/wiki/Keyboard_layout#B%C3%89PO) layout. Install it and switch the layout everytime you want to type in French. | |
Re: I don't know the answer, but this is what I read in django's documentation > It is always better for security to deploy your site behind HTTPS. Without this, it is possible for malicious network users to sniff authentication credentials or any other information transferred between client and server, and … | |
Re: 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 … | |
Re: I think [shutil.copytree](http://docs.python.org/2/library/shutil.html#shutil.copytree) should work. | |
Re: Read the file by chunks and also write chunks: with open("portrait1.dng", "rb") as binaryfile : with open("readfile.raw", "wb") as newFile: while True: chunk = binaryfile.read(4096) if not chunk: break newFile.write(binascii.hexlify(chunk)) > my whole university life is on this (translation, if it dies i die). Make sure you backup your files … | |
Re: Before even thinking of using python for this, you need to define what the computer will do and what the human player(s) will do. You don't need a specific programming language for this. | |
Re: Unindent the ask_number() and ask_yes_no() definitions and remove the self parameter. | |
Re: In python 3, the value returned by `binascii.hexlify()` is a `bytes` instance instead of a `str` instance. As `setText()` is expecting a `str` instance, you need to convert hexadecimal to `str`. This is done by hexa_str = hexadecimal.decode('utf-8') | |
| |
Re: @sam_38 Your question is way too vague. The best way to use a programming forum is to start your own thread and post code containing your attempts to solve the problem. If your question is about persisting data on disk, there is a builtin module `pickle` that can persist almost … | |
Re: Strange code and strange specifications as usual, but well ... Two points: 1. Why do you want the vector to hash as a tuple ? What's the use of this ? There must be a good reason as this breaks your code. 2. There is a serious drawback in your … | |
Re: The `sorted()` function has a boolean `reverse` parameter that allows to sort in descending order sorted(lines, key=itemgetter(3), reverse=True) This is much more efficient than trying to write your own quicksort method. | |
Re: For problem 1, I think you could remove the 'data' argument in def OnCellChange(self, evt, data): ... For problem 2, you need to compute the `row` value that you want to insert, for exemple def appendRow(self): row = self.GetNumberRows() # + 1 perhaps ? self.AppendRows(1) self.data.append((str(row), '', '', '', '', … | |
Re: @Madhu_6 It is permitted, but it does not have the meaning you expect. Here is an experiment >>> small_case = "abcdefghijklmnopqrstuvwxyz" >>> space = " " >>> camel_case = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" >>> "k" in [small_case, camel_case, space] False >>> "K" in [small_case, camel_case, space] False >>> "abcdef" in [small_case, camel_case, space] … | |
Re: No I've never seen a solution. That's one of the many features of windows that waste the user's time! ![]() | |
Re: Matplotlib can handle events such as keypress or mouse clicks. One only needs to write a few callbacks. Here is a small example adapted from the matplotlib's documentation. It first displays a curve, then, on a keypress event a second curve, then a third """ Show how to connect to … | |
Re: Hi Tcll, it's been a while indeed! I don't think there is a flaw in python's descriptor implementation. Also I don't understand why you think there is a security issue nor which 'private object' is 'passed into your backend'. If Attr is a descriptor in the class, then indeed `Instance.Attr` … | |
Re: Hi, it's been a long time since I last used wxpython, but I think it should be something like for i, seq in enumerate(data): for j, v in enumerate(seq): self.SetCellValue(i, j, v) You should find good examples in the Mouse vs Python series, which cover many things concerning wx python, … | |
Re: **What have you tried?** This is what everybody wants to know when you ask a homework question. We don't know what you know about programming in python. Obviously you must have learned how to define a function, that's a starting point. Let's take it the other way around. If I … | |
Re: > I tried to make all the print statements python2/python3 compatible Do you know you can use from __future__ import print_function to get immediate compatibility ? | |
Re: The error 'TypeError: must be type, not classobj ' usually appears in python 2 when an old style class instance is used in a function where a new style class instance is expected. Aren't you using an old version of python where Tkinter classes are old style classes ? If … | |
Re: Start by reading a list of names from a single file and print these names in the console. Post your code! | |
Re: We don't need the source file, but a link to the site where you found that library. | |
Re: Is there a `setup.py` file in the extracted hierarchy? If so, open a terminal (cmd window), go to the directory where the setup.py file is and type `python setup.py install`. Before that, make sure that the `python` command invokes the python 3.6 interpreter. EDIT: from what I read on the … |
The End.