132 Posted Topics
Re: The formatting on this makes it hard to read. How about some indention and blank lines in between sections? | |
Re: The constructor takes `Product(string product, double price)`, but you are creating it (on line 8) with `Product("200.00", 0)`. You set the `price` to `0` and the `product` to `200.00`. Try this: Product product = new Product("HP Computer", 200); | |
Re: Switch m and n around in the if statement. 24 % 6 == 0 // not 6 % 24 == 6 25 % 6 == 1 // not 6 % 25 == 6 The arguments are backwards according to the way the `%` operator works. isDivisor(m,n) == (n % m … | |
Re: Is this a question? What language is this for? What have you tried? If this is a question about programming please take a minute to look under the [Software Development](https://www.daniweb.com/software-development/2) menu, choose whatever language you are seeking help for, and post the question there. You will receive much better help … | |
Re: Did you look at the packet sniffer I showed you in response to your [first question](https://www.daniweb.com/software-development/python/threads/483755/python-http-request-sniffer-in-python)? | |
Re: How much python do you know? What have you tried? You can walk a directory like this: import os for root, dirs, files in os.walk('/my_directory'): for filename in files: if not filename.endswith('.mp3'): continue fullpath = os.path.join(root, filename) print('Found mp3 file: {}'.format(fullpath)) After that, there is the `re` module for regex, … | |
Re: I don't really use the `xml` module, and it would really help if you could [format your code](https://www.daniweb.com/community/syntax). But this is what I found: s = '<foo name="test"><foobar name="original"></foobar></foo>' d = minidom.parseString(s) elems = d.getElementsByTagName('foobar') elems[0].setAttribute('name', 'changed!') print(d.toprettyxml(indent=' ')) Output: <?xml version="1.0" ?> <foo name="test"> <foobar name="changed!"/> </foo> The element … | |
Re: There is a packet sniffer for linux here: http://www.binarytides.com/python-packet-sniffer-code-linux/ It uses the `socket` module to grab incoming and outgoing packets. It's pretty low-level stuff. The packet data is raw bytes, so you would have to decode/translate them. I converted it to Python 3 and put it on my pastebin: http://welbornprod.com/paste/?id=fgyx … | |
Re: Line 28: if(overnightCheck >= 0 && overnightCheck <= 1) { if(overnightCheck == 1) overnightPrice = 5.00; } That wrapper to make sure overnightCheck is 1 or 0 is pointless. Because you are checking it again just below, and then doing nothing for the `false` case. What happens if a user … | |
Re: I couldn't replicate it on my machine, but I'm using Mono so that is to be expected. It only added extras when I failed to type in the complete extension. Like: `file.min.css` yields `file.min.css` ..but `file.min` yields `file.min.min.css` I did however see this [AddExtension](http://msdn.microsoft.com/en-us/library/microsoft.win32.filedialog.addextension(v=vs.110).aspx) setting you might want to take … | |
Re: There is also `collections.Counter`. from collections import Counter wordcount = Counter(['this', 'this', 'that', 'that', 'that', 'and']) print(repr(wordcount)) # Reveals: # {'this': 3, 'that': 2, 'and': 1} Not only is it easy, but I'm pretty sure it performs better (coded in C). If you *really* wanted it in list format you … | |
Re: Start by posting what you have tried already. Condense it down to only what is needed to show your problem. If there are any errors then post the error message and line number. You haven't *really* told us what the problem is, only that there is a problem. We need … | |
Is this correct?  That seems like a lot of points for someone that has never contributed. Bug, or exploit? | |
Re: You closed the `Accept` function's block of code with `}`. To the compiler, all of that code is just hanging there in the namespace. Also, I'm not sure if you meant to or not but you've got double declarations of everything. Watch your braces and code blocks. Use proper indention … | |
Re: Your formatting is kinda messed up. Read [this](https://www.daniweb.com/community/syntax) for help with [code blocks](https://www.daniweb.com/community/syntax#code). | |
Re: [PyUSB](https://github.com/walac/pyusb/blob/master/docs/tutorial.rst) seems to be the recommended way of talking to USB devices. Here's a small example inspired by their tutorial: import usb.core # find() can be used to find a single device, # or all devices. devices = usb.core.find(find_all=True) # I'm just printing the list of devices. # I'm not … | |
Re: You have a nested loop there, and it modifies the list while iterating. That's asking for trouble. You're iterating over `codeList` and then `if code is not None` you are modifying `codeList`. You then iterate over the new `codeList`, and when it's done goes back to the top of the … | |
I was just looking at my profile and noticed the member badge section was pointing to 127.0.0.1. I followed the "member badge" link (the page that shows you all the options for member badges), and I found the 127.0.0.1 link there too. Here's some screenshots:   ..i clicked my … | |
Re: This is really old, and I'm no expert on WMI, but I can provide at least a little insight. It grabs the domain name for the current machine from Active Directory. Creates a comma-separated value (csv) file like: 'domain_services_info.csv' It uses WMI (Windows Management Instrumentation) to query a list of … | |
Re: This post is really old, but here is my answer in case someone else comes looking. There are several ways you can trim it down further. I can show you one using `bash`/`sh`, `grep`, and `sed`. # This says remove all spaces from the input sed "s/[ ]//g" # This … | |
Re: This works ok on my end, don't use the `while True` loop. Use `iter()`. (this is slightly modified for Python3): #!/usr/bin/env python3 import socket # This would be 'import urlparse' in Python 2. import urllib.parse url = 'http://www.py4inf.com/code/romeo.txt' # Using urlsplit to extract the domain from the url. # This … | |
Re: Please don't use this on anything that is truly important, or high risk. There are frameworks, tools, and other methods available to help you protect your site with very little effort. I'm not sure how you would do this safely in pure JavaScript, but on my site the couple passwords … | |
Re: Just thought I would add my 2 cents. **IDLE** is my 'goto' for small scripts and quick prototyping/testing. If it's not that then its '**Kate**' (kde's text editor for programmers, a gnome equivalent would be **gEdit**). But for bigger projects, like my Django site that has like 78 modules (due … | |
Re: There is a possibility that the python executable is not in `/usr/bin` on other people's systems. It could be in `/usr/local/bin`, `/home/otheruser/.local/bin`, or anywhere else. Without the `env`, you are telling it exactly which executable to use. `env` will use the system's `$PATH` to determine where python is. There is … | |
Re: What was the original problem? Your method reminds me of Visual Basic's "SendKey()". If downloading and writing an html page to disk was the problem, it can be easily solved in python. | |
![]() | Re: I don't use Wx, i tend to lean towards GTK, but this is what I've figured out. Setting the ID manually, and saving it to a dict with the filename as the value will let you retrieve it later. There were several problems with your implementation, such as redefining the … ![]() |
Re: I'm not sure of a real efficient way of doing this. Someone else might. But by iterating over each line in your test data I was able to build a dictionary with each word and a list of file numbers as the values, like `{"grain":["5", "6"], "soybean": ["6"], ... }`. … | |
Re: I see that you are overwriting the LOG_FILENAME variable. Instead of adding "log.txt" to it, you are replacing it with "log.txt". That would make it write to the desktop I think. Try doing this instead (After getting the user's home directory): LOG_FILENAME = os.path.join(homedir, "log.txt") # returns: C:\Users\USERNAME\log.txt # instead … | |
I'm not much of a javascript developer right now, as I just recently found the need to learn it. I'm using jQuery, and Javascript (sometimes stupidly, like when I find out jQuery already "abstracted out" something I wrote a 20 line function for). My question is about style though, with … | |
Re: Why would you use Comic Sans? :P P.S. - All those CSS style comments in the body? | |
Re: I'm not quite sure what you mean, but you can access Person's properties using a template. If you have a list of Person's passed to the template (lets call it `persons_list`), then you could do something like this in [Django Template Language](https://docs.djangoproject.com/en/dev/topics/templates/‎): <table> {% for person in persons_list %} <tr> … | |
Re: It seems you've got your answer at SO. | |
Re: Sorry I don't have a solid example to back this up but I would start with either `imaplib` or `poplib`. Both allow you to login/authorize an email account and check for messages. From there it would be filtering addresses with either `if 'my@email.com' in address.lower()`, or a regex expression. I … | |
Re: If they do different things they probably need their own names. pyTony is suggesting you don't redefine the same function more than once. Since they do *almost* the same thing, they could probably use a single function with different parameters. def check_input(options, msg): """ checks input, accepts a number of … | |
Re: Some providers allow you to zip it up, although some will see the exe inside the zip. There are other packaging formats that may work (tar, rar, gz, etc.). Some times just changing the file extension works, though you would have to tell your brother to change it back. I … | |
Re: To get last page number and randomly select one: last_page = Pdf_toRead.getNumPages() - 1 page_one = pdf_toRead.getPage(random.randint(0, last_page)) Also, it seems they do start at 0 like a normal list/tuple/array. Hince the '`getNumPages() - 1`'. I haven't used the pyPdf module, but IDLE and Control + Space works wonders for … | |
Re: If I have to have multi-line print statements I do something like this: print("This is my first line of text\n" + \ "And then a second line.\n" + \ "And a third.") I read python's indention really well, probably like a lot of people, and this makes those lines get … | |
Re: where are you running your little test script from? python/django can't find the settings.py module for some reason. are you running manage.py shell, or regular python interpreter? is "NewMKEProject" the name of a valid python package in your project (with \_\_init__.py even if its empty)? My directory structure is usually … | |
I'm no pro when it comes to BASH, but I have been known to shell-script my way out of a problem here and there. One of the useful things you can do is a for-loop, whether it be used on file names, script arguments, or just a string of words. … | |
I'm no pro when it comes to BASH, but I have been known to shell-script my way out of a problem here and there. One of the useful things you can do is a for-loop, whether it be used on file names, script arguments, or just a string of words. … | |
This is another useful script I came across. It prints a color-code chart in your terminal. It can help you find the color-code you are looking for, or view the current color-scheme you are using (people use it on reddit/r/unixporn to show off their system's theme, I use it to … | |
I didn't write this, the credits are in the code. It's a code-golf version, and I'm sorry about that. I am trying to 'decode' it but I don't have the skills, so the 'decoded' version doesn't have the right colors. This is an example of what you can do with … | |
Re: uhm, forbade you to use def (functions)? i don't think thats right, and not using lists/dicts/etc. can't be right either. dict, list, class, etc. would get rid of all of those `if` statements, and allow for readable code. Plus a program without a function definition makes you repeat yourself too … | |
Re: I see a "translate this page" option, if thats what you mean. it shows up automatically.  | |
I just wanted to show the basic usage of docopt, a module that makes parsing command-line arguments so much easier. I'm not affiliated with the creators of docopt, but I'm certainly thankful for their work and happy to post this little snippet. I will point you to [docopt.org](http://docopt.org) for more … | |
Re: It means the scan was unsuccessful (probably because it can't connect). Running your script like `nmapScan("127.0.0.1", "22")` brought up results, but running it on `"123.565.343.22"` (a bogus ip i just made up) brought a Key error. You could catch this with a try block: try: state=nmScan[tgtHost]['tcp'][int(tgtPort)]['state'] print("[*] " + tgtHost … | |
Re: Sorry to clutter this question with even more long code, but this is a script I wrote to check modules/classes for builtin conflicts. It searches the current directory for modules or can be used on other directories by adding to sys.path. #!/usr/bin/env python # -*- coding: utf-8 -*- import sys … | |
Re: I agree that this does sound a little weird. Especially with password resets and mobile reminders and such. I forget my security questions some times, because I don't make them too easy to crack. Questions like "what's your middle name" offer pretty much no security against anyone willing to do … | |
Re: probably need more info (code, url, etc.). it could be a number of things. | |
Re: `grep -i "king" abc.txt | wc -l` returns 5 (lines) -w returns 6 (words) |
The End.