4,305 Posted Topics
There are some pretty fancy things you can do with strings in Python. You can append, convert, justify, join, split, slice, and list selected files of a folder. I just give you a small sample here. | |
This is an application of the Python Image Library (PIL) and shows you how simple it is to do pixel math on an image. | |
Re: I always wondered what ruby looked like. Thanks Dark | |
Re: Greetings Dark! I downloaded Ruby. The sample codes look a little like a mix of Python, Java and C. Got the FreeRide IDE going, cute, but nothing shows up in the output window after running the code. Is there a trick? | |
This code gets the local time from your computer, formats the date and the time and displays the result. Does not include the bavarian time measurement of how many steins you have finished since you got up in the morning. | |
One more look at BCX basic code to show the qbasic programmers how they can modernize. This shows a function that converts an integer value to a binary string. Notice that with BCX basic you need to declare your variables. Makes the code a little easier to read too. Variable, … | |
This shows you how to create a Windows GUI program in BCX basic and embed the Media Player in the form. It will give you a fully functional player with a 30k executable size for your MP3 files. The needed header files and library files are included in the BCX … | |
New to me, but MS InternetExplorer does have COM support you can access from basic code. I had to test this out and make it work. We are using BCX basic, one of the successors to Qbasic. | |
Another look at BCX basic. Here we use COM support to manipulate Excel. In other words, from within the basic code we are entering a few numbers into the Excel spreadsheet and add them up. Of course you can do much more powerful stuff. With COM support you can also … | |
Nothing new, but something for the neophyte to ponder. Some of the functions (algorithms) used by STL containers can be applied to a normal array to do inane things like copying, displaying, finding max/min, reversing, replacing, searching, shuffling, sorting, summation. This can really simplify your code. | |
I just had to do this to see how it would look like in the code field. This small prime number generator is written in BCX basic, a mildy more modern basic than Qbasic. With BCX basic you can throw in C and assembler code and it would actually compile … | |
You probably have seen those message snakes following the cursor on a web page. Well, the javascript code is not too complex, so let's look at it ... | |
With the help of BCX I managed to create some C++ code that will allow you to send text to your printer and specify the font and other things. Play around with the options to suit your own needs. I have to admire the genius behind BCX, even though it … | |
Sooner or later a Csharp snippet had to appear. This one builds a form containing a set of buttons. A bitmap drawing area is used to draw a series of circles with random color, radius and center location. Your creation can be saved as a jpeg image file. You can … | |
Short little sound files of chicken, horses, dogs, cars, trains and other annoying things is the realm of the wave file (.wav). These are easy to play and guaranteed to confuse grandpapa. Again, we are using Windows' sound workhorse winmm.lib file. Ze function this time is PlaySound(). Here is ze … | |
Many of you know how I like to use sound to make the old computer box more interesting. The midi file packs a lot of neat instrumental music. It is very simple to play, even in a console application, using the winmm.lib file that comes with just about any Windows … | |
You can have fun and learn something too. Not too much fun though! Here we take a lighthearted look at C++ string, various ways to assign a string and substring, spell forward and reverse, find characters and substrings, append, insert, replace, remove characters, separate a sentence into words and more. | |
Re: This idea is good. FunsterStil sounds Dutch to me! | |
This Delphi procedure sends the text contained in a multiline editbox (memo in Delphi lingo) to a printer. The font and font size can be specified. | |
Re: nFunsterStil? The folks at Dev C++ use it too! Wonder what that means? | |
Just to give you an idea what Delphi can do, here is a plot of the ever popular sin(x). I have put enough information into the code comments so you can build the form. The PaintBox Paint Event takes care of the plotting. | |
This is Delphi code, just testing if there is some interest. | |
The Standard Template Library (STL) vector is tempting. The burden of dimensioning an array is removed, and there are many wonderful functions to explore. The learning curve is a little steep, it will make your head swell, but in the end it's all worthwhile. Take a look at some of … | |
Let's expand the decimal to binary converter to include, amongst others, octal and hexadecimal conversions. Also shows how to exert some input control. Simple stuff! | |
Let's say you worked in the White House and had to keep two lists, one for the friends and one for the enemies. The boss came to you and said: "The Almighty talked to me out of a burning bush last night, telling me that I shall make my enemies … | |
Another experiment with the Standard Template Library (STL). This time we are taking a look at map. Map is a Sorted Pair Associative Container (a mouthful). The pair is -- const Key, Data --, where Key has to be unique. It is Key that is sorted. In this code sample … | |
Using the C++ Standard Template Libraries (STL) can be easy, once you know how to do it. No need to putz around with doubly linked lists anymore! Here is code showing how a STL list allows you to add, insert, remove, sort, splice, merge, display, and clean-out-duplicate strings. | |
Get simple information like serial number, bytes/sector, sectors/cluster, free and total disk space of your hard drive using Windows API calls. | |
What is so easy to do in HTML gets quite involved in C. Once you learn to look past the standard GUI overhead it becomes more obvious. This example shows the effect of the mouse cursor moving across a label by changing foreground and background colors. | |
This program shows how to display a JPEG (also GIF,BMP,WMF etc.) image using some Windows Graphical User Interface C code. The program uses the uuid.lib file that comes with many C compilers. | |
This snippet shows how to draw a red circle on a Windows form. Original code via BCX, modified to compile with Dev C++. The GUI code looks a little complex. Gets simpler, once you get past the required overhead. For those who need some hand holding with the Dev C++ … | |
Use a Windows API call to add some color to your text output. A rewrite of an earlier C++ snippet for the C crowd. | |
The continued fraction expansion gives us the answer to life's most persistent questions, like what is sin(x) or even tanh(x). This surprisingly short code allows you to estimate SIN, COS, TAN, EXP, SINH, COSH and TANH fairly accurately. Careful, this code is not for the usual TV crowd! You should … | |
Re: Great code Mostafaib, just what I was looking for! | |
Re: You are almost there, you need to indent properly to keep your statement blocks together ... [code=python]def load_products(filename): #filename = 'C:\Users\User\Desktop\cssetute\products.txt' f = open(filename, 'r') dictionary = {} for line in f.readlines(): list1 = line.strip().split(',') tuple_list = [] for item in list1: line = line.rstrip() if ':' in item: text, … | |
Re: Could you please give us some more details. Like operating system, type of network and so on. | |
Re: Python has no goto statement. In C as in Java a goto should only be used in special cases, like breaking out of a series of nested loops. Here is a Python workaround ... [code=python]# setting a binary flag will work, similar to a goto in C loopsDone = False … | |
Re: You need to write the value/text you are getting to the file: target.write(self.transferArea.GetValue()) | |
Re: The other GUI toolkit that works with Python 3.1 and can display a number of image formats including .jpg is PyQT. There is a note about getting the Windows installer that Henri left at: [url]http://www.daniweb.com/forums/post922737-26.html[/url] Here is a sample code in simple (no class) style ... [code=python]# display an image … | |
Re: [QUOTE=bumsfeld;959915]Extension .pyd is used for C compiled library files for Python.[/QUOTE]Files with extension .pyd are library files for Python and are accessed with the import statement. I would recommend not to use this extension for private files that are not specifically structured Python library files. | |
Re: You can snoop around Python code with this ... [code=python]import dis def myfunc(): a = 2 b = 3 print("adding a and b and 3") c = a + b + 3 if c > 7: return c else: return None # this disassembles the above function's code dis.dis(myfunc) """my … | |
Re: To colorize words you are asking too much of good old Tkinter. You most likely need to got with the wx.StyledTextCtrl() widget. This STC control wraps the Scintilla editor component so it will work with wxPython. Could be that something like this is available for Tlinter. | |
Re: I prefer to know where functions came from, so I would use the namespace alternative ... [code=python]import math y = math.sin(1) + math.cos(1) [/code]If you use ... [code=python]from math import sin, cos y = sin(1) + cos(1) [/code]... in the hope that only sin and cos are imported, you are … | |
Re: No, the line numbers are not part of the code. They are added by DaniWeb for your convenience. Click on (Toggle Plain Text), if you want to see the code without them, or you want to copy and paste code into your editor (in your case the IDLE editor). If … | |
Re: Maybe a little example will help ... [code=python]import sys args = sys.argv print(args) print( "Source file: %s" % args[0] ) # use any of these arguments in your code print( "Argument one: %s" % args[1] ) print( "Argument two: %s" % args[2] ) """ my output after saving this code … | |
Re: Try something simple like this ... [code=python]mylist = [ 0.00024064097412677081, 0.0010840802387205584, 0.003607376872954593, 0.0078014804983401742, 0.013657631815844617 ] t = open(r'my_powerD2.csv', 'w') for item in mylist: t.write(str(item)+'\n') t.close() [/code] | |
Re: The EOF is a marker byte that is at the end of any file. If I remember my C days, it is physically -1 or such thing. It is significant to any computer language that reads/writes files. In Windows EOF is generated with key combination ctrl-z and in Linux with … | |
Re: [QUOTE=utefan001;953684]When dealing with big numbers (over 100,000 digits). I find str(myint) too slow. The code below takes my machine 8 seconds. Doing a quick test in java takes 0.186 seconds [code=python] import time #**setup part** i = 0 myint = 1 while i < 100000: i = i + 1 … | |
Re: Since you have Windows, try the PyScripter IDE from: [url]http://pyscripter.googlepages.com/[/url] It has the usual run triangle icon, and you can run the code with or without saving the file. This IDE is an executable file written with Delphi, it is free (if you like it, donate a few bucks) and … | |
Re: Do not meddle in the affairs of dragons, for them you are crunchy and good with ketchup. |
The End.