Extended ASCII [was Re: for / while else doesn't make sense]
On Wednesday 25 May 2016 16:38, Gregory Ewing wrote: > Christopher Reimer wrote: >> Nope. I meant 8-bit ASCII (0-255). >> >> http://www.ascii-code.com > > That page is talking about latin-1, which is just one of many > possible 8-bit extensions of ascii. Yes. It even says "There are *several* different variations of the 8-bit ASCII table." (emphasis added), which is an understatement and a half. Wikipedia claims over 220 different "extended ASCII" encodings: https://en.wikipedia.org/wiki/Extended_ASCII That's more than the number of countries in the world, which (depending on how you count them) is generally recognised to be about 194. http://www.worldatlas.com/nations.htm -- Steve -- https://mail.python.org/mailman/listinfo/python-list
Re: [smtplib] how to assure login was succesful?
maurice writes: > Once my python script reaches the point where I login in my email account > with: server.login(username,password) (where server server = > smtplib.SMTP('smtp.office365.com:587')), it returns a tuple like this: > > (235, > '2.7.0 Authentication successful target host [address here]') Try a wrong login. I would expect you to get some kind of exception. -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about imports and packages
On Wednesday 25 May 2016 14:39, Ben Finney wrote: > What the Python import system expects you to do is:: > > cd ../ > python3 -m fnord.foo I don't think you even need to do the cd provided the fnord directory is inside a directory on the path. It only gets complicated if fnord cannot be found by the import system. > To me, that makes Python at a severe handicap as a simple-to-use > scripting language. There's something to what you say, but I don't think it's quite that bad. To me, "simple to use" means a stand-alone, single file .py file that only imports modules in the standard library or site-packages (including the per-user directories). So long as your script is a single file, you can always run it the old fashioned way: python /path/to/my/script.py and it will Just Work. It's only packages or collections of modules that get tricky, and for them, the supported One Obvious Way is to make sure that they are on the PYTHONPATH. To make that happen, you are absolutely spoiled for choice: - if you have root access, you can put them in the global site-packages directory; - otherwise, you can put them in your per-user site directory; - or you can put them anywhere you like, and point a .pth file to them; - or add the enclosing directory to your PYTHONPATH; - or even have your script's main module modify sys.path. I don't think this is that much different from the way other scripting languages handle it. E.g. bash. If I have a set of (say) shell scripts: fnord/ +-- foo.sh +-- bar.sh where foo.sh runs bar.sh, but fnord is *not* on the PATH, the way you make it work is: - have foo.sh temporarily modify the PATH; - have foo.sh call bar.sh using an absolute pathname. That second option isn't available to Python, but then, .pth files aren't available to the shell :-) -- Steve -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about imports and packages
On Wed, May 25, 2016 at 6:27 PM, Steven D'Aprano wrote: > I don't think this is that much different from the way other scripting > languages handle it. E.g. bash. If I have a set of (say) shell scripts: > > fnord/ > +-- foo.sh > +-- bar.sh > > > where foo.sh runs bar.sh, but fnord is *not* on the PATH, the way you make it > work is: > > - have foo.sh temporarily modify the PATH; > - have foo.sh call bar.sh using an absolute pathname. > > That second option isn't available to Python, but then, .pth files aren't > available to the shell :-) The one obvious way with shell scripts is a *relative* pathname. You can say "./bar.sh" (or, if you want to run something relative to the script directory, some manipulation of path names and $0 will do that for you). The best Python equivalent would be: from . import bar I'd very much like for that to be possible. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: for / while else doesn't make sense
> On May 24, 2016, at 11:38 PM, Gregory Ewing > wrote: > > Christopher Reimer wrote: >> Nope. I meant 8-bit ASCII (0-255). >> http://www.ascii-code.com > > That page is talking about latin-1, which is just one of many > possible 8-bit extensions of ascii. Back in the early 1980's, I grew up on 8-bit processors and latin-1 was all we had for ASCII. Over the last several days from reading this thread (and variations thereof), l've seen several extended characters that I have no clue on how to reproduce on my keyboard. I haven't embraced extended character sets yet, which means I still think of ASCII characters as being 0 through 255 (8-bit). Thank you, Chris R. -- https://mail.python.org/mailman/listinfo/python-list
Exended ASCII and code pages [was Re: for / while else doesn't make sense]
On Wednesday 25 May 2016 19:10, Christopher Reimer wrote: > Back in the early 1980's, I grew up on 8-bit processors and latin-1 was all > we had for ASCII. It really, truly wasn't. But you can be forgiven for not knowing that, since until the rise of the public Internet most people weren't exposed to more than one code page or encoding, and it was incredibly common for people to call *any* encoding "ASCII". (That's like calling any computer "an IBM", or any soft-drink "Coke".) But being an old Mac user from the 1980s, I'm very aware that DOS and Mac used different character sets, although even I wasn't aware at the time that the DOS character sets were internationalised with different versions of "extended ASCII". (That's how Anglo-centric I was in the 1980s: I honestly never gave a moment's thought to the fact that, say, Greek computer users would like to be able to type in Greek. I thought that while DOS users and Mac users had different character sets, all DOS users had the same character set, and likewise for Mac users.) The first code pages were from IBM in the 1970s. Different countries had their own national standards for "extended ASCII", as did different computer manufacturers. Apple, Apricot, Atari, Commodore and other hardware manufacturers used their own proprietary extensions. Due to the close partnership between IBM and Microsoft, they kept their register of code pages in sync until they fell out over OS/2 and NT. Since the 1990s, not so much. The Wikipedia articles on "Code page", "Extended ASCII" etc are good for giving a broad overview, but they lack a lot of the finer detail such as the years the different standards were formally created and when they were first made available as code pages on PCs. If you care about that sort of minutia, you will have to go digging. But very broadly speaking, even in the 1980s there was no shortage of extensions to ASCII. While the code page system was necessary at the time, the legacy of them today continues to plague computer users, causing moji-bake, errors on file systems[1], and holding back the adoption of Unicode. [1] I'm speaking from experience there. Take files created on a Windows machine using some legacy code page, and try to copy them to another server using Unicode, and depending on the intelligence of the server, you may not be able to copy them. On the flip side, there are many file names I can easily create on Linux but cannot copy to a FAT file system. -- Steve -- https://mail.python.org/mailman/listinfo/python-list
html & python connection problem with hyperlinks
Why not created the field title, that located on the template BusinessList.html as a link to go to Business_Detail.html..? please check Code: models. py: from django.db import models REGIONS = ( ('ΘΕΣ', 'ΘΕΣΣΑΛΟΝΙΚΗ'), ('ΣΕΡ', 'ΣΕΡΡΕΣ'), ( 'ΑΘΗ', 'ΑΘΗΝΑ'), TYPEOFBUSINESS = ( ('ΕΣΤ', 'ΕΣΤΙΑΤΟΡΙΑ'), ('ΦΑΡ', 'ΦΑΡΜΑΚΕΙΑ'), ('ΒΙΒ', 'ΒΙΒΛΙΟΠΩΛΕΙΑ'), ( 'ΚΟΜ', 'ΚΟΜΜΩΤΗΡΙΑ'), ('ΣΙΝ', 'ΣΙΝΕΜΑ') ) class Business(models.Model): created_Date = models.DateTimeField(auto_now_add=True) owner = models.ForeignKey('auth.User', related_name='snippets', null=True) title = models.CharField(max_length=100, blank=True, default='') Type_of_Business = models.CharField(max_length=3, choices=TYPEOFBUSINESS) region = models.CharField(max_length=3, choices=REGIONS) address = models.CharField(max_length=100, blank=True, default='') phone = models.CharField(max_length=15, blank=True, default='') image = models.ImageField(null=True) def __str__(self): return str(self.title) views.py from django.contrib.auth.models import User from django.http import HttpResponse from django.shortcuts import render, get_object_or_404 from rest_framework import filters from rest_framework import generics from rest_framework import permissions from snippets.permissions import IsOwnerOrReadOnly from snippets.serializers import SnippetSerializer from snippets.serializers import UserSerializer from .models import Business class UserList(generics.ListAPIView): queryset = User.objects.all() serializer_class = UserSerializer class UserDetail(generics.RetrieveAPIView): queryset = User.objects.all() serializer_class = UserSerializer class BusinessList(generics.ListCreateAPIView): permission_classes = (permissions.IsAuthenticatedOrReadOnly,) queryset = Business.objects.all() serializer_class = SnippetSerializer filter_backends = (filters.DjangoFilterBackend,filters.SearchFilter, filters.OrderingFilter,) filter_fields = ('Type_of_Business', 'region') search_fields = ('Type_of_Business', 'region') ordering_fields = ('Type_of_Business','title', 'region') def BusinessList(request): business = Business.objects.all(); return render(request, 'snippets/BusinessList.html' {'business':business}) def perform_create(self, serializer): serializer.save(owner=self.request.user) class Business_Detail(generics.RetrieveUpdateDestroyAPIView): permission_classes = (permissions.IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly,) queryset = Business.objects.all() serializer_class = SnippetSerializer def Business_Detail(request, pk): business = get_object_or_404(Business, pk=pk) return render(request, 'snippets/Business_Detail.html', {'business': business}) serializers.py from rest_framework import serializers from snippets.models import Business from django.contrib.auth.models import User class SnippetSerializer(serializers.HyperlinkedModelSerializer): owner = serializers.ReadOnlyField(source='owner.username') class Meta: model = Business fields = ('created_Date', 'owner', 'title','Type_of_Business', 'region', 'address', 'phone', 'image') class UserSerializer(serializers.ModelSerializer): snippets = serializers.PrimaryKeyRelatedField(many=True, queryset=Business.objects.all()) class Meta: model = User fields = ('id', 'username', 'snippets') BusinessList.html {% extends 'snippets/base.html' %} {% block content %} {% for business in business%} {{ business.created_Date }} #τυπωσε ημερ.δημιουργιας του Business {{ business.title }} {{business.Type_of_Business }} {{ business.region }} {{ business.address }} {{ business.phone }} {% if business.image %} {% endif %} {% endfor %} {% endblock %} Business_Detail.html {% extends 'snippets/base.html' %}' %} {% block content %} {% if business.created_Date %} # αν υπαρχει ημερομηνια δημιουργίας {{ business.created_Date }} {% endif %} {{ business.title }} {{ business.region }} {{ business.Type_of_Business}} {{ business.phone }} {% if business.image %} # αν υπαρχει εικονα # παρε εικονα απο το αντιστοιχο url {% endif %} {% endblock %} tutorial/snippets/urls.py from django.conf.urls import url, include from django.contrib import admin from rest_framework.urlpatterns import format_suffix_patterns from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.conf.urls import include from . import views urlpatterns = [ url(r'^admin/', include(admin.site.urls)), url(r'^$', views.BusinessList.as_view()), url(r'^business/(?P[0-9]+)/$', views.Business_Detail.as_view()), url(r'^users/$', views.UserList.as_view()), url(r'^users/(?P[0-9]+)/$', views.UserDetail.as_view()), url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')), ] urlpatterns = format_suffix_patterns(urlpatterns) urlpatterns += staticfiles_urlpatterns() tutorial/urls.py from django.conf.urls import include, url from django.contrib import admin from django.conf import settings from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.conf.urls.static import static urlp
Re: Exended ASCII and code pages [was Re: for / while else doesn't make sense]
On Wed, May 25, 2016 at 8:19 PM, Steven D'Aprano wrote: > While the code page system was necessary at > the time, the legacy of them today continues to plague computer users, causing > moji-bake, errors on file systems[1], and holding back the adoption of > Unicode. > > [1] I'm speaking from experience there. Take files created on a Windows > machine > using some legacy code page, and try to copy them to another server using > Unicode, and depending on the intelligence of the server, you may not be able > to copy them. On the flip side, there are many file names I can easily create > on Linux but cannot copy to a FAT file system. And getting a .zip file from a Windows user that had a file in it called "Café Sounds.something", extracting it on Linux, and finding it called "Caf\xe9" or something. Very annoying. Fortunately it was only the one file in a large directory. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: for / while else doesn't make sense
Christopher Reimer : > Back in the early 1980's, I grew up on 8-bit processors and latin-1 was > all we had for ASCII. You really were very advanced. According to https://en.wikipedia.org/wiki/ISO/IEC_8859-1#History>, ISO 8859-1 was standardized in 1985. "Eight-bit-cleanness" became a thing in the early 1990's. Where I was in late 1980's, the terminals were still 7-bit, and instead of ASCII, national 7-bit character set variants were being used. For example, you might see Pascal code like this: ä return the net å ret := grossÄunitÅ * grossRate http://www.aivosto.com/vbtips/charsets-7bit.html> > Over the last several days from reading this thread (and variations > thereof), l've seen several extended characters that I have no clue on > how to reproduce on my keyboard. I haven't embraced extended character > sets yet, which means I still think of ASCII characters as being 0 > through 255 (8-bit). But Latin-1 is on your fingertips? ¡Qué bueno! Entonces sabes dónde están las teclas españolas, ¿no? Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: Spurious issue in CPython 2.7.5
Hi! Thanks. Replies in-line > Den 24. maj 2016 klokken 19:12 skrev Steven D'Aprano : > > On Tue, 24 May 2016 08:22 pm, thomas povtal.org wrote: > > > Hi, > > > > Please excuse me if this is not the right place, but I have some issues > > with CPython on a NUMA machine. > > Do you mean a Non-Uniform Memory Access machine? > > Can you be more specific about the actual machine and OS used? It's Ubuntu 12.04 LTS. It appears as a NUMA machine with two nodes. However, I later learned that it's (probably?) not a real NUMA but just Ubuntu's way of representing two socktets for CPUs. I'm not very skilled in such low-level matters, unfortunately. > > 1: I get "RuntimeWarning: tp_compare didn't return -1 or -2 for > > exception". It's a line like: > > > > "if Foo = False:" where Foo is a global variable (global Foo). > > What is the type and value of Foo? global Foo = False > > Now, I've searched somewhat on google for indications on when this > > warning can be seen. However, I haven't really been able to understand > > why and even if it's significant or not. (At face value I'm nervous the > > Python runtime environment is corrupted for that process). > > At face value, that RuntimeWarning seems to indicate a bug in the > interpreter. Ok. I was fearing this. > > 2: In my process later on I get: "OverflowError: long too big to > > convert". > > Can you copy and paste the actual traceback rather than retyping it from > memory? I think you're missing something, namely what the long is being > converted to. The rest of the traceback will help too. 2016-05-24_08:15:40.84187 File "checkrc.pxd", line 14, in zmq.core.checkrc._check_rc (zmq/core/socket.c:5932) 2016-05-24_08:15:40.84187 OverflowError: long too big to convert I agree it looks like cut off, but it isn't... > > This happens in different places and seems to always relate to > > obtaining a length of something (dict or list created by list > > comprehension). Fx > > > > "for i in xrange(0, len_of_stuff, max_section_size):" > > > > en_of_stuff is always less than the max long (around 600). > > What do you mean, "the max long"? Longs do not have a max value. The only > limit is the amount of memory you have. > > What about max_section_size? How big is that? 30 > > We're using gevent and I'm suspecting some "threading" could cause > > this, as I'm able to replicate it locally with the same data. > > Typo: you said later that you are *not* able to replicate it. > > You're using a global variable with threaded code? You're a brave (or > foolhardy) man... Yeah, I didn't write the code originally, but that's not an excuse. The greenlets involved doesn't appear to be mulithreaded in this case, though. Even if it was, could that miss with the interpreter to give these sporious messages? > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Spurious issue in CPython 2.7.5
On 25/05/2016 13:04, thomas povtal.org wrote: > 2016-05-24_08:15:40.84187 File "checkrc.pxd", line 14, in > zmq.core.checkrc._check_rc (zmq/core/socket.c:5932) > 2016-05-24_08:15:40.84187 OverflowError: long too big to convert That exception is arising from ZeroMQ's own code, by the look of it. (Or perhaps pyzmq). It's not impossible that it's arising ultimately from Python's interpreter core, but you'd want to take that up with the ZeroMQ guys first to see what checks they're doing which might raise that exception. https://github.com/zeromq TJG -- https://mail.python.org/mailman/listinfo/python-list
Re: for / while else doesn't make sense
> On May 25, 2016, at 3:47 AM, Marko Rauhamaa wrote: > > Christopher Reimer : > >> Back in the early 1980's, I grew up on 8-bit processors and latin-1 was >> all we had for ASCII. > > You really were very advanced. According to https://en.wikipedia.org/wiki/ISO/IEC_8859-1#History>, ISO 8859-1 was > standardized in 1985. "Eight-bit-cleanness" became a thing in the early > 1990's. Apparently, I wasn't. According to the Internet, which can't be wrong, many of the 8-bit computers in the early 1980's were based on 1960's ASCII with some non-standard characters tossed in. Latin-1 probably came during my DOS days in the 1990's. As for ISO 8859-1, the standard was approved in 1985 but it was based on the character set for the first ANSI standard terminal, DEC VT-2200, that came out in 1983. Still early 1980's. ;) Thank you, Chris R. -- https://mail.python.org/mailman/listinfo/python-list
Re: Spurious issue in CPython 2.7.5
Hi! Thanks. It was an example... I get the very same exception text (the one that appears to be cut off) in this line in our own code: if Foo == False: (where Foo is global Foo = False.) :) T Den 25. maj 2016 klokken 14:13 skrev Tim Golden : On 25/05/2016 13:04, thomas povtal.org wrote: > 2016-05-24_08:15:40.84187 File "checkrc.pxd", line 14, in > zmq.core.checkrc._check_rc (zmq/core/socket.c:5932) > 2016-05-24_08:15:40.84187 OverflowError: long too big to convert That exception is arising from ZeroMQ's own code, by the look of it. (Or perhaps pyzmq). It's not impossible that it's arising ultimately from Python's interpreter core, but you'd want to take that up with the ZeroMQ guys first to see what checks they're doing which might raise that exception. https://github.com/zeromq TJG -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
ValueError: I/O operation on closed file
Hi Gorup, why i am getting "ValueError: I/O operation on closed file" this error. Pls let me know. Thanks in Advance. san -- https://mail.python.org/mailman/listinfo/python-list
Re: ValueError: I/O operation on closed file
On Wed, May 25, 2016 at 8:29 AM, San wrote: > Hi Gorup, > > why i am getting "ValueError: I/O operation on closed file" this error. > Pls let me know. Because your program is incorrect? Why not list your code, so that someone might be able to help you? > > Thanks in Advance. > san > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays -- https://mail.python.org/mailman/listinfo/python-list
Find the max number of elements in lists as value in a dictionary
I want to find the maximal number of elements contained in a nested dictionary, e.g. data = { 'violations': { 'col1': {'err': [elem1, elem2, elem3]}, 'col2': {'err': [elem1, elem2]} } } so to find the maximal number of elements in the lists for key 'err' in key 'col1' and 'col2'. Also key 'violations' may contain many keys (e.g. 'col1' , 'col2', 'col3' etc), so what's the best way to do this (using a loop)? max = 0for col in data.violations: if max < len(data.violations.col.err): max = len(data.violations.col.err) cheers -- https://mail.python.org/mailman/listinfo/python-list
Re: ValueError: I/O operation on closed file
On Wed, 25 May 2016 05:29:53 -0700, San wrote: > Hi Gorup, > > why i am getting "ValueError: I/O operation on closed file" this error. > Pls let me know. > > Thanks in Advance. > san because you are trying to do something with a file that has been closed the error message is quite explanatory -- One friend in a lifetime is much; two are many; three are hardly possible. Friendship needs a certain parallelism of life, a community of thought, a rivalry of aim. -- Henry Brook Adams -- https://mail.python.org/mailman/listinfo/python-list
IndexError for using pandas dataframe values
Hi, I tried to use DataFrame.values to convert a list of columns in a dataframe to a numpy ndarray/matrix, matrix = df.values[:, list_of_cols] but got an error, IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices so what's the problem with the list of columns I passed in? many thanks -- https://mail.python.org/mailman/listinfo/python-list
Re: Find the max number of elements in lists as value in a dictionary
Daiyue Weng writes: > I want to find the maximal number of elements contained in a nested > dictionary, e.g. > > data = { > 'violations': > { > 'col1': {'err': [elem1, elem2, elem3]}, > 'col2': {'err': [elem1, elem2]} > } > } > > so to find the maximal number of elements in the lists for key 'err' in key > 'col1' and 'col2'. Also key 'violations' may contain many keys (e.g. 'col1' > , 'col2', 'col3' etc), so what's the best way to do this (using a loop)? > > max = 0for col in data.violations: >if max < len(data.violations.col.err): > max = len(data.violations.col.err) Write a generator function that produces an object that generates the lengths. The magic word is the "yield" which is used like "return" but makes it so that the resulting objects yields each value on demand. For greater magic, make it yield the path to each list together with the length (length first, for easy max): def errcounts(data): for top, sub in data.items(): for mid, wev in sub.items(): if 'err' in wev: yield (len(wev['err']), top, mid) With that, Python's max does it all: max(errcounts(data)) => (3, 'violations', 'col1') This anticipated a next question; tuple comparison is overly specific; use a key function to max to not overspecify if you care; max needs a default in case there is no data; this same thing can be done with a single "generator expression" and that might be good, depending on the actual details and taste. Many other caveats apply. -- https://mail.python.org/mailman/listinfo/python-list
Re: Find the max number of elements in lists as value in a dictionary
On 2016-05-25, Daiyue Weng wrote: > I want to find the maximal number of elements contained in a nested > dictionary, e.g. > > data = { > 'violations': > { > 'col1': {'err': [elem1, elem2, elem3]}, > 'col2': {'err': [elem1, elem2]} > } > } > > so to find the maximal number of elements in the lists for key 'err' in key > 'col1' and 'col2'. Also key 'violations' may contain many keys (e.g. 'col1' > , 'col2', 'col3' etc), so what's the best way to do this (using a loop)? > > max = 0for col in data.violations: >if max < len(data.violations.col.err): > max = len(data.violations.col.err) In Python 3 you could do: max((len(col["err"]) for col in data["violations"].values()), default=0) In Python 2 you can do the same but you can't specify "default=0" and so it will throw an exception if there are no lists found, so you could use something like: max_errs = 0 if data["violations"]: max_errs = max(len(col["err"]) for col in data["violations"].values()) -- https://mail.python.org/mailman/listinfo/python-list
Re: html & python connection problem with hyperlinks
On Wed, May 25, 2016 at 3:24 AM, wrote: > Why not created the field title, that located on the template > BusinessList.html as a link to go to Business_Detail.html..? please check > > Code: > > models. py: > > from django.db import models > > > REGIONS = ( > ('ΘΕΣ', 'ΘΕΣΣΑΛΟΝΙΚΗ'), > ('ΣΕΡ', 'ΣΕΡΡΕΣ'), > ( 'ΑΘΗ', 'ΑΘΗΝΑ'), > > > > TYPEOFBUSINESS = ( > ('ΕΣΤ', 'ΕΣΤΙΑΤΟΡΙΑ'), > ('ΦΑΡ', 'ΦΑΡΜΑΚΕΙΑ'), > ('ΒΙΒ', 'ΒΙΒΛΙΟΠΩΛΕΙΑ'), > ( 'ΚΟΜ', 'ΚΟΜΜΩΤΗΡΙΑ'), > ('ΣΙΝ', 'ΣΙΝΕΜΑ') > > ) > > class Business(models.Model): > created_Date = models.DateTimeField(auto_now_add=True) > owner = models.ForeignKey('auth.User', related_name='snippets', null=True) > title = models.CharField(max_length=100, blank=True, default='') > Type_of_Business = models.CharField(max_length=3, choices=TYPEOFBUSINESS) > region = models.CharField(max_length=3, choices=REGIONS) > address = models.CharField(max_length=100, blank=True, default='') > phone = models.CharField(max_length=15, blank=True, default='') > image = models.ImageField(null=True) > > > def __str__(self): > return str(self.title) > > views.py > > from django.contrib.auth.models import User > from django.http import HttpResponse > from django.shortcuts import render, get_object_or_404 > from rest_framework import filters > from rest_framework import generics > from rest_framework import permissions > from snippets.permissions import IsOwnerOrReadOnly > from snippets.serializers import SnippetSerializer > from snippets.serializers import UserSerializer > from .models import Business > > > > class UserList(generics.ListAPIView): > queryset = User.objects.all() > serializer_class = UserSerializer > > > class UserDetail(generics.RetrieveAPIView): > queryset = User.objects.all() > serializer_class = UserSerializer > > class BusinessList(generics.ListCreateAPIView): > > permission_classes = (permissions.IsAuthenticatedOrReadOnly,) > queryset = Business.objects.all() > serializer_class = SnippetSerializer > filter_backends = (filters.DjangoFilterBackend,filters.SearchFilter, > filters.OrderingFilter,) > filter_fields = ('Type_of_Business', 'region') > search_fields = ('Type_of_Business', 'region') > ordering_fields = ('Type_of_Business','title', 'region') > > > def BusinessList(request): > business = Business.objects.all(); > return render(request, 'snippets/BusinessList.html' {'business':business}) > > def perform_create(self, serializer): > serializer.save(owner=self.request.user) > > > > class Business_Detail(generics.RetrieveUpdateDestroyAPIView): > permission_classes = (permissions.IsAuthenticatedOrReadOnly, > IsOwnerOrReadOnly,) > queryset = Business.objects.all() > serializer_class = SnippetSerializer > > > def Business_Detail(request, pk): > business = get_object_or_404(Business, pk=pk) > return render(request, 'snippets/Business_Detail.html', {'business': > business}) > > serializers.py > > from rest_framework import serializers > from snippets.models import Business > from django.contrib.auth.models import User > > > class SnippetSerializer(serializers.HyperlinkedModelSerializer): > owner = serializers.ReadOnlyField(source='owner.username') > > class Meta: > model = Business > fields = ('created_Date', 'owner', 'title','Type_of_Business', 'region', > 'address', 'phone', 'image') > > > class UserSerializer(serializers.ModelSerializer): > snippets = serializers.PrimaryKeyRelatedField(many=True, > queryset=Business.objects.all()) > > class Meta: > model = User > fields = ('id', 'username', 'snippets') > > BusinessList.html > > {% extends 'snippets/base.html' %} > > {% block content %} > {% for business in business%} > > > {{ business.created_Date }} #τυπωσε ημερ.δημιουργιας του Business > > {{ > business.title }} > {{business.Type_of_Business }} > {{ business.region }} > {{ business.address }} > {{ business.phone }} > {% if business.image %} > > {% endif %} > > {% endfor %} > {% endblock %} > > Business_Detail.html > > {% extends 'snippets/base.html' %}' %} > > {% block content %} > > {% if business.created_Date %} # αν υπαρχει ημερομηνια δημιουργίας > > {{ business.created_Date }} > > {% endif %} > {{ business.title }} > {{ business.region }} > {{ business.Type_of_Business}} > {{ business.phone }} > > {% if business.image %} # αν υπαρχει εικονα > # παρε εικονα απο το αντιστοιχο url > {% endif %} > > > {% endblock %} > > tutorial/snippets/urls.py > > from django.conf.urls import url, include > from django.contrib import admin > from rest_framework.urlpatterns import format_suffix_patterns > from django.contrib.staticfiles.urls import staticfiles_urlpatterns > from django.conf.urls import include > > from . import views > > urlpatterns = [ > url(r'^admin/', include(admin.site.urls)), > url(r'^$', views.BusinessList.as_view()), > url(r'^business/(?P[0-9]+)/$', views.Business_Detail.as_view()), > url(r'^users/$', views.UserList.as_view()), > url(r'^users/(?P[0-9]+)/$', views.UserDetail.as_view()), > url(r'^api-auth/', include('rest_framework.urls', > namespace=
Re: IndexError for using pandas dataframe values
Daiyue Weng wrote: > Hi, I tried to use DataFrame.values to convert a list of columns in a > dataframe to a numpy ndarray/matrix, > > matrix = df.values[:, list_of_cols] > > but got an error, > > IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis > (None) and integer or boolean arrays are valid indices > > so what's the problem with the list of columns I passed in? > > many thanks Your suggestively named list_of_cols is probably not a list. Have your script print its value and type before the failing operation: print(type(list_of_cols), list_of_cols) > matrix = df.values[:, list_of_cols] -- https://mail.python.org/mailman/listinfo/python-list
Do you think a DB based on Coroutine and AsyncIO is a good idea? I have written a demo on GitHub.
Link: https://github.com/JimChengLin/AsyncDB I always wonder why people do not make an async DB, when they are crazy with async web framework. Hard disks are faster than the Internet, but still pretty slow compared to CPU/RAM. Due to my limited English skill, I may be not able to explain how it works very precisely. Please be patient. :) Currently, people just build a sync DB that provides an async connection. It is "evil". Everything should be async. My implementation is not pure async though. The insert and del actions are half async due to there is not async __setitem__. I prefer a neat API over performance. It is my first post. Jim -- https://mail.python.org/mailman/listinfo/python-list
Re: Do you think a DB based on Coroutine and AsyncIO is a good idea? I have written a demo on GitHub.
On Wed, May 25, 2016 at 10:52 AM, wrote: > Link: https://github.com/JimChengLin/AsyncDB > > I always wonder why people do not make an async DB, when they are crazy with > async web framework. Hard disks are faster than the Internet, but still > pretty slow compared to CPU/RAM. In-process dbm-style databases aren't really all that popular though, are they? At least, I never hear much about them. It seems to me that most people use out-of-process SQL or NoSQL databases. For those, the details of the database implementation aren't very important to the user, and all that is really needed is an async client library, such as aiopg. I wonder if there's a need for a version 3 of the Python DBAPI spec including async operations? > My implementation is not pure async though. The insert and del actions are > half async due to there is not async __setitem__. I prefer a neat API over > performance. Would it be going too far if we had async versions of all the special methods: __ainit__, __asetitem__, __aiadd__, etc.? -- https://mail.python.org/mailman/listinfo/python-list
Re: Do you think a DB based on Coroutine and AsyncIO is a good idea? I have written a demo on GitHub.
On Wednesday, 25 May 2016 19:15:38 UTC+1, Ian wrote: > On Wed, May 25, 2016 at 10:52 AM, wrote: > > Link: https://github.com/JimChengLin/AsyncDB > > > > I always wonder why people do not make an async DB, when they are crazy > > with async web framework. Hard disks are faster than the Internet, but > > still pretty slow compared to CPU/RAM. > > In-process dbm-style databases aren't really all that popular though, > are they? At least, I never hear much about them. It seems to me that > most people use out-of-process SQL or NoSQL databases. For those, the > details of the database implementation aren't very important to the > user, and all that is really needed is an async client library, such > as aiopg. > > I wonder if there's a need for a version 3 of the Python DBAPI spec > including async operations? > > > My implementation is not pure async though. The insert and del actions are > > half async due to there is not async __setitem__. I prefer a neat API over > > performance. > > Would it be going too far if we had async versions of all the special > methods: __ainit__, __asetitem__, __aiadd__, etc.? We do not have to have all special methods. Indeed, we just need an async __setitem__. At least, it is my proposal. Would the core dev team consider it? I think in-process DB is quite popular in less serious development, e.g. SQLite. A sync DB with async connections can be treated as "async DB". But still, it is "evil" :). You know what I mean? It is about purity. Haha -- https://mail.python.org/mailman/listinfo/python-list
Re: Exended ASCII and code pages [was Re: for / while else doesn't make sense]
On 25/05/16 11:19, Steven D'Aprano wrote: On Wednesday 25 May 2016 19:10, Christopher Reimer wrote: Back in the early 1980's, I grew up on 8-bit processors and latin-1 was all we had for ASCII. It really, truly wasn't. But you can be forgiven for not knowing that, since until the rise of the public Internet most people weren't exposed to more than one code page or encoding, and it was incredibly common for people to call *any* encoding "ASCII". Indeed - at that time, I was working with COBOL on an IBM S/370. On that system, we used EBCDIC ASCII. That was the wierdest ASCII of all ;) E. -- https://mail.python.org/mailman/listinfo/python-list
Format a timedelta object
I have a timedelta object, and I want to display it in a nice human-readable format like 03:45:17 for "three hours, forty five minutes, 17 seconds". Is there a standard way to do this? -- Steve -- https://mail.python.org/mailman/listinfo/python-list
Re: Format a timedelta object
On Thu, May 26, 2016 at 12:16 AM, Steven D'Aprano wrote: > I have a timedelta object, and I want to display it in a nice human-readable > format like 03:45:17 for "three hours, forty five minutes, 17 seconds". > > Is there a standard way to do this? >>> timedelta(100) datetime.timedelta(100) >>> str(timedelta(seconds=100)) '0:01:40' >>> str(timedelta(hours=100)) '4 days, 4:00:00' (I recently spent *way* too long trying to figure out how to properly format the thing before being reminded that a plain str call gives exactly what I was after.) -- Zach -- https://mail.python.org/mailman/listinfo/python-list
Re: Format a timedelta object
Steven D'Aprano : > I have a timedelta object, and I want to display it in a nice > human-readable format like 03:45:17 for "three hours, forty five > minutes, 17 seconds". > > Is there a standard way to do this? >>> import datetime >>> td = datetime.timedelta(hours=3, minutes=45, seconds=17) >>> d = datetime.datetime(2000, 1, 1) >>> (d + td).strftime("%T") '03:45:17' >>> "%02d:%02d:%02d" % ( ... td.seconds // 3600, td.seconds % 3600 // 60, td.seconds % 60) '03:45:17' -- https://mail.python.org/mailman/listinfo/python-list
Re: ValueError: I/O operation on closed file
On Wednesday, May 25, 2016 at 6:00:07 PM UTC+5:30, San wrote: > Hi Gorup, > > why i am getting "ValueError: I/O operation on closed file" this error. > Pls let me know. > > Thanks in Advance. > san Hello, Following is the code i used. def test_results(filename): import csv with open(filename,"rU") as f: reader = csv.reader(f,delimiter="\t") result = {} for row in reader: key = row[0] if key in result: result[row[0]].append(row[1]) else: result[row[0]] = key result[key]=row[1:] print result filename ='filename.csv' test_results(filename) -- https://mail.python.org/mailman/listinfo/python-list
Re: for / while else doesn't make sense
On Wednesday, May 25, 2016 at 4:18:02 PM UTC+5:30, Marko Rauhamaa wrote: > Christopher Reimer: > > > Back in the early 1980's, I grew up on 8-bit processors and latin-1 was > > all we had for ASCII. > > You really were very advanced. According to https://en.wikipedia.org/wiki/ISO/IEC_8859-1#History>, ISO 8859-1 was > standardized in 1985. "Eight-bit-cleanness" became a thing in the early > 1990's. > > Where I was in late 1980's, the terminals were still 7-bit, and > instead of ASCII, national 7-bit character set variants were being used. > For example, you might see Pascal code like this: > >ä return the net å >ret := grossÄunitÅ * grossRate > > http://www.aivosto.com/vbtips/charsets-7bit.html> > > > Over the last several days from reading this thread (and variations > > thereof), l've seen several extended characters that I have no clue on > > how to reproduce on my keyboard. I haven't embraced extended character > > sets yet, which means I still think of ASCII characters as being 0 > > through 255 (8-bit). > > But Latin-1 is on your fingertips? ¡Qué bueno! Entonces sabes dónde > están las teclas españolas, ¿no? Thanks to this (sub)thread Ive added a new section: "Lemma: 7=8" here http://blog.languager.org/2014/04/unicode-and-unix-assumption.html All contributors gratefully acknowledged! -- https://mail.python.org/mailman/listinfo/python-list
Re: ValueError: I/O operation on closed file
On Thursday, May 26, 2016 at 11:17:56 AM UTC+5:30, San wrote: > On Wednesday, May 25, 2016 at 6:00:07 PM UTC+5:30, San wrote: > > Hi Gorup, > > > > why i am getting "ValueError: I/O operation on closed file" this error. > > Pls let me know. > > > > Thanks in Advance. > > san > > Hello, > Following is the code i used. > > def test_results(filename): > import csv > with open(filename,"rU") as f: > reader = csv.reader(f,delimiter="\t") > result = {} > for row in reader: > key = row[0] > if key in result: > result[row[0]].append(row[1]) > else: > result[row[0]] = key > result[key]=row[1:] > print result > > filename ='filename.csv' > test_results(filename) I think your for needs to be indented in the with -- https://mail.python.org/mailman/listinfo/python-list
Re: ValueError: I/O operation on closed file
On Thursday 26 May 2016 15:47, San wrote: > Following is the code i used. > > def test_results(filename): > import csv > with open(filename,"rU") as f: > reader = csv.reader(f,delimiter="\t") > result = {} You should use more consistent indents. Can you set your editor to automatically use four spaces each time you hit the tab key? In any case, you indent the "with" block. There are TWO lines indented, then you outdent again. That means the with block completes and the file is closed. You have: def test_restults(filename): ... with open(...) as f: indented block # f gets closed here for row in reader: indented block print result What you should have is: def test_restults(filename): ... with open(...) as f: indented block for row in reader: indented block # f gets closed here print result -- Steve -- https://mail.python.org/mailman/listinfo/python-list
Re: for / while else doesn't make sense
Rustom Mody writes: > On Wednesday, May 25, 2016 at 4:18:02 PM UTC+5:30, Marko Rauhamaa wrote: ... >> instead of ASCII, national 7-bit character set variants were being >> used. For example, you might see Pascal code like this: >> >>ä return the net å >>ret := grossÄunitÅ * grossRate >> >> http://www.aivosto.com/vbtips/charsets-7bit.html> ... > Thanks to this (sub)thread Ive added a new section: "Lemma: 7=8" here > http://blog.languager.org/2014/04/unicode-and-unix-assumption.html There may be a small inaccuracy at the point where you refer to Latin[1-15]. There are 15 parts to ISO-8859, numbered from 1 to 16 (with part 12 abandoned), but their numbers are not in synch with the Latin-N nicknames. In particular, Latin-9 is 8859-15, while 8859-9 is Latin-5. Some of the 8859-N are not Latin-anything. https://en.wikipedia.org/wiki/ISO/IEC_8859 This important detail should fit well in your narrative :) (Regarding Marko's 7-bit example, some terminals gave us a choice: they could be toggled to show those certain codes as {[\|]} or as letters, it was just not possible to see both at the same time.) -- https://mail.python.org/mailman/listinfo/python-list