761 Posted Topics
Re: For example, given a file full of numbers "file.num"[CODE]values = [] with open("file.num") as f: for line in f: for value in line.split(): values.append(int(value)) print(values)[/CODE]Of course this is not production quality since it doesn't handle files that have badly formatted integers. For that, you probably want a try block around … | |
Re: Guiding you step by step on your project is not the function of DaniWeb. However here is a very broad step by step process that you can use for any project: [LIST=1] [*]Decide what it is that you are doing. (chat page for logged in users) [*]Refine your decision into … | |
Re: First, you should show us some idea of what you think would work for your database schema, and only then will we be able to give some help. Second, this is not really the right forum for talking about a web crawler. Once you have the crawler working well enough … | |
Re: I think that you want to loop through all the items in mylist, discarding any of them that are all spaces and keeping any that have length. You do not need to do it in place as your code tries to do but you do need to understand a little … | |
Re: You want to look at the [URL="http://docs.python.org/library/struct.html"]struct[/URL] module which allows you to parse arbitrary sequence of binary types. You need to be aware of big-endian versus little-endian binary layout in the file. | |
Re: You can do this with the [URL="http://docs.python.org/library/struct.html"]struct[/URL] package. For instance, you can read four of your short integers with this snippet (derived from code I saw here: [url]http://pyfaq.infogami.com/how-do-i-read-or-write-binary-data):[/url][CODE]import struct f = open(filename, "rb") s = f.read(8) w, x, y, z = struct.unpack(">hhhh", s) [/CODE] | |
Re: I think you may be over-thinking. This works as expected:[CODE]def fun_a(): return "I am function a" def fun_b(): return "I'm b" s = { 'a': fun_a, 'b': fun_b} print("s['a'](): %s"%s['a']()) print("s['b'](): %s"%s['b']()) keep_fun = fun_a fun_a = fun_b print("After fun_a = fun_b") print("s['a'](): %s"%s['a']()) print("s['b'](): %s"%s['b']()) print("call fun_a() direct: %s"%fun_a()) … | |
Re: You can do it with either technique you mention, but it may be better over the long term (in maintenance) to have company_contact separate from customer_contact. This will start to matter when you start to care about something that matters for customers but not in house contacts (date of the … | |
Re: A key in a dictionary must be immutable (the error message does state that requirement, but so subtly that you did not notice: Mutable types should not be hashed), and lists are mutable. You can use your list as a key if you cast it to a tuple first. | |
Re: Please re-post your problem code along with the entire (error) output. When I fixed the int casts and the top level dispatch (1,2,3), the code ran as expected for me. At the top level, you can add this, to help diagnose trouble:[CODE]else: print("Missed the expected options with value %s of … | |
Re: First, you should show some effort. The best form of effort to show is some of your own code, best if it actually works to do something (maybe not the right thing); or if you cannot get it to compile then show the code and the errors you get from … | |
Re: I don't speak tkinter, but look at lines 18 and 25. Could be you need to scope the call back funcction? [iCODE]... , command = [B]Application.[/B]helloCallBack[/iCODE] | |
Re: That looks like it works. Let me point out a few places it could be better, simpler: [LIST] [*]At line (approximately 2) put [icode]totalNumber = 100[/icode]so that if you ever want to change the count of numbers to ask for, you can do it in one place. [*]For similar reasons, … | |
Re: For example, each city is in exactly one country, and each country has zero or more cities. Since this is always a one-to-many relationship, each smaller unit can have a column specifying the unique key of its next-larger unit. Similarly, each country is in exactly one sub-region, each sub-region in … | |
Re: First two meta-issues: Please use [[I][/I]CODE] and [/[I][/I]CODE] tags around your code. The result gives line numbers, saves indentation, highlights keywords and is generally a good thing (and DaniWeb wants you to do it too). The easy way is to press the [C[I][/I]ODE] button on at the top of the … | |
Re: [CODE]shell> mysqlimport [options] db_name textfile1 [textfile2 ...][/CODE] See [url]http://dev.mysql.com/doc/refman/5.0/en/mysqlimport.html[/url] and particularly, search for a comment about csv files on Windows (which you will want to alter to your specific platform) | |
Re: You should have command line tools that you can use to examine the database. Look in the [iCODE]bin[/iCODE] directory of the PostgreSQL installation location. There is also a [icode]doc[/icode] directory there. | |
Re: A virtual machine is "as if" a real machine, but running as a program on some other machine. This is useful in a variety of ways. Two of them are: [LIST=1] [*]You can run several virtual machines (even different OSs) at the same time on one piece of hardware. [*]You … | |
Re: I would not want to write that in (bash), though I suppose it might be possible if you are allowed to use tools such as wget, curl, etc. | |
Re: One of the things people do best is design and invent things, including programming languages. Also, consider that we've been doing programming for about 50 years now more or less. Compare that to, say mechanical engineering which we've been doing since the Great Wall of China... or earlier... and there … | |
Re: Try this?( no guarantee) [iCODE]echo "<img src='/images/bar_".{$row['teamA']}.".jpg'>";[/iCODE] | |
Re: better yet, what did your text book or class notes say? | |
Re: So... what you want is another loop nested inside the first loop. I'll say it in English: loop over the x value, and for each x value, loop over the y value. | |
Re: A trigger cannot directly do what you want. The documentation says: [URL="http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html"]A trigger is a named database object that is associated with a table, and that activates when a particular event occurs for the table. The trigger becomes associated with the table which must be a permanent table. CREATE TRIGGER … | |
Re: In the purple band at the top of the page is a search box. Type into that search box [I]compare two directories[/I] and press the [search] button. This problem has already been answered more than a few times on DaniWeb | |
Re: Line 10 is a problem: How do you ever quit? It should probably look something like[iCODE]while split_str:[/iCODE] (Or: What [B]is[/B] your halt condition?) line 33 is also a problem: Your while loop starts [B]after[/B] split_str is created the first time, so you need to add line 34:[iCODE]split_str = sstr.split()[/iCODE] I … | |
Re: It seems a bit odd to try to do this [B]in[/B] your shell. [B]From[/B] your shell, sure. Look here: [url]http://www.thefreecountry.com/security/encryption.shtml[/url] | |
Re: Modulus operator is the right thing to use. Why not? However, here's another way:[CODE]def divisibleBy3theHardWay(anInt): while anInt > 10: sum = 0 for c in str(anInt): sum += int(c) # I'm assuming anInt is indeed an int anInt = sum return anInt in (0,3,6,9)[/CODE]This method is also known as 'striking … | |
Re: Another DaniWeb poster has strongly recommended [URL="http://www.sybase.com/SQLAnywhere11DatabaseManagement?cmpid=cpc_us_q409_gg_sqla_sqladm0210&mc=google"]Sybase SQL Anywhere[/URL] which I can neither confirm nor deny from my own experience. Postgreql is also good and free. | |
Re: If this is class work, please at least sketch out a plan of attack, better with some code (be sure to use [noparse][CODE][/noparse][I]your code goes here[/I][/CODE] tags around your code). If this is work related, please consider getting a serious commercial quality backup program (there are free ones available: I … | |
Re: The size of a heap is smaller than the size of a tree: Heaps can be implemented on an array with effectively no overhead for storage whereas trees need extra storage to refer to each node's two subtrees[B](*[/B]). Intuitively (I haven't really thought about it hard), it seems to me … | |
Re: Oracle has a very good reputation. You may also want to look at MySql and Postgresql which are free and quite robust, but may not have such "nice" tools. In my career, I have found it very good to use more than one (programming language, or compiler, or DBMS) when … | |
Re: Read some papers on cryptography. What is interesting or important in what you learned? Can you think of some other way to do something that was discussed? Think outside the boundaries: Would steganography work better than or be better in conjunction with other techniques? What's wrong with sending messages by … | |
Re: First a meta message: You misunderstood the instructions about how to post code (easy to do). The easiest way to post code is to press the (CODE) button at the top of the message box, then paste your code between the `your code here` tags that it places for you. … | |
Re: This is just a guess. Try [icode](yafc [url]ftp://test:test@192.168.1.225:21[/url]) < commands[/icode]. The parens make the enclosed command(s) run in a sub process together which may work as you wish. | |
Re: Please imagine that a stranger walked up to you and said: [I]for exapmle cam sees people.and ıt should detect dıstance between people how can we calculate ıt does anyone any ıdea about ıt? ı couldnt fıgure out the algorıthm[/I] Would you understand what that stranger wanted? Would you feel the … | |
Re: Have a look here: [url]http://bytes.com/topic/python/answers/591081-connections-py[/url] (and note my signature ;) | |
Re: You do [B]not[/B] need a authorized certificate, though you may use it if you prefer. What the Certificate Authority does is "guarantee" that you are who you say you are. That guarantee can be via a public key associated with your certificate. [I]Where do people get the public key?[/I] You … | |
Re: "Cloud" is a buzz word referring to the (cloud of) computational resources that are available "on the web". [URL="http://www.google.com/url?sa=t&source=web&cd=1&ved=0CDIQFjAA&url=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FCloud_computing&ei=kBZvTMTdOIKCsQOEkrShCw&usg=AFQjCNHiF-WwWAL5XvVJY_JoQCkrwdCi3w"]Cloud computing[/URL] uses those resources to do work. | |
Re: Use your Intel connections to find something at or near an Intel site near LA (Jeez. LA? Ick). Failing the Intel route, drop back to your University connections and use their resources to find another graduate who works near your target area. I think you see the pattern: Unless you … | |
Re: From the command line chant [iCODE]which bsh[/iCODE]and see what happens. My guess: It will print nothing (which means it can't find bsh on your $PATH). Could you be having a bad editorial day and missing the 'a' in bash? (a few minutes later): OK, I see that on some systems … | |
Re: It is much easier to understand the program if you use CODE tags around your source code: It makes your code much easier to understand, gives syntax highlighting, protects indentation, gives line numbers and is a generally great idea. The way to understand a program is to break it into … | |
Re: I think you are either talking about a [I]type[/I] (float in Python) or a [I]representation[/I] which you can do with string formatting. [I]Type[/I] [CODE]integerValue = 484 floatValue = float(integerValue)[/CODE] [I]Representation[/I][CODE]print("%e"%integerValue)[/CODE]If neither of these is what you want, then you must ask your question more precisely. | |
Re: One way: Instead of directly printing the '*', save them into a string, then at the end [iCODE]print("%[I]<width>[/I]s"%theAsteriskString)[/iCODE] Another way: Instead of printing the asterisk, append it to an array. Kind of like this (but using your code instead of my for loop), then convert and print the array:[CODE]blanks = … | |
Re: I think you are working too hard. How about this code?[CODE]with open('file1.txt') as f1: # 42 K lines with open('file2.txt') as f2: # 18 lines with open('file3.txt','w') as fout: matches = set() for line in f2: matches.add(line.strip()) for line in f1: c0,c1,c2,rest = line.split(None,3) if c0 in matches or c2 … | |
Re: I'm confused. What label? Which database? Is this the right forum for this question? | |
Re: MySql and Postgresql are the usual choices for web service databases: They are good quality, freely available, have a large user base which means reasonably good support. Oracle also has a freely available version: [url]http://www.oracle.com/technetwork/database/express-edition/overview/index.html[/url] You may also want to look at Berkeley DB: [url]http://www.oracle.com/technetwork/database/berkeleydb/overview/index.html[/url] (also owned by Oracle). Microsoft … | |
Re: Better to use a join with the ALARMS table. I have [B]not[/B] checked that my syntax is correct... [CODE]SELECT s.Status as Error, NOW() - s.`TIMESTAMP` as `TIME Down`, s.`TIMESTAMP`, a.Reason from STATUS s join ALARMS a on s.error = a.Error_code where s.status = 5 AND s.timestamp > $lastTimeWeLooked[/CODE]Or something like … | |
Re: Perhaps you should invest in a tinfoil hat? Or better yet, describe more precisely what you want. It would also be good to know what is your operating system and why you want such a thing. | |
Re: Is the leaf node a final state? If so, then it has [B]+[/B][I]verymuch[/I] if a win, [B]-[/B][I]verymuch[/I] if a loss and [I](whatever you deem appropriate)[/I] if it a draw. Look in the right column of this page, near the top. See all the related DaniWeb posts? Some of them may … |
The End.